Skip to content

Commit 063fc76

Browse files
committed
test(sdk): add testcase of toJSONString()
1 parent 110a00e commit 063fc76

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

sdk/src/test/java/com/deploygate/sdk/CustomAttributesTest.java

+40
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,46 @@ public void size() {
8989
Truth.assertThat(attributes.size()).isEqualTo(0);
9090
}
9191

92+
@Test
93+
public void toJSONString() {
94+
Truth.assertThat(attributes.getJSONString()).isEqualTo("{}");
95+
96+
attributes.putString("string", "value");
97+
attributes.putInt("int", Integer.MAX_VALUE);
98+
attributes.putLong("long", Long.MAX_VALUE);
99+
attributes.putFloat("float", Float.MAX_VALUE);
100+
attributes.putDouble("double", Double.MAX_VALUE);
101+
attributes.putBoolean("boolean", true);
102+
103+
String expectedJSON = "{" +
104+
"\"string\":\"value\"," +
105+
"\"int\":2147483647," +
106+
"\"long\":9223372036854775807," +
107+
"\"float\":3.4028235E38," +
108+
"\"double\":1.7976931348623157E308," +
109+
"\"boolean\":true" +
110+
"}";
111+
Truth.assertThat(attributes.getJSONString()).isEqualTo(expectedJSON);
112+
113+
attributes.removeAll();
114+
attributes.putString("string2", "value2");
115+
attributes.putInt("int2", Integer.MIN_VALUE);
116+
attributes.putLong("long2", Long.MIN_VALUE);
117+
attributes.putFloat("float2", Float.MIN_VALUE);
118+
attributes.putDouble("double2", Double.MIN_VALUE);
119+
attributes.putBoolean("boolean2", false);
120+
121+
String expectedJSON2 = "{" +
122+
"\"string2\":\"value2\"," +
123+
"\"int2\":-2147483648," +
124+
"\"long2\":-9223372036854775808," +
125+
"\"float2\":1.4E-45," +
126+
"\"double2\":4.9E-324," +
127+
"\"boolean2\":false" +
128+
"}";
129+
Truth.assertThat(attributes.getJSONString()).isEqualTo(expectedJSON2);
130+
}
131+
92132
@Test
93133
public void not_exceed_max_size() {
94134
Truth.assertThat(attributes.putString("key1", "value1")).isTrue();

0 commit comments

Comments
 (0)