Skip to content

Commit 68d7865

Browse files
add a test
1 parent aa02720 commit 68d7865

File tree

2 files changed

+109
-5
lines changed

2 files changed

+109
-5
lines changed

‎pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<groupId>org.apache.maven.plugins</groupId>
99
<artifactId>maven-compiler-plugin</artifactId>
1010
<configuration>
11-
<source>1.8</source>
12-
<target>1.8</target>
11+
<source>9</source>
12+
<target>9</target>
1313
</configuration>
1414
</plugin>
1515
</plugins>

‎src/test/b2SdkExamples/B2JsonTest.java

+107-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import com.google.gson.Gson;
66
import com.google.gson.GsonBuilder;
77
import org.json.JSONException;
8+
import org.junit.Ignore;
89
import org.junit.Test;
910
import org.skyscreamer.jsonassert.JSONAssert;
1011

12+
import java.math.BigDecimal;
1113
import java.time.LocalDate;
1214
import java.time.LocalDateTime;
13-
import java.util.Objects;
15+
import java.util.*;
1416

1517
import static org.junit.Assert.assertEquals;
1618

@@ -157,26 +159,128 @@ private static class TestResponse {
157159
@B2Json.optional(omitNull = true)
158160
public final LocalDate localDate;
159161

162+
@B2Json.required
163+
public final Map<Integer, Map<String, BigDecimal>> revenueMap;
164+
165+
@B2Json.required
166+
public final Map<String, Long> simpleMap;
167+
168+
@B2Json.required
169+
public final Set<String> categories;
170+
160171
@B2Json.constructor(params = "" +
161172
"str," +
162173
"message," +
163174
"reason," +
164175
"succeeded," +
165176
"status," +
166177
"localDateTime," +
167-
"localDate"
178+
"localDate," +
179+
"revenueMap," +
180+
"simpleMap," +
181+
"categories"
168182
)
169-
public TestResponse(String str, String message, String reason, boolean succeeded, int status, LocalDateTime localDateTime, LocalDate localDate) {
183+
public TestResponse(String str, String message, String reason, boolean succeeded, int status, LocalDateTime localDateTime, LocalDate localDate,
184+
Map<Integer, Map<String, BigDecimal>> revenueMap,
185+
Map<String, Long> simpleMap,
186+
Set<String> categories) {
170187
this.str = str;
171188
this.message = message;
172189
this.reason = reason;
173190
this.succeeded = succeeded;
174191
this.status = status;
175192
this.localDateTime = localDateTime;
176193
this.localDate = localDate;
194+
this.simpleMap = simpleMap;
195+
this.revenueMap = revenueMap;
196+
this.categories = categories;
177197
}
178198
}
179199

200+
// @Test
201+
// public void testResponseUsingB2Json() throws B2JsonException, JSONException {
202+
// Map<String, Map<String, BigDecimal>> revenueMap = new TreeMap<>();
203+
// Map<String, Long> simpleMap = new TreeMap<>();
204+
// TestResponse obj = new TestResponse("str",
205+
// "message",
206+
// "reason",
207+
// true,
208+
// 200,
209+
// LocalDateTime.of(2023, 03, 31, 12, 21),
210+
// LocalDate.of(2023, 03, 31),
211+
// revenueMap,
212+
// simpleMap,
213+
// Set.of("test"));
214+
// System.out.println("obj is: " + obj);
215+
// String expected = "{\n" +
216+
// " \"categories\": [\n" +
217+
// " \"test\"\n" +
218+
// " ],\n" +
219+
// " \"localDate\": \"20230331\",\n" +
220+
// " \"localDateTime\": \"d20230331_m122100\",\n" +
221+
// " \"message\": \"message\",\n" +
222+
// " \"reason\": \"reason\",\n" +
223+
// " \"revenueMap\": {},\n" +
224+
// " \"simpleMap\": {},\n" +
225+
// " \"status\": 200,\n" +
226+
// " \"str\": \"str\",\n" +
227+
// " \"succeeded\": true\n" +
228+
// "}";
229+
// System.out.println("b2Json.toJson(obj): " + b2Json.toJson(obj));
230+
// JSONAssert.assertEquals(expected, b2Json.toJson(obj), true);
231+
// }
232+
233+
@Test
234+
@Ignore
235+
public void testResponseUsingGson() throws JSONException {
236+
Map<Integer, Map<String, BigDecimal>> revenueMap = new TreeMap<>();
237+
revenueMap.put(123, new HashMap<>());
238+
Map<String, Long> simpleMap = new TreeMap<>();
239+
TestResponse obj = new TestResponse("str",
240+
"message",
241+
"reason",
242+
true,
243+
200,
244+
LocalDateTime.of(2023, 03, 31, 12, 21),
245+
LocalDate.of(2023, 03, 31),
246+
revenueMap,
247+
simpleMap,
248+
Set.of("test"));
249+
System.out.println("obj is: " + obj);
250+
String expected = "{\n" +
251+
" \"str\": \"str\",\n" +
252+
" \"message\": \"message\",\n" +
253+
" \"reason\": \"reason\",\n" +
254+
" \"succeeded\": true,\n" +
255+
" \"status\": 200,\n" +
256+
" \"localDateTime\": {\n" +
257+
" \"date\": {\n" +
258+
" \"year\": 2023,\n" +
259+
" \"month\": 3,\n" +
260+
" \"day\": 31\n" +
261+
" },\n" +
262+
" \"time\": {\n" +
263+
" \"hour\": 12,\n" +
264+
" \"minute\": 21,\n" +
265+
" \"second\": 0,\n" +
266+
" \"nano\": 0\n" +
267+
" }\n" +
268+
" },\n" +
269+
" \"localDate\": {\n" +
270+
" \"year\": 2023,\n" +
271+
" \"month\": 3,\n" +
272+
" \"day\": 31\n" +
273+
" },\n" +
274+
" \"revenueMap\": {},\n" +
275+
" \"simpleMap\": {},\n" +
276+
" \"categories\": [\n" +
277+
" \"test\"\n" +
278+
" ]\n" +
279+
"}";
280+
System.out.println("b2Json.toJson(obj): " + gson.toJson(obj));
281+
JSONAssert.assertEquals(expected, gson.toJson(obj), true);
282+
}
283+
180284
@Test
181285
public void testObject() throws B2JsonException {
182286
String json = "{\n" +

0 commit comments

Comments
 (0)