-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (Mailgun/Email): Simplify some fields as Boolean
- Loading branch information
Showing
9 changed files
with
189 additions
and
487 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
client/src/main/com/sinch/sdk/domains/mailgun/api/v1/adapters/BooleanFormSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import com.sinch.sdk.core.databind.FormSerializer; | ||
import java.util.Map; | ||
|
||
public class BooleanFormSerializer extends FormSerializer<Boolean> { | ||
|
||
@Override | ||
public void serialize(Boolean in, String fieldName, Map<String, Object> out) { | ||
if (null != in) { | ||
out.put(fieldName, format(in)); | ||
} | ||
} | ||
|
||
private static String format(Boolean value) { | ||
return String.format("%s", value); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...rc/test/java/com/sinch/sdk/domains/mailgun/api/v1/adapters/BooleanFormSerializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.sinch.sdk.core.TestHelpers; | ||
import java.util.HashMap; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class BooleanFormSerializerTest { | ||
BooleanFormSerializer serializer = new BooleanFormSerializer(); | ||
|
||
@Test | ||
void serializeTrue() { | ||
|
||
HashMap<String, Object> map = new HashMap<>(); | ||
|
||
serializer.serialize(true, "key name", map); | ||
|
||
TestHelpers.recursiveEquals("true", map.get("key name")); | ||
} | ||
|
||
@Test | ||
void serializeFalse() { | ||
|
||
HashMap<String, Object> map = new HashMap<>(); | ||
|
||
serializer.serialize(false, "key name", map); | ||
|
||
TestHelpers.recursiveEquals("false", map.get("key name")); | ||
} | ||
|
||
@Test | ||
void serializeNull() { | ||
|
||
HashMap<String, Object> map = new HashMap<>(); | ||
|
||
serializer.serialize(null, "key name", map); | ||
|
||
Assertions.assertNull(map.get("key name")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.