@@ -211,6 +211,9 @@ public void testRemoveIrrelevantBackgroundStartRequests() throws NoSuchMethodExc
211211 LeanplumEventDataManagerTest .setDatabaseToNull ();
212212 }
213213
214+ // Given a list of unsent requests
215+ // we want to get the list of strings to send
216+ // We should get back the correct list of requests to send
214217 @ Test
215218 public void testJsonEncodeUnsentRequestsWithExceptionLargeNumbers () throws NoSuchMethodException ,
216219 InvocationTargetException , IllegalAccessException {
@@ -263,7 +266,7 @@ public void testJsonEncodeUnsentRequestsWithExceptionLargeNumbers() throws NoSuc
263266
264267 @ Test
265268 public void testJsonEncodeUnsentRequestsWithException () {
266- List <Map <String , Object >> requests = mockRequests (2 , 2 );
269+ List <Map <String , Object >> requests = mockRequests (4 );
267270
268271 Request realRequest = new Request ("POST" , Constants .Methods .START , null );
269272 Request request = spy (realRequest );
@@ -273,39 +276,43 @@ public void testJsonEncodeUnsentRequestsWithException() {
273276
274277 Request .RequestsWithEncoding requestsWithEncoding = request .getRequestsWithEncodedStringStoredRequests (1.0 );
275278
276- assertEquals ("{\" data\" :[{\" 0\" :\" 0\" },{\" 0\" :\" 1\" },{\" 1\" :\" 0\" },{\" 1\" :\" 1\" }]}" , requestsWithEncoding .jsonEncodedString );
279+ assertEquals (4 , requestsWithEncoding .unsentRequests .size ());
280+ assertEquals (4 , requestsWithEncoding .requestsToSend .size ());
281+ final String expectedJson = "{\" data\" :[{\" 0\" :\" testData\" },{\" 1\" :\" testData\" },{\" 2\" :\" testData\" },{\" 3\" :\" testData\" }]}" ;
282+ assertEquals (expectedJson , requestsWithEncoding .jsonEncodedString );
277283 }
278284
285+ // Given a list of requests
286+ // we want to encode to a JSON String
287+ // The String should have the expected format
279288 @ Test
280289 public void testJsonEncodeUnsentRequests () {
281- List <Map <String , Object >> requests = mockRequests (2 , 2 );
290+ List <Map <String , Object >> requests = mockRequests (4 );
282291
283292 Request realRequest = new Request ("POST" , Constants .Methods .START , null );
284293 Request request = spy (realRequest );
285294 when (request .getUnsentRequests (1.0 )).thenReturn (requests );
286295
287296 Request .RequestsWithEncoding requestsWithEncoding = request .getRequestsWithEncodedStringStoredRequests (1.0 );
288-
289- assertEquals ("{ \" data \" :[{ \" 0 \" : \" 0 \" },{ \" 0 \" : \" 1 \" },{ \" 1 \" : \" 0 \" },{ \" 1 \" : \" 1 \" }]}" , requestsWithEncoding .jsonEncodedString );
297+ final String expectedJson = "{ \" data \" :[{ \" 0 \" : \" testData \" },{ \" 1 \" : \" testData \" },{ \" 2 \" : \" testData \" },{ \" 3 \" : \" testData \" }]}" ;
298+ assertEquals (expectedJson , requestsWithEncoding .jsonEncodedString );
290299 }
291300 @ Test
292301 public void testGetRequestsWithEncodedStringStoredRequests () {
293- List <Map <String , Object >> requests = mockRequests (2 , 2 );
302+ List <Map <String , Object >> requests = mockRequests (4 );
294303 String json = Request .jsonEncodeUnsentRequests (requests );
295- String expectedJson = "{\" data\" :[{\" 0\" :\" 0\" },{\" 0\" :\" 1\" },{\" 1\" :\" 0\" },{\" 1\" :\" 1\" }]}" ;
304+
305+ final String expectedJson = "{\" data\" :[{\" 0\" :\" testData\" },{\" 1\" :\" testData\" },{\" 2\" :\" testData\" },{\" 3\" :\" testData\" }]}" ;
296306 assertEquals (json , expectedJson );
297307 }
298308
299- private List <Map <String , Object >> mockRequests (int listSize , int requestSize ) {
309+ private List <Map <String , Object >> mockRequests (int requestSize ) {
300310 List <Map <String , Object >> requests = new ArrayList <>();
301311
302- for (int i =0 ; i < listSize ; i ++) {
303-
304- for (int j =0 ; j < requestSize ; j ++) {
305- Map <String , Object > request = new HashMap <String , Object >();
306- request .put (Integer .toString (i ), Integer .toString (j ));
307- requests .add (request );
308- }
312+ for (int i =0 ; i < requestSize ; i ++) {
313+ Map <String , Object > request = new HashMap <String , Object >();
314+ request .put (Integer .toString (i ), "testData" );
315+ requests .add (request );
309316 }
310317 return requests ;
311318 }
0 commit comments