diff --git a/android/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java b/android/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java index 5c10dd5819d2..92887c36138a 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java @@ -21,19 +21,17 @@ import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.common.annotations.GwtCompatible; -import com.google.common.annotations.GwtIncompatible; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import javax.annotation.CheckForNull; import junit.framework.TestCase; -import org.mockito.Mockito; /** * Test for {@link FutureCallback}. * * @author Anthony Zana */ -@GwtCompatible(emulated = true) +@GwtCompatible public class FutureCallbackTest extends TestCase { public void testSameThreadSuccess() { SettableFuture f = SettableFuture.create(); @@ -96,31 +94,53 @@ public void testRuntimeExceptionFromGet() { addCallback(f, callback, directExecutor()); } - @GwtIncompatible // Mockito public void testOnSuccessThrowsRuntimeException() throws Exception { RuntimeException exception = new RuntimeException(); String result = "result"; SettableFuture future = SettableFuture.create(); - @SuppressWarnings("unchecked") // Safe for a mock - FutureCallback callback = Mockito.mock(FutureCallback.class); + int[] successCalls = new int[1]; + int[] failureCalls = new int[1]; + FutureCallback callback = + new FutureCallback() { + @Override + public void onSuccess(String result) { + successCalls[0]++; + throw exception; + } + + @Override + public void onFailure(Throwable t) { + failureCalls[0]++; + } + }; addCallback(future, callback, directExecutor()); - Mockito.doThrow(exception).when(callback).onSuccess(result); future.set(result); assertEquals(result, future.get()); - Mockito.verify(callback).onSuccess(result); - Mockito.verifyNoMoreInteractions(callback); + assertThat(successCalls[0]).isEqualTo(1); + assertThat(failureCalls[0]).isEqualTo(0); } - @GwtIncompatible // Mockito public void testOnSuccessThrowsError() throws Exception { class TestError extends Error {} TestError error = new TestError(); String result = "result"; SettableFuture future = SettableFuture.create(); - @SuppressWarnings("unchecked") // Safe for a mock - FutureCallback callback = Mockito.mock(FutureCallback.class); + int[] successCalls = new int[1]; + int[] failureCalls = new int[1]; + FutureCallback callback = + new FutureCallback() { + @Override + public void onSuccess(String result) { + successCalls[0]++; + throw error; + } + + @Override + public void onFailure(Throwable t) { + failureCalls[0]++; + } + }; addCallback(future, callback, directExecutor()); - Mockito.doThrow(error).when(callback).onSuccess(result); try { future.set(result); fail("Should have thrown"); @@ -128,8 +148,8 @@ class TestError extends Error {} assertSame(error, e); } assertEquals(result, future.get()); - Mockito.verify(callback).onSuccess(result); - Mockito.verifyNoMoreInteractions(callback); + assertThat(successCalls[0]).isEqualTo(1); + assertThat(failureCalls[0]).isEqualTo(0); } public void testWildcardFuture() { diff --git a/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java b/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java index 1cc88a31f59e..2efdebec57b8 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java @@ -21,19 +21,17 @@ import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.common.annotations.GwtCompatible; -import com.google.common.annotations.GwtIncompatible; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import junit.framework.TestCase; import org.checkerframework.checker.nullness.qual.Nullable; -import org.mockito.Mockito; /** * Test for {@link FutureCallback}. * * @author Anthony Zana */ -@GwtCompatible(emulated = true) +@GwtCompatible public class FutureCallbackTest extends TestCase { public void testSameThreadSuccess() { SettableFuture f = SettableFuture.create(); @@ -96,31 +94,53 @@ public void testRuntimeExceptionFromGet() { addCallback(f, callback, directExecutor()); } - @GwtIncompatible // Mockito public void testOnSuccessThrowsRuntimeException() throws Exception { RuntimeException exception = new RuntimeException(); String result = "result"; SettableFuture future = SettableFuture.create(); - @SuppressWarnings("unchecked") // Safe for a mock - FutureCallback callback = Mockito.mock(FutureCallback.class); + int[] successCalls = new int[1]; + int[] failureCalls = new int[1]; + FutureCallback callback = + new FutureCallback() { + @Override + public void onSuccess(String result) { + successCalls[0]++; + throw exception; + } + + @Override + public void onFailure(Throwable t) { + failureCalls[0]++; + } + }; addCallback(future, callback, directExecutor()); - Mockito.doThrow(exception).when(callback).onSuccess(result); future.set(result); assertEquals(result, future.get()); - Mockito.verify(callback).onSuccess(result); - Mockito.verifyNoMoreInteractions(callback); + assertThat(successCalls[0]).isEqualTo(1); + assertThat(failureCalls[0]).isEqualTo(0); } - @GwtIncompatible // Mockito public void testOnSuccessThrowsError() throws Exception { class TestError extends Error {} TestError error = new TestError(); String result = "result"; SettableFuture future = SettableFuture.create(); - @SuppressWarnings("unchecked") // Safe for a mock - FutureCallback callback = Mockito.mock(FutureCallback.class); + int[] successCalls = new int[1]; + int[] failureCalls = new int[1]; + FutureCallback callback = + new FutureCallback() { + @Override + public void onSuccess(String result) { + successCalls[0]++; + throw error; + } + + @Override + public void onFailure(Throwable t) { + failureCalls[0]++; + } + }; addCallback(future, callback, directExecutor()); - Mockito.doThrow(error).when(callback).onSuccess(result); try { future.set(result); fail("Should have thrown"); @@ -128,8 +148,8 @@ class TestError extends Error {} assertSame(error, e); } assertEquals(result, future.get()); - Mockito.verify(callback).onSuccess(result); - Mockito.verifyNoMoreInteractions(callback); + assertThat(successCalls[0]).isEqualTo(1); + assertThat(failureCalls[0]).isEqualTo(0); } public void testWildcardFuture() {