4444import java .util .List ;
4545import java .util .Map ;
4646
47+ import static org .mockito .AdditionalMatchers .not ;
48+ import static org .mockito .Matchers .eq ;
4749import static org .mockito .Mockito .spy ;
4850import static org .mockito .Mockito .when ;
4951
@@ -208,7 +210,7 @@ public void testRemoveIrrelevantBackgroundStartRequests() throws NoSuchMethodExc
208210 Request .deleteSentRequests (unsentRequests .size ());
209211 LeanplumEventDataManagerTest .setDatabaseToNull ();
210212 }
211-
213+
212214 @ Test
213215 public void testJsonEncodeUnsentRequestsWithExceptionLargeNumbers () throws NoSuchMethodException ,
214216 InvocationTargetException , IllegalAccessException {
@@ -224,6 +226,8 @@ public void testJsonEncodeUnsentRequestsWithExceptionLargeNumbers() throws NoSuc
224226 requestsWithEncoding = request .getRequestsWithEncodedStringStoredRequests (1.0 );
225227
226228 assertNotNull (requestsWithEncoding .unsentRequests );
229+ assertNotNull (requestsWithEncoding .requestsToSend );
230+ assertNotNull (requestsWithEncoding .jsonEncodedString );
227231 assertEquals (5000 , requestsWithEncoding .unsentRequests .size ());
228232
229233 // Throw OOM on 5000 requests
@@ -232,15 +236,27 @@ public void testJsonEncodeUnsentRequestsWithExceptionLargeNumbers() throws NoSuc
232236 requestsWithEncoding = request .getRequestsWithEncodedStringStoredRequests (1.0 );
233237
234238 assertNotNull (requestsWithEncoding .unsentRequests );
239+ assertNotNull (requestsWithEncoding .requestsToSend );
240+ assertNotNull (requestsWithEncoding .jsonEncodedString );
235241 assertEquals (2500 , requestsWithEncoding .unsentRequests .size ());
236242
237243 // Throw OOM on 2500, 5000 requests
238244 // Expectation: 1250 requests returned.
239245 when (request .getUnsentRequests (0.5 )).thenThrow (OutOfMemoryError .class );
240246 requestsWithEncoding = request .getRequestsWithEncodedStringStoredRequests (1.0 );
241247
248+ // Throw OOM on >0 requests
249+ // Expectation: 0 requests returned but no crash
250+
251+ when (request .getUnsentRequests (not (eq (0 )))).thenThrow (OutOfMemoryError .class );
252+ requestsWithEncoding = request .getRequestsWithEncodedStringStoredRequests (1.0 );
253+
242254 assertNotNull (requestsWithEncoding .unsentRequests );
243- assertEquals (1250 , requestsWithEncoding .unsentRequests .size ());
255+ assertNotNull (requestsWithEncoding .requestsToSend );
256+ assertNotNull (requestsWithEncoding .jsonEncodedString );
257+ assertEquals (0 , requestsWithEncoding .unsentRequests .size ());
258+ assertEquals (0 , requestsWithEncoding .requestsToSend .size ());
259+ assertEquals ("{\" data\" :[]}" , requestsWithEncoding .jsonEncodedString );
244260
245261 }
246262
0 commit comments