Skip to content

Commit

Permalink
Make PlatformFee implements Serializable interface (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
rezigned authored Aug 24, 2020
1 parent c5fc95a commit 5312389
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.github.ben-manes.versions'

group 'co.omise'
version '4.0.0'
version '4.0.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/co/omise/models/PlatformFee.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public class PlatformFee {
import java.io.Serializable;

public class PlatformFee implements Serializable {
private long amount;
private long fixed;
private Double percentage;
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/co/omise/models/SerializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import org.junit.Test;

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;

public class SerializationTest extends OmiseTest {
Expand All @@ -20,6 +24,8 @@ public void testModelSerializability() throws IOException {
byte[] sampleBytes = getResourceBytes(objectJsonName(testcase.getValue()));
OmiseObject instance = serializer.deserialize(new ByteArrayInputStream(sampleBytes), testcase.getValue());

assertSerializable(instance);

Map<String, Object> map = serializer.serializeToMap(instance);
Map<String, Object> comparison = serializer.objectMapper().readValue(sampleBytes, new TypeReference<Map<String, Object>>() {
});
Expand All @@ -29,6 +35,7 @@ public void testModelSerializability() throws IOException {
}

private void assertMapEquals(String prefix, Map<String, Object> expectedMap, Map<String, Object> actualMap) {

MapDifference<String, Object> differences = Maps.difference(expectedMap, actualMap);
if (differences.entriesDiffering().size() == 0 && differences.entriesOnlyOnLeft().size() == 0) {
return; // all good : )
Expand Down Expand Up @@ -87,4 +94,17 @@ private String objectJsonName(Class klass) {
return "/testdata/objects/" + fileName + "_object.json";
}
}

/**
* Check if object is serializable
*
* @param instance
* @throws NotSerializableException
*/
private void assertSerializable(OmiseObject instance) throws IOException, NotSerializableException {
OutputStream out = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(out);

stream.writeObject(instance);
}
}

0 comments on commit 5312389

Please sign in to comment.