4
4
import com .backblaze .b2 .json .B2JsonException ;
5
5
import com .google .gson .Gson ;
6
6
import com .google .gson .GsonBuilder ;
7
- import org .json .JSONArray ;
8
7
import org .json .JSONException ;
9
- import org .junit .Ignore ;
10
8
import org .junit .Test ;
11
9
import org .skyscreamer .jsonassert .JSONAssert ;
12
10
@@ -162,7 +160,7 @@ private static class TestResponse {
162
160
public final LocalDate localDate ;
163
161
164
162
@ B2Json .required
165
- public final Map <Integer , Map <String , BigDecimal >> revenueMap ;
163
+ public final Map <String , Map <String , BigDecimal >> revenueMap ;
166
164
167
165
@ B2Json .required
168
166
public final Map <String , Long > simpleMap ;
@@ -183,7 +181,7 @@ private static class TestResponse {
183
181
"categories"
184
182
)
185
183
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 ,
187
185
Map <String , Long > simpleMap ,
188
186
Set <String > categories ) {
189
187
this .str = str ;
@@ -199,44 +197,44 @@ public TestResponse(String str, String message, String reason, boolean succeeded
199
197
}
200
198
}
201
199
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
+ }
234
233
235
234
@ Test
236
- @ Ignore
237
235
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 <>());
240
238
Map <String , Long > simpleMap = new TreeMap <>();
241
239
TestResponse obj = new TestResponse ("str" ,
242
240
"message" ,
@@ -248,7 +246,6 @@ public void testResponseUsingGson() throws JSONException {
248
246
revenueMap ,
249
247
simpleMap ,
250
248
Set .of ("test" ));
251
- System .out .println ("obj is: " + obj );
252
249
String expected = "{\n " +
253
250
" \" str\" : \" str\" ,\n " +
254
251
" \" message\" : \" message\" ,\n " +
@@ -273,13 +270,14 @@ public void testResponseUsingGson() throws JSONException {
273
270
" \" month\" : 3,\n " +
274
271
" \" day\" : 31\n " +
275
272
" },\n " +
276
- " \" revenueMap\" : {},\n " +
273
+ " \" revenueMap\" : {\n " +
274
+ " \" 123\" : {}\n " +
275
+ " },\n " +
277
276
" \" simpleMap\" : {},\n " +
278
277
" \" categories\" : [\n " +
279
278
" \" test\" \n " +
280
279
" ]\n " +
281
280
"}" ;
282
- System .out .println ("b2Json.toJson(obj): " + gson .toJson (obj ));
283
281
JSONAssert .assertEquals (expected , gson .toJson (obj ), true );
284
282
}
285
283
0 commit comments