Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

Expand Down Expand Up @@ -220,7 +221,7 @@ public void getBlocking_hasCachedValue_returnsCache() throws Exception {

@Test
public void getBlocking_hasNoCachedValueAndFileReadTimesOut_returnsNull() throws Exception {
when(mockStorageClient.read()).thenReturn(configContainer);
when(mockStorageClient.read()).thenAnswer(BLOCK_INDEFINITELY);

ConfigContainer container = cacheClient.getBlocking(/* diskReadTimeoutInSeconds= */ 0L);

Expand Down Expand Up @@ -329,4 +330,18 @@ public void cleanUp() {
cacheThreadPool.shutdownNow();
testingThreadPool.shutdownNow();
}

/**
* A Mockito "answer" that blocks indefinitely. The only way that {@link Answer#answer} will
* return is if its thread is interrupted. This may be useful to cause a method to never return,
* which should result in a timeout waiting for the operation to complete.
* <p>
* Example:
* {@code when(foo.get()).thenAnswer(BLOCK_INDEFINITELY); }
*/
private static final Answer<ConfigContainer> BLOCK_INDEFINITELY =
invocation -> {
Thread.sleep(Long.MAX_VALUE);
throw new RuntimeException("BLOCK_INDEFINITELY.answer() should never get here");
};
}
Loading