Skip to content

Commit

Permalink
interopt-testing: move mockito from compile to testCompile (grpc#5541)
Browse files Browse the repository at this point in the history
Resolves grpc#5540
  • Loading branch information
dapengzhang0 committed Apr 3, 2019
1 parent 10d920a commit 2cace60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 57 deletions.
4 changes: 2 additions & 2 deletions interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
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;
Expand Down Expand Up @@ -131,9 +129,6 @@
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.
Expand Down Expand Up @@ -1491,19 +1486,18 @@ public void statusCodeAndMessage() throws Exception {
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);

// Test FullDuplexCall
@SuppressWarnings("unchecked")
StreamObserver<StreamingOutputCallResponse> responseObserver =
mock(StreamObserver.class);
StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestObserver
= asyncStub.fullDuplexCall(responseObserver);
requestObserver.onNext(streamingRequest);
requestObserver.onCompleted();

ArgumentCaptor<Throwable> 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);
}

Expand Down Expand Up @@ -1820,48 +1814,6 @@ private static void assumeEnoughMemory() {
actuallyFreeMemory >= 64 * 1024 * 1024);
}

/**
* Wrapper around {@link Mockito#verify}, to keep log spam down on failure.
*/
private static <T> 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.
Expand Down

0 comments on commit 2cace60

Please sign in to comment.