mirror of https://github.com/grpc/grpc-java.git
interopt-testing: move mockito from compile to testCompile (#5541)
Resolves #5540
This commit is contained in:
parent
63d512ecb4
commit
40526086eb
|
|
@ -76,8 +76,6 @@ dependencies {
|
||||||
implementation 'io.grpc:grpc-protobuf-lite:1.21.0-SNAPSHOT' // CURRENT_GRPC_VERSION
|
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-stub:1.21.0-SNAPSHOT' // CURRENT_GRPC_VERSION
|
||||||
implementation 'io.grpc:grpc-testing: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
|
// workaround for https://github.com/google/protobuf/issues/1889
|
||||||
protobuf 'com.google.protobuf:protobuf-java:3.0.2'
|
protobuf 'com.google.protobuf:protobuf-java:3.0.2'
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ dependencies {
|
||||||
project(':grpc-testing'),
|
project(':grpc-testing'),
|
||||||
libraries.google_auth_oauth2_http,
|
libraries.google_auth_oauth2_http,
|
||||||
libraries.junit,
|
libraries.junit,
|
||||||
libraries.mockito,
|
|
||||||
libraries.truth
|
libraries.truth
|
||||||
compileOnly libraries.javax_annotation
|
compileOnly libraries.javax_annotation
|
||||||
runtime libraries.opencensus_impl,
|
runtime libraries.opencensus_impl,
|
||||||
libraries.netty_tcnative
|
libraries.netty_tcnative
|
||||||
testCompile project(':grpc-context').sourceSets.test.output
|
testCompile project(':grpc-context').sourceSets.test.output,
|
||||||
|
libraries.mockito
|
||||||
}
|
}
|
||||||
|
|
||||||
configureProtoCompilation()
|
configureProtoCompilation()
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,6 @@ import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
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.AccessToken;
|
||||||
import com.google.auth.oauth2.ComputeEngineCredentials;
|
import com.google.auth.oauth2.ComputeEngineCredentials;
|
||||||
|
|
@ -131,9 +129,6 @@ import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.Timeout;
|
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.
|
* Abstract base class for all GRPC transport tests.
|
||||||
|
|
@ -1491,19 +1486,18 @@ public abstract class AbstractInteropTest {
|
||||||
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
|
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
|
||||||
|
|
||||||
// Test FullDuplexCall
|
// Test FullDuplexCall
|
||||||
@SuppressWarnings("unchecked")
|
StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
|
||||||
StreamObserver<StreamingOutputCallResponse> responseObserver =
|
|
||||||
mock(StreamObserver.class);
|
|
||||||
StreamObserver<StreamingOutputCallRequest> requestObserver
|
StreamObserver<StreamingOutputCallRequest> requestObserver
|
||||||
= asyncStub.fullDuplexCall(responseObserver);
|
= asyncStub.fullDuplexCall(responseObserver);
|
||||||
requestObserver.onNext(streamingRequest);
|
requestObserver.onNext(streamingRequest);
|
||||||
requestObserver.onCompleted();
|
requestObserver.onCompleted();
|
||||||
|
|
||||||
ArgumentCaptor<Throwable> captor = ArgumentCaptor.forClass(Throwable.class);
|
assertThat(responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS))
|
||||||
verify(responseObserver, timeout(operationTimeoutMillis())).onError(captor.capture());
|
.isTrue();
|
||||||
assertEquals(Status.UNKNOWN.getCode(), Status.fromThrowable(captor.getValue()).getCode());
|
assertThat(responseObserver.getError()).isNotNull();
|
||||||
assertEquals(errorMessage, Status.fromThrowable(captor.getValue()).getDescription());
|
Status status = Status.fromThrowable(responseObserver.getError());
|
||||||
verifyNoMoreInteractions(responseObserver);
|
assertEquals(Status.UNKNOWN.getCode(), status.getCode());
|
||||||
|
assertEquals(errorMessage, status.getDescription());
|
||||||
assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN);
|
assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1820,48 +1814,6 @@ public abstract class AbstractInteropTest {
|
||||||
actuallyFreeMemory >= 64 * 1024 * 1024);
|
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
|
* Poll the next metrics record and check it against the provided information, including the
|
||||||
* message sizes.
|
* message sizes.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue