|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertThrows; |
6 | 6 | import static org.junit.jupiter.api.Assertions.assertTrue; |
7 | 7 |
|
| 8 | +import com.google.gson.Gson; |
| 9 | +import com.google.gson.GsonBuilder; |
| 10 | +import com.google.gson.annotations.JsonAdapter; |
8 | 11 | import com.google.gson.annotations.SerializedName; |
| 12 | +import com.stripe.model.StringInt64TypeAdapter; |
9 | 13 | import com.stripe.param.common.EmptyParam; |
10 | 14 | import java.time.Instant; |
11 | 15 | import java.util.Arrays; |
@@ -122,6 +126,12 @@ private static class HasInstantParam extends ApiRequestParams { |
122 | 126 | public Instant instantParam; |
123 | 127 | } |
124 | 128 |
|
| 129 | + private static class HasStringInt64Param extends ApiRequestParams { |
| 130 | + @SerializedName("divide_by") |
| 131 | + @JsonAdapter(StringInt64TypeAdapter.class) |
| 132 | + public Long divideBy; |
| 133 | + } |
| 134 | + |
125 | 135 | @Test |
126 | 136 | public void testHasExtraParams() { |
127 | 137 | ModelHasExtraParams params = new ModelHasExtraParams(ParamCode.ENUM_FOO); |
@@ -288,6 +298,28 @@ public void testObjectMaps() { |
288 | 298 | assertEquals(objBar.get("hello"), "world"); |
289 | 299 | } |
290 | 300 |
|
| 301 | + @Test |
| 302 | + public void testToMapWithStringInt64Params() { |
| 303 | + HasStringInt64Param params = new HasStringInt64Param(); |
| 304 | + params.divideBy = 123L; |
| 305 | + |
| 306 | + Map<String, Object> paramMap = toMap(params); |
| 307 | + |
| 308 | + TestCase.assertEquals(1, paramMap.size()); |
| 309 | + TestCase.assertTrue(paramMap.containsKey("divide_by")); |
| 310 | + TestCase.assertEquals("123", paramMap.get("divide_by")); |
| 311 | + } |
| 312 | + |
| 313 | + @Test |
| 314 | + public void testFromJsonWithStringInt64ResourceField() { |
| 315 | + Gson gson = new GsonBuilder().create(); |
| 316 | + |
| 317 | + HasStringInt64Param resource = |
| 318 | + gson.fromJson("{\"divide_by\":\"123\"}", HasStringInt64Param.class); |
| 319 | + |
| 320 | + TestCase.assertEquals(Long.valueOf(123L), resource.divideBy); |
| 321 | + } |
| 322 | + |
291 | 323 | @Test |
292 | 324 | public void testToMapWithInstantParams() { |
293 | 325 | HasInstantParam params = new HasInstantParam(); |
|
0 commit comments