From 40526086eb612f07715b45b2181a7448d12a481f Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Wed, 3 Apr 2019 14:09:03 -0700 Subject: [PATCH] interopt-testing: move mockito from compile to testCompile (#5541) Resolves #5540 --- android-interop-testing/app/build.gradle | 2 - interop-testing/build.gradle | 4 +- .../integration/AbstractInteropTest.java | 62 +++---------------- 3 files changed, 9 insertions(+), 59 deletions(-) diff --git a/android-interop-testing/app/build.gradle b/android-interop-testing/app/build.gradle index 26b2bf3d5b..03d76c4ba1 100644 --- a/android-interop-testing/app/build.gradle +++ b/android-interop-testing/app/build.gradle @@ -76,8 +76,6 @@ dependencies { implementation 'io.grpc:grpc-protobuf-lite:1.21.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-stub:1.21.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-testing:1.21.0-SNAPSHOT' // CURRENT_GRPC_VERSION - - implementation 'org.mockito:mockito-core:2.25.1' // workaround for https://github.com/google/protobuf/issues/1889 protobuf 'com.google.protobuf:protobuf-java:3.0.2' diff --git a/interop-testing/build.gradle b/interop-testing/build.gradle index 44503aee89..6de61d3aec 100644 --- a/interop-testing/build.gradle +++ b/interop-testing/build.gradle @@ -23,12 +23,12 @@ dependencies { project(':grpc-testing'), libraries.google_auth_oauth2_http, libraries.junit, - libraries.mockito, libraries.truth compileOnly libraries.javax_annotation runtime libraries.opencensus_impl, libraries.netty_tcnative - testCompile project(':grpc-context').sourceSets.test.output + testCompile project(':grpc-context').sourceSets.test.output, + libraries.mockito } configureProtoCompilation() diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index d600eadf56..daf87b3c2e 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -28,8 +28,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.timeout; import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.ComputeEngineCredentials; @@ -131,9 +129,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.mockito.verification.VerificationMode; /** * Abstract base class for all GRPC transport tests. @@ -1491,19 +1486,18 @@ public abstract class AbstractInteropTest { assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN); // Test FullDuplexCall - @SuppressWarnings("unchecked") - StreamObserver responseObserver = - mock(StreamObserver.class); + StreamRecorder responseObserver = StreamRecorder.create(); StreamObserver requestObserver = asyncStub.fullDuplexCall(responseObserver); requestObserver.onNext(streamingRequest); requestObserver.onCompleted(); - ArgumentCaptor captor = ArgumentCaptor.forClass(Throwable.class); - verify(responseObserver, timeout(operationTimeoutMillis())).onError(captor.capture()); - assertEquals(Status.UNKNOWN.getCode(), Status.fromThrowable(captor.getValue()).getCode()); - assertEquals(errorMessage, Status.fromThrowable(captor.getValue()).getDescription()); - verifyNoMoreInteractions(responseObserver); + assertThat(responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS)) + .isTrue(); + assertThat(responseObserver.getError()).isNotNull(); + Status status = Status.fromThrowable(responseObserver.getError()); + assertEquals(Status.UNKNOWN.getCode(), status.getCode()); + assertEquals(errorMessage, status.getDescription()); assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN); } @@ -1820,48 +1814,6 @@ public abstract class AbstractInteropTest { actuallyFreeMemory >= 64 * 1024 * 1024); } - /** - * Wrapper around {@link Mockito#verify}, to keep log spam down on failure. - */ - private static T verify(T mock, VerificationMode mode) { - try { - return Mockito.verify(mock, mode); - } catch (final AssertionError e) { - String msg = e.getMessage(); - if (msg.length() >= 256) { - // AssertionError(String, Throwable) only present in Android API 19+ - throw new AssertionError(msg.substring(0, 256)) { - @Override - public synchronized Throwable getCause() { - return e; - } - }; - } - throw e; - } - } - - /** - * Wrapper around {@link Mockito#verify}, to keep log spam down on failure. - */ - private static void verifyNoMoreInteractions(Object... mocks) { - try { - Mockito.verifyNoMoreInteractions(mocks); - } catch (final AssertionError e) { - String msg = e.getMessage(); - if (msg.length() >= 256) { - // AssertionError(String, Throwable) only present in Android API 19+ - throw new AssertionError(msg.substring(0, 256)) { - @Override - public synchronized Throwable getCause() { - return e; - } - }; - } - throw e; - } - } - /** * Poll the next metrics record and check it against the provided information, including the * message sizes.