Add test coverage for isInitialized in MemoizingInterruptibleSupplier.
RELNOTES: None.
@@ -37,7 +37,7 @@ public final class MemoizingInterruptibleSupplierTest {
}
@Test
- public void returnsCorrectResult() throws Exception {
+ public void getReturnsCorrectResult() throws Exception {
MemoizingInterruptibleSupplier<String> supplier =
MemoizingInterruptibleSupplier.of(callCounter::call);
returnVal = "abc";
@@ -47,6 +47,18 @@ public final class MemoizingInterruptibleSupplierTest {
assertThat(result).isEqualTo("abc");
}
+ @Test
+ public void subsequentCallToGetReturnsCorrectResult() throws Exception {
+ MemoizingInterruptibleSupplier<String> supplier =
+ MemoizingInterruptibleSupplier.of(callCounter::call);
+ returnVal = "abc";
+
+ supplier.get();
+ String result = supplier.get();
+
+ assertThat(result).isEqualTo("abc");
+ }
+
@Test
public void onlyCallsDelegateOnce() throws Exception {
MemoizingInterruptibleSupplier<String> supplier =
@@ -70,6 +82,39 @@ public final class MemoizingInterruptibleSupplierTest {
GcFinalization.awaitClear(ref);
}
+ @Test
+ public void notInitializedBeforeCallingGet() {
+ MemoizingInterruptibleSupplier<String> supplier =
+ MemoizingInterruptibleSupplier.of(callCounter::call);
+
+ boolean initialized = supplier.isInitialized();
+
+ assertThat(initialized).isFalse();
+ }
+
+ @Test
+ public void isInitializedAfterCallingGet() throws Exception {
+ MemoizingInterruptibleSupplier<String> supplier =
+ MemoizingInterruptibleSupplier.of(callCounter::call);
+
+ supplier.get();
+ boolean initialized = supplier.isInitialized();
+
+ assertThat(initialized).isTrue();
+ }
+
+ @Test
+ public void isStillInitializedAfterSubsequentCallToGet() throws Exception {
+ MemoizingInterruptibleSupplier<String> supplier =
+ MemoizingInterruptibleSupplier.of(callCounter::call);
+
+ supplier.get();
+ supplier.get();
+ boolean initialized = supplier.isInitialized();
+
+ assertThat(initialized).isTrue();
+ }
+
@Test
public void of_returnsSameInstanceIfAlreadyMemoizing() {
InterruptibleSupplier<String> supplier = MemoizingInterruptibleSupplier.of(callCounter::call);
