diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6c8b0181..fc0c1ae7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -29,7 +29,7 @@ jobs: run: ./gradlew test - name: Publish package - run: ./gradlew uploadArchives + run: ./gradlew publish env: PGP_SIGNING_KEY: ${{ secrets.PGP_SIGNING_KEY }} PGP_SIGNING_PASSWORD: ${{ secrets.PGP_SIGNING_PASSWORD }} diff --git a/build.gradle b/build.gradle index 7c1643b5..6df3405a 100644 --- a/build.gradle +++ b/build.gradle @@ -31,14 +31,9 @@ buildscript { } } -task javadocJar(type: Jar) { - archiveClassifier = 'javadoc' - from javadoc -} - -task sourcesJar(type: Jar) { - archiveClassifier = 'sources' - from sourceSets.main.allSource +java { + withJavadocJar() + withSourcesJar() } distributions { @@ -56,16 +51,21 @@ signing { sign configurations.archives } -artifacts { - archives javadocJar, sourcesJar +javadoc { + if(JavaVersion.current().isJava9Compatible()) { + options.addBooleanOption('html5', true) + } } // REF: https://docs.gradle.org/current/userguide/publishing_maven.html publishing { publications { - mavenJava(MavenPublication) { - artifactId = 'omise-java' - + shadow(MavenPublication) { + publication -> + project.shadow.component(publication) + artifactId = 'omise-java' + artifact sourcesJar + artifact javadocJar pom { name = 'Omise Java' description = 'Java bindings for the Omise API' diff --git a/src/main/java/co/omise/Client.java b/src/main/java/co/omise/Client.java index 26c2feff..dae327c9 100644 --- a/src/main/java/co/omise/Client.java +++ b/src/main/java/co/omise/Client.java @@ -37,7 +37,7 @@ public class Client { private final OkHttpClient httpClient; - private Requester requester; + private final Requester requester; /** * Creates a Client that sends the specified API version string in the header to access an earlier version diff --git a/src/main/java/co/omise/Example.java b/src/main/java/co/omise/Example.java index d6b39c26..9870431c 100644 --- a/src/main/java/co/omise/Example.java +++ b/src/main/java/co/omise/Example.java @@ -176,7 +176,7 @@ void reverseCharge() throws IOException, OmiseException, ClientException { new Charge.ReverseRequestBuilder("chrg_test_4xso2s8ivdej29pqnhz").build(); Charge charge = client().sendRequest(reverseChargeRequest); - System.out.printf("charge reversal: %s", Boolean.toString(charge.isReversed())); + System.out.printf("charge reversal: %s", charge.isReversed()); } void updateCharge() throws IOException, OmiseException, ClientException { diff --git a/src/main/java/co/omise/Serializer.java b/src/main/java/co/omise/Serializer.java index 85f1afa0..a20fbfe6 100644 --- a/src/main/java/co/omise/Serializer.java +++ b/src/main/java/co/omise/Serializer.java @@ -68,8 +68,7 @@ private Serializer() { .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true) - .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // TODO: Deprecate in vNext + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); } /** @@ -197,7 +196,7 @@ public Map serializeToMap(T model) { * @return The string value for using as query parameters. */ public > String serializeToQueryParams(T value) { - return (String) objectMapper.convertValue(value, String.class); + return objectMapper.convertValue(value, String.class); } /** diff --git a/src/main/java/co/omise/models/Account.java b/src/main/java/co/omise/models/Account.java index 16ac05c1..9b548281 100644 --- a/src/main/java/co/omise/models/Account.java +++ b/src/main/java/co/omise/models/Account.java @@ -146,11 +146,6 @@ public void setZeroInterestInstallments(boolean zeroInterestInstallments) { public static class GetRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "account"); diff --git a/src/main/java/co/omise/models/AuthorizationType.java b/src/main/java/co/omise/models/AuthorizationType.java index 5ed5177e..630b3d01 100644 --- a/src/main/java/co/omise/models/AuthorizationType.java +++ b/src/main/java/co/omise/models/AuthorizationType.java @@ -6,5 +6,5 @@ public enum AuthorizationType { @JsonProperty("pre_auth") PreAuth, @JsonProperty("final_auth") - FinalAuth; + FinalAuth } diff --git a/src/main/java/co/omise/models/Balance.java b/src/main/java/co/omise/models/Balance.java index 3eab059e..70dec1b1 100644 --- a/src/main/java/co/omise/models/Balance.java +++ b/src/main/java/co/omise/models/Balance.java @@ -3,11 +3,7 @@ import co.omise.Endpoint; import co.omise.requests.RequestBuilder; import co.omise.requests.ResponseType; -import com.fasterxml.jackson.annotation.JsonProperty; import okhttp3.HttpUrl; -import okhttp3.RequestBody; - -import java.io.IOException; /** * Balance object @@ -63,11 +59,6 @@ public void setTransferable(long transferable) { public static class GetRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "balance"); diff --git a/src/main/java/co/omise/models/Capability.java b/src/main/java/co/omise/models/Capability.java index c625e104..23a05265 100644 --- a/src/main/java/co/omise/models/Capability.java +++ b/src/main/java/co/omise/models/Capability.java @@ -5,9 +5,7 @@ import co.omise.requests.ResponseType; import com.fasterxml.jackson.annotation.JsonProperty; import okhttp3.HttpUrl; -import okhttp3.RequestBody; -import java.io.IOException; import java.util.List; /** @@ -66,11 +64,6 @@ public void setZeroInterestInstallments(boolean zeroInterestInstallments) { public static class GetRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "capability"); diff --git a/src/main/java/co/omise/models/Card.java b/src/main/java/co/omise/models/Card.java index bf8e5a6f..9d8c01b1 100644 --- a/src/main/java/co/omise/models/Card.java +++ b/src/main/java/co/omise/models/Card.java @@ -302,8 +302,8 @@ public Create expiration(int month, int year) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String customerId; - private String cardId; + private final String customerId; + private final String cardId; public DeleteRequestBuilder(String customerId, String cardId) { this.customerId = customerId; this.cardId = cardId; @@ -326,18 +326,13 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String customerId; - private String cardId; + private final String customerId; + private final String cardId; public GetRequestBuilder(String customerId, String cardId) { this.customerId = customerId; this.cardId = cardId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "customers", customerId, "cards", cardId); @@ -350,8 +345,8 @@ protected ResponseType type() { } public static class UpdateRequestBuilder extends RequestBuilder { - private String customerId; - private String cardId; + private final String customerId; + private final String cardId; @JsonProperty private String city; @@ -425,17 +420,12 @@ protected RequestBody payload() throws IOException { } public static class ListRequestBuilder extends RequestBuilder> { - private String customerId; + private final String customerId; private ScopedList.Options options; public ListRequestBuilder(String customerId) { this.customerId = customerId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/Chain.java b/src/main/java/co/omise/models/Chain.java index 82b77abc..00063454 100644 --- a/src/main/java/co/omise/models/Chain.java +++ b/src/main/java/co/omise/models/Chain.java @@ -3,12 +3,9 @@ import co.omise.Endpoint; import co.omise.requests.RequestBuilder; import co.omise.requests.ResponseType; -import com.fasterxml.jackson.annotation.JsonProperty; + import com.fasterxml.jackson.core.type.TypeReference; import okhttp3.HttpUrl; -import okhttp3.RequestBody; - -import java.io.IOException; /** * Chain object @@ -56,11 +53,6 @@ public void setRevoked(boolean revoked) { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -84,16 +76,11 @@ public ListRequestBuilder options(ScopedList.Options options) { } public static class GetRequestBuilder extends RequestBuilder { - private String chainId; + private final String chainId; public GetRequestBuilder(String chainId) { this.chainId = chainId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "chains", chainId); @@ -106,7 +93,7 @@ protected ResponseType type() { } public static class RevokeRequestBuilder extends RequestBuilder { - private String chainId; + private final String chainId; public RevokeRequestBuilder(String chainId) { this.chainId = chainId; } diff --git a/src/main/java/co/omise/models/Charge.java b/src/main/java/co/omise/models/Charge.java index 74d7a9bb..8a466183 100644 --- a/src/main/java/co/omise/models/Charge.java +++ b/src/main/java/co/omise/models/Charge.java @@ -514,11 +514,6 @@ public void setMerchantAdvice(String merchantAdvice) { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -689,17 +684,12 @@ public CreateRequestBuilder metadata(String key, Object value) { } public static class ListEventsRequestBuilder extends RequestBuilder> { - private String chargeId; + private final String chargeId; private ScopedList.Options options; public ListEventsRequestBuilder(String chargeId) { this.chargeId = chargeId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -725,11 +715,6 @@ public ListEventsRequestBuilder options(ScopedList.Options options) { public static class ListSchedulesRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -753,16 +738,11 @@ public ListSchedulesRequestBuilder options(ScopedList.Options options) { } public static class GetRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; public GetRequestBuilder(String chargeId) { this.chargeId = chargeId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "charges", chargeId); @@ -775,7 +755,7 @@ protected ResponseType type() { } public static class UpdateRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; @JsonProperty private String description; @@ -828,7 +808,7 @@ public UpdateRequestBuilder metadata(String key, Object value) { } public static class CaptureRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; @JsonProperty("capture_amount") private long captureAmount; @@ -864,7 +844,7 @@ protected RequestBody payload() throws IOException { } public static class ExpireRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; public ExpireRequestBuilder(String chargeId) { this.chargeId = chargeId; } @@ -886,7 +866,7 @@ protected ResponseType type() { } public static class MarkAsFailedRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; public MarkAsFailedRequestBuilder(String chargeId) { this.chargeId = chargeId; } @@ -908,7 +888,7 @@ protected ResponseType type() { } public static class MarkAsPaidRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; public MarkAsPaidRequestBuilder(String chargeId) { this.chargeId = chargeId; } @@ -930,7 +910,7 @@ protected ResponseType type() { } public static class ReverseRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; public ReverseRequestBuilder(String chargeId) { this.chargeId = chargeId; } diff --git a/src/main/java/co/omise/models/ChargeStatus.java b/src/main/java/co/omise/models/ChargeStatus.java index 42a4ba59..61fb5466 100644 --- a/src/main/java/co/omise/models/ChargeStatus.java +++ b/src/main/java/co/omise/models/ChargeStatus.java @@ -14,5 +14,5 @@ public enum ChargeStatus { @JsonProperty("successful") Successful, @JsonProperty("unknown") - Unknown; + Unknown } \ No newline at end of file diff --git a/src/main/java/co/omise/models/Customer.java b/src/main/java/co/omise/models/Customer.java index ae2c53c5..22dc34ea 100644 --- a/src/main/java/co/omise/models/Customer.java +++ b/src/main/java/co/omise/models/Customer.java @@ -77,7 +77,7 @@ public void setMetadata(Map metadata) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String customerId; + private final String customerId; public DeleteRequestBuilder(String customerId) { this.customerId = customerId; } @@ -99,16 +99,11 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String customerId; + private final String customerId; public GetRequestBuilder(String customerId) { this.customerId = customerId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "customers", customerId); @@ -122,7 +117,7 @@ protected ResponseType type() { @JsonInclude(JsonInclude.Include.NON_NULL) public static class UpdateRequestBuilder extends RequestBuilder { - private String customerId; + private final String customerId; @JsonProperty private String card; @@ -198,11 +193,6 @@ public UpdateRequestBuilder metadata(String key, Object value) { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -289,17 +279,12 @@ public CreateRequestBuilder metadata(String key, Object value) { } public static class ListSchedulesRequestBuilder extends RequestBuilder> { - private String customerId; + private final String customerId; private ScopedList.Options options; public ListSchedulesRequestBuilder(String customerId) { this.customerId = customerId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/Dispute.java b/src/main/java/co/omise/models/Dispute.java index 5b9f3b96..2a4f4467 100644 --- a/src/main/java/co/omise/models/Dispute.java +++ b/src/main/java/co/omise/models/Dispute.java @@ -164,11 +164,6 @@ public void setTransactions(List transactions) { public static class ClosedRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "disputes", "closed"); @@ -184,11 +179,6 @@ public static class ListRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "disputes", "open"); @@ -236,11 +221,6 @@ protected ResponseType type() { public static class PendingRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "disputes", "pending"); @@ -253,16 +233,11 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String disputeId; + private final String disputeId; public GetRequestBuilder(String disputeId) { this.disputeId = disputeId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "disputes", disputeId); @@ -275,7 +250,7 @@ protected ResponseType type() { } public static class UpdateRequestBuilder extends RequestBuilder { - private String disputeId; + private final String disputeId; @JsonProperty private String message; @@ -328,7 +303,7 @@ public UpdateRequestBuilder metadata(String key, Object value) { } public static class CloseRequestBuilder extends RequestBuilder { - private String disputeId; + private final String disputeId; @JsonProperty private DisputeStatus status; @@ -363,7 +338,7 @@ protected RequestBody payload() throws IOException { } public static class AcceptRequestBuilder extends RequestBuilder { - private String disputeId; + private final String disputeId; public AcceptRequestBuilder(String disputeId) { this.disputeId = disputeId; } @@ -385,7 +360,7 @@ protected ResponseType type() { } public static class CreateDisputeRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; public CreateDisputeRequestBuilder(String chargeId) { this.chargeId = chargeId; } diff --git a/src/main/java/co/omise/models/DisputeReasonCode.java b/src/main/java/co/omise/models/DisputeReasonCode.java index abf9b253..5bfccd3f 100644 --- a/src/main/java/co/omise/models/DisputeReasonCode.java +++ b/src/main/java/co/omise/models/DisputeReasonCode.java @@ -34,5 +34,5 @@ public enum DisputeReasonCode { @JsonProperty("transaction_not_recognised") TransactionNotRecognised, @JsonProperty("unauthorized_charge") - UnauthorizedCharge; + UnauthorizedCharge } \ No newline at end of file diff --git a/src/main/java/co/omise/models/DisputeStatus.java b/src/main/java/co/omise/models/DisputeStatus.java index 8a94b6d6..70bf8cd6 100644 --- a/src/main/java/co/omise/models/DisputeStatus.java +++ b/src/main/java/co/omise/models/DisputeStatus.java @@ -12,5 +12,5 @@ public enum DisputeStatus { @JsonProperty("pending") Pending, @JsonProperty("won") - Won; + Won } \ No newline at end of file diff --git a/src/main/java/co/omise/models/Document.java b/src/main/java/co/omise/models/Document.java index abe9624c..b8dc5c15 100644 --- a/src/main/java/co/omise/models/Document.java +++ b/src/main/java/co/omise/models/Document.java @@ -46,8 +46,8 @@ public void setLocation(String location) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String disputeId; - private String documentId; + private final String disputeId; + private final String documentId; public DeleteRequestBuilder(String disputeId, String documentId) { this.disputeId = disputeId; this.documentId = documentId; @@ -70,18 +70,13 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String disputeId; - private String documentId; + private final String disputeId; + private final String documentId; public GetRequestBuilder(String disputeId, String documentId) { this.disputeId = disputeId; this.documentId = documentId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "disputes", disputeId, "documents", documentId); @@ -94,17 +89,12 @@ protected ResponseType type() { } public static class ListRequestBuilder extends RequestBuilder> { - private String disputeId; + private final String disputeId; private ScopedList.Options options; public ListRequestBuilder(String disputeId) { this.disputeId = disputeId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -128,7 +118,7 @@ public ListRequestBuilder options(ScopedList.Options options) { } public static class CreateRequestBuilder extends RequestBuilder { - private String disputeId; + private final String disputeId; @JsonProperty private String file; diff --git a/src/main/java/co/omise/models/Event.java b/src/main/java/co/omise/models/Event.java index 15dd9002..ca170a06 100644 --- a/src/main/java/co/omise/models/Event.java +++ b/src/main/java/co/omise/models/Event.java @@ -6,9 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import okhttp3.HttpUrl; -import okhttp3.RequestBody; -import java.io.IOException; import java.util.List; /** @@ -56,16 +54,11 @@ public void setWebhookDeliveries(List webhookDeliveries) { } public static class GetRequestBuilder extends RequestBuilder { - private String eventId; + private final String eventId; public GetRequestBuilder(String eventId) { this.eventId = eventId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "events", eventId); @@ -80,11 +73,6 @@ protected ResponseType type() { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/Forex.java b/src/main/java/co/omise/models/Forex.java index a2554c77..fecf2fab 100644 --- a/src/main/java/co/omise/models/Forex.java +++ b/src/main/java/co/omise/models/Forex.java @@ -3,11 +3,7 @@ import co.omise.Endpoint; import co.omise.requests.RequestBuilder; import co.omise.requests.ResponseType; -import com.fasterxml.jackson.annotation.JsonProperty; import okhttp3.HttpUrl; -import okhttp3.RequestBody; - -import java.io.IOException; /** * Forex object @@ -53,16 +49,11 @@ public void setRate(Double rate) { } public static class GetRequestBuilder extends RequestBuilder { - private String currency; + private final String currency; public GetRequestBuilder(String currency) { this.currency = currency; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "forex", currency); diff --git a/src/main/java/co/omise/models/Link.java b/src/main/java/co/omise/models/Link.java index 1de5969c..769270a6 100644 --- a/src/main/java/co/omise/models/Link.java +++ b/src/main/java/co/omise/models/Link.java @@ -111,7 +111,7 @@ public void setUsedAt(DateTime usedAt) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String linkId; + private final String linkId; public DeleteRequestBuilder(String linkId) { this.linkId = linkId; } @@ -133,16 +133,11 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String linkId; + private final String linkId; public GetRequestBuilder(String linkId) { this.linkId = linkId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "links", linkId); @@ -157,11 +152,6 @@ protected ResponseType type() { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -244,17 +234,12 @@ protected RequestBody payload() throws IOException { } public static class ListChargesRequestBuilder extends RequestBuilder> { - private String linkId; + private final String linkId; private ScopedList.Options options; public ListChargesRequestBuilder(String linkId) { this.linkId = linkId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/OmiseException.java b/src/main/java/co/omise/models/OmiseException.java index 0a788d0a..83537cad 100644 --- a/src/main/java/co/omise/models/OmiseException.java +++ b/src/main/java/co/omise/models/OmiseException.java @@ -58,6 +58,6 @@ public void setMessage(String message) { @Override public String toString() { - return "(" + Integer.toString(httpStatusCode) + "/" + code + ") " + message; + return "(" + httpStatusCode + "/" + code + ") " + message; } } diff --git a/src/main/java/co/omise/models/Ordering.java b/src/main/java/co/omise/models/Ordering.java index 5d2d2316..a1aeda49 100644 --- a/src/main/java/co/omise/models/Ordering.java +++ b/src/main/java/co/omise/models/Ordering.java @@ -6,5 +6,5 @@ public enum Ordering { @JsonProperty("chronological") Chronological, @JsonProperty("reverse_chronological") - ReverseChronological; + ReverseChronological } \ No newline at end of file diff --git a/src/main/java/co/omise/models/Params.java b/src/main/java/co/omise/models/Params.java index 697eeb41..3b521bf6 100644 --- a/src/main/java/co/omise/models/Params.java +++ b/src/main/java/co/omise/models/Params.java @@ -39,7 +39,7 @@ public abstract class Params { * @return An {@link Map} containing keys and values to adds to the URL. */ public Map query(Serializer serializer) { - return Collections.unmodifiableMap(new HashMap()); + return Collections.unmodifiableMap(new HashMap<>()); } /** diff --git a/src/main/java/co/omise/models/Receipt.java b/src/main/java/co/omise/models/Receipt.java index 64342613..7235ee2f 100644 --- a/src/main/java/co/omise/models/Receipt.java +++ b/src/main/java/co/omise/models/Receipt.java @@ -6,10 +6,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import okhttp3.HttpUrl; -import okhttp3.RequestBody; -import org.joda.time.LocalDate; -import java.io.IOException; +import org.joda.time.LocalDate; /** * Receipt object @@ -224,11 +222,6 @@ public void setWht(long wht) { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -252,16 +245,11 @@ public ListRequestBuilder options(ScopedList.Options options) { } public static class GetRequestBuilder extends RequestBuilder { - private String receiptId; + private final String receiptId; public GetRequestBuilder(String receiptId) { this.receiptId = receiptId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "receipts", receiptId); diff --git a/src/main/java/co/omise/models/Recipient.java b/src/main/java/co/omise/models/Recipient.java index 73c769f8..a219489e 100644 --- a/src/main/java/co/omise/models/Recipient.java +++ b/src/main/java/co/omise/models/Recipient.java @@ -2,7 +2,6 @@ import co.omise.Endpoint; import co.omise.models.schedules.Schedule; -import co.omise.models.schedules.TransferSchedule; import co.omise.requests.RequestBuilder; import co.omise.requests.ResponseType; import com.fasterxml.jackson.annotation.JsonProperty; @@ -164,7 +163,7 @@ public void setVerifiedAt(DateTime verifiedAt) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String recipientId; + private final String recipientId; public DeleteRequestBuilder(String recipientId) { this.recipientId = recipientId; } @@ -186,16 +185,11 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String recipientId; + private final String recipientId; public GetRequestBuilder(String recipientId) { this.recipientId = recipientId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "recipients", recipientId); @@ -208,7 +202,7 @@ protected ResponseType type() { } public static class UpdateRequestBuilder extends RequestBuilder { - private String recipientId; + private final String recipientId; @JsonProperty("bank_account") private BankAccount.Params bankAccount; @@ -298,11 +292,6 @@ public UpdateRequestBuilder metadata(String key, Object value) { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -410,17 +399,12 @@ public CreateRequestBuilder metadata(String key, Object value) { } public static class ListSchedulesRequestBuilder extends RequestBuilder> { - private String recipientId; + private final String recipientId; private ScopedList.Options options; public ListSchedulesRequestBuilder(String recipientId) { this.recipientId = recipientId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -444,7 +428,7 @@ public ListSchedulesRequestBuilder options(ScopedList.Options options) { } public static class VerifyRequestBuilder extends RequestBuilder { - private String recipientId; + private final String recipientId; public VerifyRequestBuilder(String recipientId) { this.recipientId = recipientId; } diff --git a/src/main/java/co/omise/models/RecipientFailureCode.java b/src/main/java/co/omise/models/RecipientFailureCode.java index bb86e4c4..de38de54 100644 --- a/src/main/java/co/omise/models/RecipientFailureCode.java +++ b/src/main/java/co/omise/models/RecipientFailureCode.java @@ -8,5 +8,5 @@ public enum RecipientFailureCode { @JsonProperty("bank_not_found") BankNotFound, @JsonProperty("name_mismatch") - NameMismatch; + NameMismatch } \ No newline at end of file diff --git a/src/main/java/co/omise/models/RecipientType.java b/src/main/java/co/omise/models/RecipientType.java index 54dfb0a3..9920ba39 100644 --- a/src/main/java/co/omise/models/RecipientType.java +++ b/src/main/java/co/omise/models/RecipientType.java @@ -6,5 +6,5 @@ public enum RecipientType { @JsonProperty("corporation") Corporation, @JsonProperty("individual") - Individual; + Individual } \ No newline at end of file diff --git a/src/main/java/co/omise/models/Refund.java b/src/main/java/co/omise/models/Refund.java index 01cae2bb..8b2162d4 100644 --- a/src/main/java/co/omise/models/Refund.java +++ b/src/main/java/co/omise/models/Refund.java @@ -123,11 +123,6 @@ public void setVoided(boolean voided) { public static class ListRefundsRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -151,17 +146,12 @@ public ListRefundsRequestBuilder options(ScopedList.Options options) { } public static class ListRequestBuilder extends RequestBuilder> { - private String chargeId; + private final String chargeId; private ScopedList.Options options; public ListRequestBuilder(String chargeId) { this.chargeId = chargeId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -185,7 +175,7 @@ public ListRequestBuilder options(ScopedList.Options options) { } public static class CreateRequestBuilder extends RequestBuilder { - private String chargeId; + private final String chargeId; @JsonProperty private long amount; @@ -245,18 +235,13 @@ public CreateRequestBuilder metadata(String key, Object value) { } public static class GetRequestBuilder extends RequestBuilder { - private String chargeId; - private String refundId; + private final String chargeId; + private final String refundId; public GetRequestBuilder(String chargeId, String refundId) { this.chargeId = chargeId; this.refundId = refundId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "charges", chargeId, "refunds", refundId); diff --git a/src/main/java/co/omise/models/RefundStatus.java b/src/main/java/co/omise/models/RefundStatus.java index 97a11792..f144bd95 100644 --- a/src/main/java/co/omise/models/RefundStatus.java +++ b/src/main/java/co/omise/models/RefundStatus.java @@ -4,5 +4,5 @@ public enum RefundStatus { @JsonProperty("closed") - Closed; + Closed } \ No newline at end of file diff --git a/src/main/java/co/omise/models/SearchResult.java b/src/main/java/co/omise/models/SearchResult.java index 777274fb..61848945 100644 --- a/src/main/java/co/omise/models/SearchResult.java +++ b/src/main/java/co/omise/models/SearchResult.java @@ -166,7 +166,7 @@ public RequestBody body(Serializer serializer) { */ public static class SearchRequestBuilder extends RequestBuilder> { - private SearchResult.Options options; + private final SearchResult.Options options; public SearchRequestBuilder(SearchResult.Options options) { this.options = options; diff --git a/src/main/java/co/omise/models/Shipping.java b/src/main/java/co/omise/models/Shipping.java index 871a2053..3da736c5 100644 --- a/src/main/java/co/omise/models/Shipping.java +++ b/src/main/java/co/omise/models/Shipping.java @@ -1,10 +1,7 @@ package co.omise.models; -import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; import com.fasterxml.jackson.annotation.JsonProperty; -import java.lang.reflect.Field; - public class Shipping { public String street1; public String street2; diff --git a/src/main/java/co/omise/models/Source.java b/src/main/java/co/omise/models/Source.java index dbf71a56..6c055124 100644 --- a/src/main/java/co/omise/models/Source.java +++ b/src/main/java/co/omise/models/Source.java @@ -3,7 +3,7 @@ import co.omise.Endpoint; import co.omise.requests.RequestBuilder; import co.omise.requests.ResponseType; -import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; + import com.fasterxml.jackson.annotation.JsonProperty; import okhttp3.HttpUrl; import okhttp3.RequestBody; @@ -335,7 +335,7 @@ public CreateRequestBuilder phoneNumber(String phoneNumber) { public CreateRequestBuilder addItem(Item item) { if(this.items == null) { - this.items = new ArrayList(); + this.items = new ArrayList<>(); } this.items.add(item); return this; @@ -368,16 +368,11 @@ protected RequestBody payload() throws IOException { } public static class GetRequestBuilder extends RequestBuilder { - private String sourceId; + private final String sourceId; public GetRequestBuilder(String sourceId) { this.sourceId = sourceId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "sources", sourceId); diff --git a/src/main/java/co/omise/models/SystemInfo.java b/src/main/java/co/omise/models/SystemInfo.java index 2bca2c33..60ab017b 100644 --- a/src/main/java/co/omise/models/SystemInfo.java +++ b/src/main/java/co/omise/models/SystemInfo.java @@ -3,11 +3,8 @@ import co.omise.Endpoint; import co.omise.requests.RequestBuilder; import co.omise.requests.ResponseType; -import com.fasterxml.jackson.annotation.JsonProperty; import okhttp3.HttpUrl; -import okhttp3.RequestBody; -import java.io.IOException; import java.util.List; public class SystemInfo extends Model { @@ -32,11 +29,6 @@ public void setVersions(List versions) { public static class GetRequestBuilder extends RequestBuilder { - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, ""); diff --git a/src/main/java/co/omise/models/Token.java b/src/main/java/co/omise/models/Token.java index 7e978054..bf6ae70a 100644 --- a/src/main/java/co/omise/models/Token.java +++ b/src/main/java/co/omise/models/Token.java @@ -85,16 +85,11 @@ protected RequestBody payload() throws IOException { } public static class GetRequestBuilder extends RequestBuilder { - private String tokenId; + private final String tokenId; public GetRequestBuilder(String tokenId) { this.tokenId = tokenId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.VAULT, "tokens", tokenId); diff --git a/src/main/java/co/omise/models/Transaction.java b/src/main/java/co/omise/models/Transaction.java index efe6387e..5a67789f 100644 --- a/src/main/java/co/omise/models/Transaction.java +++ b/src/main/java/co/omise/models/Transaction.java @@ -6,10 +6,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import okhttp3.HttpUrl; -import okhttp3.RequestBody; -import org.joda.time.DateTime; -import java.io.IOException; +import org.joda.time.DateTime; /** * Transaction object @@ -83,16 +81,11 @@ public void setTransferableAt(DateTime transferableAt) { } public static class GetRequestBuilder extends RequestBuilder { - private String transactionId; + private final String transactionId; public GetRequestBuilder(String transactionId) { this.transactionId = transactionId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "transactions", transactionId); @@ -107,11 +100,6 @@ protected ResponseType type() { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/TransactionDirection.java b/src/main/java/co/omise/models/TransactionDirection.java index 7170490f..65238a71 100644 --- a/src/main/java/co/omise/models/TransactionDirection.java +++ b/src/main/java/co/omise/models/TransactionDirection.java @@ -6,5 +6,5 @@ public enum TransactionDirection { @JsonProperty("credit") Credit, @JsonProperty("debit") - Debit; + Debit } \ No newline at end of file diff --git a/src/main/java/co/omise/models/TransactionFee.java b/src/main/java/co/omise/models/TransactionFee.java index 5267ba2e..66587c13 100644 --- a/src/main/java/co/omise/models/TransactionFee.java +++ b/src/main/java/co/omise/models/TransactionFee.java @@ -1,7 +1,6 @@ package co.omise.models; import com.fasterxml.jackson.annotation.JsonProperty; -import org.joda.time.DateTime; public class TransactionFee { @JsonProperty("fee_flat") diff --git a/src/main/java/co/omise/models/Transfer.java b/src/main/java/co/omise/models/Transfer.java index e32caf1c..d02d4ee5 100644 --- a/src/main/java/co/omise/models/Transfer.java +++ b/src/main/java/co/omise/models/Transfer.java @@ -211,7 +211,7 @@ public void setTransactions(List transactions) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String transferId; + private final String transferId; public DeleteRequestBuilder(String transferId) { this.transferId = transferId; } @@ -233,16 +233,11 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String transferId; + private final String transferId; public GetRequestBuilder(String transferId) { this.transferId = transferId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "transfers", transferId); @@ -255,7 +250,7 @@ protected ResponseType type() { } public static class UpdateRequestBuilder extends RequestBuilder { - private String transferId; + private final String transferId; @JsonProperty private long amount; @@ -310,11 +305,6 @@ public UpdateRequestBuilder metadata(String key, Object value) { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -403,11 +393,6 @@ public CreateRequestBuilder metadata(String key, Object value) { public static class ListSchedulesRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -431,7 +416,7 @@ public ListSchedulesRequestBuilder options(ScopedList.Options options) { } public static class MarkAsPaidRequestBuilder extends RequestBuilder { - private String transferId; + private final String transferId; public MarkAsPaidRequestBuilder(String transferId) { this.transferId = transferId; } @@ -453,7 +438,7 @@ protected ResponseType type() { } public static class MarkAsSentRequestBuilder extends RequestBuilder { - private String transferId; + private final String transferId; public MarkAsSentRequestBuilder(String transferId) { this.transferId = transferId; } diff --git a/src/main/java/co/omise/models/schedules/Occurrence.java b/src/main/java/co/omise/models/schedules/Occurrence.java index d6b52c5a..7b3bec21 100644 --- a/src/main/java/co/omise/models/schedules/Occurrence.java +++ b/src/main/java/co/omise/models/schedules/Occurrence.java @@ -8,12 +8,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import okhttp3.HttpUrl; -import okhttp3.RequestBody; + import org.joda.time.DateTime; import org.joda.time.LocalDate; -import java.io.IOException; - /** * Occurrence object * @@ -97,16 +95,11 @@ public void setStatus(OccurrenceStatus status) { } public static class GetRequestBuilder extends RequestBuilder { - private String occurrenceId; + private final String occurrenceId; public GetRequestBuilder(String occurrenceId) { this.occurrenceId = occurrenceId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "occurrences", occurrenceId); @@ -119,17 +112,12 @@ protected ResponseType type() { } public static class ListRequestBuilder extends RequestBuilder> { - private String scheduleId; + private final String scheduleId; private ScopedList.Options options; public ListRequestBuilder(String scheduleId) { this.scheduleId = scheduleId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/schedules/OccurrenceStatus.java b/src/main/java/co/omise/models/schedules/OccurrenceStatus.java index 17f9ea50..67bb0a8d 100644 --- a/src/main/java/co/omise/models/schedules/OccurrenceStatus.java +++ b/src/main/java/co/omise/models/schedules/OccurrenceStatus.java @@ -10,5 +10,5 @@ public enum OccurrenceStatus { @JsonProperty("skipped") Skipped, @JsonProperty("successful") - Successful; + Successful } \ No newline at end of file diff --git a/src/main/java/co/omise/models/schedules/Schedule.java b/src/main/java/co/omise/models/schedules/Schedule.java index bac005c1..e195e31b 100644 --- a/src/main/java/co/omise/models/schedules/Schedule.java +++ b/src/main/java/co/omise/models/schedules/Schedule.java @@ -155,7 +155,7 @@ public void setTransfer(TransferSchedule transfer) { } public static class DeleteRequestBuilder extends RequestBuilder { - private String scheduleId; + private final String scheduleId; public DeleteRequestBuilder(String scheduleId) { this.scheduleId = scheduleId; } @@ -177,16 +177,11 @@ protected ResponseType type() { } public static class GetRequestBuilder extends RequestBuilder { - private String scheduleId; + private final String scheduleId; public GetRequestBuilder(String scheduleId) { this.scheduleId = scheduleId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { return buildUrl(Endpoint.API, "schedules", scheduleId); @@ -201,11 +196,6 @@ protected ResponseType type() { public static class ListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -302,17 +292,12 @@ protected RequestBody payload() throws IOException { } public static class ListOccurrencesRequestBuilder extends RequestBuilder> { - private String scheduleId; + private final String scheduleId; private ScopedList.Options options; public ListOccurrencesRequestBuilder(String scheduleId) { this.scheduleId = scheduleId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -336,17 +321,12 @@ public ListOccurrencesRequestBuilder options(ScopedList.Options options) { } public static class CustomerScheduleListRequestBuilder extends RequestBuilder> { - private String customerId; + private final String customerId; private ScopedList.Options options; public CustomerScheduleListRequestBuilder(String customerId) { this.customerId = customerId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -370,17 +350,12 @@ public CustomerScheduleListRequestBuilder options(ScopedList.Options options) { } public static class RecipientScheduleListRequestBuilder extends RequestBuilder> { - private String recipientId; + private final String recipientId; private ScopedList.Options options; public RecipientScheduleListRequestBuilder(String recipientId) { this.recipientId = recipientId; } - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { @@ -406,11 +381,6 @@ public RecipientScheduleListRequestBuilder options(ScopedList.Options options) { public static class TransferScheduleListRequestBuilder extends RequestBuilder> { private ScopedList.Options options; - @Override - protected String method() { - return GET; - } - @Override protected HttpUrl path() { if (options == null) { diff --git a/src/main/java/co/omise/models/schedules/SchedulePeriod.java b/src/main/java/co/omise/models/schedules/SchedulePeriod.java index d4abadab..654f461d 100644 --- a/src/main/java/co/omise/models/schedules/SchedulePeriod.java +++ b/src/main/java/co/omise/models/schedules/SchedulePeriod.java @@ -8,5 +8,5 @@ public enum SchedulePeriod { @JsonProperty("month") Month, @JsonProperty("week") - Week; + Week } \ No newline at end of file diff --git a/src/main/java/co/omise/models/schedules/ScheduleStatus.java b/src/main/java/co/omise/models/schedules/ScheduleStatus.java index c2332de3..d7a47aef 100644 --- a/src/main/java/co/omise/models/schedules/ScheduleStatus.java +++ b/src/main/java/co/omise/models/schedules/ScheduleStatus.java @@ -14,5 +14,5 @@ public enum ScheduleStatus { @JsonProperty("running") Running, @JsonProperty("suspended") - Suspended; + Suspended } \ No newline at end of file diff --git a/src/main/java/co/omise/models/schedules/Weekdays.java b/src/main/java/co/omise/models/schedules/Weekdays.java index e44544fb..56d30384 100644 --- a/src/main/java/co/omise/models/schedules/Weekdays.java +++ b/src/main/java/co/omise/models/schedules/Weekdays.java @@ -16,5 +16,5 @@ public enum Weekdays { @JsonProperty("tuesday") Tuesday, @JsonProperty("wednesday") - Wednesday; + Wednesday } \ No newline at end of file diff --git a/src/main/java/co/omise/requests/RequestBuilder.java b/src/main/java/co/omise/requests/RequestBuilder.java index 2ab30804..34f61b98 100644 --- a/src/main/java/co/omise/requests/RequestBuilder.java +++ b/src/main/java/co/omise/requests/RequestBuilder.java @@ -52,9 +52,8 @@ protected String method() { * Abstract method that needs to be implement by all children of this class to provide API Path * * @return the url path as {@link HttpUrl} - * @throws IOException the I/O when {@link Serializer} is unable to correctly serialize the content of the class using Jackson */ - protected abstract HttpUrl path() throws IOException; + protected abstract HttpUrl path(); /** * Default Content type of the HTTP Request. @@ -131,12 +130,12 @@ protected HttpUrl buildUrl(Endpoint endpoint, String path, Params params) { return new HttpUrlBuilder(endpoint, path, serializer).params(params).build(); } - public class HttpUrlBuilder { - private Endpoint endpoint; - private String path; + public static class HttpUrlBuilder { + private final Endpoint endpoint; + private final String path; private String[] segments; private Params params; - private Serializer serializer; + private final Serializer serializer; public HttpUrlBuilder(Endpoint endpoint, String path, Serializer serializer) { this.endpoint = endpoint; @@ -166,7 +165,7 @@ public HttpUrl build() { continue; } - builder = builder.addPathSegment(segment); + builder.addPathSegment(segment); } } @@ -174,7 +173,7 @@ public HttpUrl build() { Map queries = params.query(serializer); if (!queries.isEmpty()) { for (Map.Entry pair : queries.entrySet()) { - builder = builder.addQueryParameter(pair.getKey(), pair.getValue()); + builder.addQueryParameter(pair.getKey(), pair.getValue()); } } } diff --git a/src/main/java/co/omise/requests/RequesterImpl.java b/src/main/java/co/omise/requests/RequesterImpl.java index f69332ac..75890ac3 100644 --- a/src/main/java/co/omise/requests/RequesterImpl.java +++ b/src/main/java/co/omise/requests/RequesterImpl.java @@ -17,8 +17,8 @@ * @see Serializer */ public class RequesterImpl implements Requester { - private OkHttpClient httpClient; - private Serializer serializer; + private final OkHttpClient httpClient; + private final Serializer serializer; /** * Instantiates a new RequesterImpl instance. diff --git a/src/test/java/co/omise/ConfigTest.java b/src/test/java/co/omise/ConfigTest.java index c5b27c87..3b36ef65 100644 --- a/src/test/java/co/omise/ConfigTest.java +++ b/src/test/java/co/omise/ConfigTest.java @@ -20,15 +20,14 @@ public void testCtor() { @Test public void testUserAgent() { - StringBuilder builder = new StringBuilder(); - builder.append("OmiseJava/"); - builder.append(PKG_VERSION); - builder.append(" OmiseAPI/"); - builder.append(API_VERSION); - builder.append(" Java/"); - builder.append(JAVA_VERSION); + String builder = "OmiseJava/" + + PKG_VERSION + + " OmiseAPI/" + + API_VERSION + + " Java/" + + JAVA_VERSION; - assertEquals(builder.toString(), config().userAgent()); + assertEquals(builder, config().userAgent()); } static Config config() { diff --git a/src/test/java/co/omise/SerializableTest.java b/src/test/java/co/omise/SerializableTest.java index fccdf3ac..3b721870 100644 --- a/src/test/java/co/omise/SerializableTest.java +++ b/src/test/java/co/omise/SerializableTest.java @@ -7,7 +7,7 @@ import java.io.*; public class SerializableTest { - private String filename = "file.ser"; + private final String filename = "file.ser"; private Account account; diff --git a/src/test/java/co/omise/SerializerTest.java b/src/test/java/co/omise/SerializerTest.java index 28217ed5..e8049b7a 100644 --- a/src/test/java/co/omise/SerializerTest.java +++ b/src/test/java/co/omise/SerializerTest.java @@ -27,8 +27,7 @@ public void testSerialize() throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); serializer().serialize(outputStream, new Dummy()); - byte[] bytes = outputStream.toByteArray(); - assertEquals(DUMMY_JSON, new String(bytes, 0, bytes.length)); + assertEquals(DUMMY_JSON, outputStream.toString()); } @Test @@ -36,8 +35,7 @@ public void testSerializeParams() throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); serializer().serializeParams(outputStream, new DummyParams()); - byte[] bytes = outputStream.toByteArray(); - assertEquals(DUMMY_PARAMS_JSON, new String(bytes, 0, bytes.length)); + assertEquals(DUMMY_PARAMS_JSON, outputStream.toString()); } @Test @@ -127,9 +125,9 @@ public void setHello(String hello) { public static final class DummyParams extends Params { @JsonProperty - private String hello; + private final String hello; @JsonProperty("what") - private String another; + private final String another; public DummyParams() { hello = "world"; diff --git a/src/test/java/co/omise/live/LiveCapabilityRequest.java b/src/test/java/co/omise/live/LiveCapabilityRequestTest.java similarity index 93% rename from src/test/java/co/omise/live/LiveCapabilityRequest.java rename to src/test/java/co/omise/live/LiveCapabilityRequestTest.java index df585a9f..511dd7a7 100644 --- a/src/test/java/co/omise/live/LiveCapabilityRequest.java +++ b/src/test/java/co/omise/live/LiveCapabilityRequestTest.java @@ -9,7 +9,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class LiveCapabilityRequest extends BaseLiveTest { +public class LiveCapabilityRequestTest extends BaseLiveTest { @Test @Ignore("only hit when test on live.") diff --git a/src/test/java/co/omise/models/SerializationTest.java b/src/test/java/co/omise/models/SerializationTest.java index 260308eb..bf749e52 100644 --- a/src/test/java/co/omise/models/SerializationTest.java +++ b/src/test/java/co/omise/models/SerializationTest.java @@ -11,7 +11,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.NotSerializableException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Map; @@ -79,6 +78,7 @@ private void assertMapEquals(String prefix, Map expectedMap, Map assertNotNull(prefix + "." + entry.getKey(), actual); } + assert expected != null; assertEquals(prefix + "." + entry.getKey() + " has mismatched value.", expected.getClass(), actual.getClass()); assertEquals(prefix + "." + entry.getKey() + " has mismatched value.", expected, actual); } @@ -98,10 +98,10 @@ private String objectJsonName(Class klass) { /** * Check if object is serializable * - * @param instance - * @throws NotSerializableException + * @param instance The object to check for serializability. + * @throws IOException If an I/O error occurs during serialization. */ - private void assertSerializable(OmiseObject instance) throws IOException, NotSerializableException { + private void assertSerializable(OmiseObject instance) throws IOException { OutputStream out = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(out); diff --git a/src/test/java/co/omise/requests/CardRequestTest.java b/src/test/java/co/omise/requests/CardRequestTest.java index c01ae718..b2dfc326 100644 --- a/src/test/java/co/omise/requests/CardRequestTest.java +++ b/src/test/java/co/omise/requests/CardRequestTest.java @@ -3,7 +3,7 @@ import co.omise.models.Card; import co.omise.models.OmiseException; import co.omise.models.ScopedList; -import com.fasterxml.jackson.core.type.TypeReference; + import org.junit.Test; import java.io.IOException; diff --git a/src/test/java/co/omise/requests/ChargeRequestTest.java b/src/test/java/co/omise/requests/ChargeRequestTest.java index 7923a093..f9378eca 100644 --- a/src/test/java/co/omise/requests/ChargeRequestTest.java +++ b/src/test/java/co/omise/requests/ChargeRequestTest.java @@ -9,7 +9,7 @@ import org.junit.Test; import java.io.IOException; -import java.util.Arrays; +import java.util.Collections; public class ChargeRequestTest extends RequestTest { private final String CHARGE_ID = "chrg_test_4yq7duw15p9hdrjp8oq"; @@ -53,7 +53,7 @@ public void testCreateWithWebhooks() throws IOException, OmiseException { new Charge.CreateRequestBuilder() .amount(100000) .currency("thb") - .webhookEndpoints(Arrays.asList("https://webhook.site/123")) + .webhookEndpoints(Collections.singletonList("https://webhook.site/123")) .build(); Charge charge = getTestRequester().sendRequest(createChargeRequest); @@ -179,7 +179,7 @@ public void testDisputable() throws IOException, OmiseException { Charge charge = getTestRequester().sendRequest(getChargeRequest); assertRequested("GET", "/charges/" + CHARGE_ID, 200); - assertEquals(false, charge.isDisputable()); + assertFalse(charge.isDisputable()); } @Test @@ -189,7 +189,7 @@ public void testCapturable() throws IOException, OmiseException { Charge charge = getTestRequester().sendRequest(getChargeRequest); assertRequested("GET", "/charges/" + CHARGE_ID, 200); - assertEquals(false, charge.isCapturable()); + assertFalse(charge.isCapturable()); } @Test @@ -199,7 +199,7 @@ public void testReversible() throws IOException, OmiseException { Charge charge = getTestRequester().sendRequest(getChargeRequest); assertRequested("GET", "/charges/" + CHARGE_ID, 200); - assertEquals(false, charge.isReversible()); + assertFalse(charge.isReversible()); } @Test @@ -209,7 +209,7 @@ public void testRefundable() throws IOException, OmiseException { Charge charge = getTestRequester().sendRequest(getChargeRequest); assertRequested("GET", "/charges/" + CHARGE_ID, 200); - assertEquals(false, charge.isRefundable()); + assertFalse(charge.isRefundable()); } } diff --git a/src/test/java/co/omise/testutils/TestInterceptor.java b/src/test/java/co/omise/testutils/TestInterceptor.java index 834dcc40..56d4fad8 100644 --- a/src/test/java/co/omise/testutils/TestInterceptor.java +++ b/src/test/java/co/omise/testutils/TestInterceptor.java @@ -17,7 +17,7 @@ public TestInterceptor(OmiseTest test) { } @Override - public Response intercept(Chain chain) throws IOException { + public Response intercept(Chain chain) { Request request = chain.request(); HttpUrl url = request.url(); lastRequest = request;