File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
firebase-config/src/test/java/com/google/firebase/remoteconfig/internal Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 42
42
import org .mockito .ArgumentCaptor ;
43
43
import org .mockito .Mock ;
44
44
import org .mockito .MockitoAnnotations ;
45
+ import org .mockito .stubbing .Answer ;
45
46
import org .robolectric .RobolectricTestRunner ;
46
47
import org .robolectric .annotation .Config ;
47
48
@@ -220,7 +221,7 @@ public void getBlocking_hasCachedValue_returnsCache() throws Exception {
220
221
221
222
@ Test
222
223
public void getBlocking_hasNoCachedValueAndFileReadTimesOut_returnsNull () throws Exception {
223
- when (mockStorageClient .read ()).thenReturn ( configContainer );
224
+ when (mockStorageClient .read ()).thenAnswer ( BLOCK_INDEFINITELY );
224
225
225
226
ConfigContainer container = cacheClient .getBlocking (/* diskReadTimeoutInSeconds= */ 0L );
226
227
@@ -329,4 +330,18 @@ public void cleanUp() {
329
330
cacheThreadPool .shutdownNow ();
330
331
testingThreadPool .shutdownNow ();
331
332
}
333
+
334
+ /**
335
+ * A Mockito "answer" that blocks indefinitely. The only way that {@link Answer#answer} will
336
+ * return is if its thread is interrupted. This may be useful to cause a method to never return,
337
+ * which should result in a timeout waiting for the operation to complete.
338
+ * <p>
339
+ * Example:
340
+ * {@code when(foo.get()).thenAnswer(BLOCK_INDEFINITELY); }
341
+ */
342
+ private static final Answer <ConfigContainer > BLOCK_INDEFINITELY =
343
+ invocation -> {
344
+ Thread .sleep (Long .MAX_VALUE );
345
+ throw new RuntimeException ("BLOCK_INDEFINITELY.answer() should never get here" );
346
+ };
332
347
}
You can’t perform that action at this time.
0 commit comments