Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builder pattern to RequestOptions #1236

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/main/java/com/adyen/model/RequestOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
import java.util.HashMap;

public class RequestOptions {

private String idempotencyKey;
private String requestedVerificationCodeHeader;
private HashMap<String, String> additionalServiceHeaders;

public RequestOptions idempotencyKey(String idempotencyKey){
this.idempotencyKey = idempotencyKey;
return this;
}
public RequestOptions requestedVerificationCodeHeader(String requestedVerificationCodeHeader){
this.requestedVerificationCodeHeader = requestedVerificationCodeHeader;
return this;
}
public RequestOptions additionalServiceHeaders(HashMap<String, String> additionalServiceHeaders){
this.additionalServiceHeaders = additionalServiceHeaders;
return this;
}
public String getIdempotencyKey() {
return idempotencyKey;
}
Expand All @@ -31,5 +41,12 @@ public HashMap<String, String> getAdditionalServiceHeaders() {
public void setAdditionalServiceHeaders(HashMap<String, String> additionalServiceHeaders) {
this.additionalServiceHeaders = additionalServiceHeaders;
}

@Override
public String toString() {
return "RequestOptions{" +
"idempotencyKey='" + idempotencyKey + '\'' +
", requestedVerificationCodeHeader='" + requestedVerificationCodeHeader + '\'' +
", additionalServiceHeaders=" + additionalServiceHeaders +
'}';
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/adyen/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.adyen.enums.Environment;
import com.adyen.enums.Region;
import com.adyen.model.RequestOptions;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;

import javax.net.ssl.SSLContext;
import java.util.HashMap;

public class ClientTest {

Expand Down Expand Up @@ -42,6 +44,17 @@ public void testClientCertificateAuth() {
Assert.assertEquals(Environment.LIVE, client.getConfig().getEnvironment());
}

@Test
public void testRequestOptionsBuilderPattern() {
HashMap<String, String> map = new HashMap<>();
map.put("thing", "thing");
RequestOptions requestOptions = new RequestOptions()
.idempotencyKey("idempotency")
.requestedVerificationCodeHeader("headers")
.additionalServiceHeaders(map);
Assert.assertEquals(requestOptions.getAdditionalServiceHeaders(), map);
}

private void assertCommonEndpoints(Config config) {
Assert.assertEquals(Client.TERMINAL_API_ENDPOINT_LIVE, config.getTerminalApiCloudEndpoint());
}
Expand Down
Loading