Skip to content

Commit 5eb9e11

Browse files
fix B2Json tests
1 parent 2b0a864 commit 5eb9e11

File tree

1 file changed

+40
-42
lines changed

1 file changed

+40
-42
lines changed

src/test/b2SdkExamples/B2JsonTest.java

+40-42
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.backblaze.b2.json.B2JsonException;
55
import com.google.gson.Gson;
66
import com.google.gson.GsonBuilder;
7-
import org.json.JSONArray;
87
import org.json.JSONException;
9-
import org.junit.Ignore;
108
import org.junit.Test;
119
import org.skyscreamer.jsonassert.JSONAssert;
1210

@@ -162,7 +160,7 @@ private static class TestResponse {
162160
public final LocalDate localDate;
163161

164162
@B2Json.required
165-
public final Map<Integer, Map<String, BigDecimal>> revenueMap;
163+
public final Map<String, Map<String, BigDecimal>> revenueMap;
166164

167165
@B2Json.required
168166
public final Map<String, Long> simpleMap;
@@ -183,7 +181,7 @@ private static class TestResponse {
183181
"categories"
184182
)
185183
public TestResponse(String str, String message, String reason, boolean succeeded, int status, LocalDateTime localDateTime, LocalDate localDate,
186-
Map<Integer, Map<String, BigDecimal>> revenueMap,
184+
Map<String, Map<String, BigDecimal>> revenueMap,
187185
Map<String, Long> simpleMap,
188186
Set<String> categories) {
189187
this.str = str;
@@ -199,44 +197,44 @@ public TestResponse(String str, String message, String reason, boolean succeeded
199197
}
200198
}
201199

202-
// @Test
203-
// public void testResponseUsingB2Json() throws B2JsonException, JSONException {
204-
// Map<String, Map<String, BigDecimal>> revenueMap = new TreeMap<>();
205-
// Map<String, Long> simpleMap = new TreeMap<>();
206-
// TestResponse obj = new TestResponse("str",
207-
// "message",
208-
// "reason",
209-
// true,
210-
// 200,
211-
// LocalDateTime.of(2023, 03, 31, 12, 21),
212-
// LocalDate.of(2023, 03, 31),
213-
// revenueMap,
214-
// simpleMap,
215-
// Set.of("test"));
216-
// System.out.println("obj is: " + obj);
217-
// String expected = "{\n" +
218-
// " \"categories\": [\n" +
219-
// " \"test\"\n" +
220-
// " ],\n" +
221-
// " \"localDate\": \"20230331\",\n" +
222-
// " \"localDateTime\": \"d20230331_m122100\",\n" +
223-
// " \"message\": \"message\",\n" +
224-
// " \"reason\": \"reason\",\n" +
225-
// " \"revenueMap\": {},\n" +
226-
// " \"simpleMap\": {},\n" +
227-
// " \"status\": 200,\n" +
228-
// " \"str\": \"str\",\n" +
229-
// " \"succeeded\": true\n" +
230-
// "}";
231-
// System.out.println("b2Json.toJson(obj): " + b2Json.toJson(obj));
232-
// JSONAssert.assertEquals(expected, b2Json.toJson(obj), true);
233-
// }
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("test1", "test2"));
214+
System.out.println("obj is: " + obj);
215+
String expected = "{\n" +
216+
" \"categories\": [\n" +
217+
" \"test1\",\n" +
218+
" \"test2\"\n" +
219+
" ],\n" +
220+
" \"localDate\": \"20230331\",\n" +
221+
" \"localDateTime\": \"d20230331_m122100\",\n" +
222+
" \"message\": \"message\",\n" +
223+
" \"reason\": \"reason\",\n" +
224+
" \"revenueMap\": {},\n" +
225+
" \"simpleMap\": {},\n" +
226+
" \"status\": 200,\n" +
227+
" \"str\": \"str\",\n" +
228+
" \"succeeded\": true\n" +
229+
"}";
230+
System.out.println("b2Json.toJson(obj): " + b2Json.toJson(obj));
231+
JSONAssert.assertEquals(expected, b2Json.toJson(obj), true);
232+
}
234233

235234
@Test
236-
@Ignore
237235
public void testResponseUsingGson() throws JSONException {
238-
Map<Integer, Map<String, BigDecimal>> revenueMap = new TreeMap<>();
239-
revenueMap.put(123, new HashMap<>());
236+
Map<String, Map<String, BigDecimal>> revenueMap = new TreeMap<>();
237+
revenueMap.put("123", new HashMap<>());
240238
Map<String, Long> simpleMap = new TreeMap<>();
241239
TestResponse obj = new TestResponse("str",
242240
"message",
@@ -248,7 +246,6 @@ public void testResponseUsingGson() throws JSONException {
248246
revenueMap,
249247
simpleMap,
250248
Set.of("test"));
251-
System.out.println("obj is: " + obj);
252249
String expected = "{\n" +
253250
" \"str\": \"str\",\n" +
254251
" \"message\": \"message\",\n" +
@@ -273,13 +270,14 @@ public void testResponseUsingGson() throws JSONException {
273270
" \"month\": 3,\n" +
274271
" \"day\": 31\n" +
275272
" },\n" +
276-
" \"revenueMap\": {},\n" +
273+
" \"revenueMap\": {\n" +
274+
" \"123\": {}\n" +
275+
" },\n" +
277276
" \"simpleMap\": {},\n" +
278277
" \"categories\": [\n" +
279278
" \"test\"\n" +
280279
" ]\n" +
281280
"}";
282-
System.out.println("b2Json.toJson(obj): " + gson.toJson(obj));
283281
JSONAssert.assertEquals(expected, gson.toJson(obj), true);
284282
}
285283

0 commit comments

Comments
 (0)