mirror of https://github.com/grpc/grpc-java.git
all: fix usages of any(<Primitive>.class) matchers
In Mockito 2, if a method expects a primitive type, but an any(<Primitive>.class) matcher is used in its place, it will throw an error. To prepare for this upcoming breakage, change all existing any(<Primitive>.class) matchers to use the correct any<Primitive>() matcher.
This commit is contained in:
parent
0dbab26bb4
commit
a31473ef20
|
|
@ -26,6 +26,8 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.AdditionalAnswers.delegatesTo;
|
import static org.mockito.AdditionalAnswers.delegatesTo;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.same;
|
import static org.mockito.Matchers.same;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
@ -414,8 +416,7 @@ public class AbstractClientStreamTest {
|
||||||
assertTrue(payloadCaptor.getValue() != null);
|
assertTrue(payloadCaptor.getValue() != null);
|
||||||
// GET requests don't have BODY.
|
// GET requests don't have BODY.
|
||||||
verify(sink, never())
|
verify(sink, never())
|
||||||
.writeFrame(
|
.writeFrame(any(WritableBuffer.class), anyBoolean(), anyBoolean(), anyInt());
|
||||||
any(WritableBuffer.class), any(Boolean.class), any(Boolean.class), any(Integer.class));
|
|
||||||
assertThat(tracer.nextOutboundEvent()).isEqualTo("outboundMessage(0)");
|
assertThat(tracer.nextOutboundEvent()).isEqualTo("outboundMessage(0)");
|
||||||
assertThat(tracer.nextOutboundEvent()).matches("outboundMessageSent\\(0, [0-9]+, [0-9]+\\)");
|
assertThat(tracer.nextOutboundEvent()).matches("outboundMessageSent\\(0, [0-9]+, [0-9]+\\)");
|
||||||
assertNull(tracer.nextOutboundEvent());
|
assertNull(tracer.nextOutboundEvent());
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.mockito.AdditionalAnswers.delegatesTo;
|
import static org.mockito.AdditionalAnswers.delegatesTo;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.same;
|
import static org.mockito.Matchers.same;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
@ -270,8 +272,7 @@ public class AbstractServerStreamTest {
|
||||||
|
|
||||||
stream.writeMessage(new ByteArrayInputStream(new byte[]{}));
|
stream.writeMessage(new ByteArrayInputStream(new byte[]{}));
|
||||||
|
|
||||||
verify(sink, never())
|
verify(sink, never()).writeFrame(any(WritableBuffer.class), anyBoolean(), anyInt());
|
||||||
.writeFrame(any(WritableBuffer.class), any(Boolean.class), any(Integer.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
@ -180,10 +181,11 @@ public class ProxyDetectorImplTest {
|
||||||
when(authenticator.requestPasswordAuthentication(
|
when(authenticator.requestPasswordAuthentication(
|
||||||
any(String.class),
|
any(String.class),
|
||||||
any(InetAddress.class),
|
any(InetAddress.class),
|
||||||
any(Integer.class),
|
anyInt(),
|
||||||
any(String.class),
|
any(String.class),
|
||||||
any(String.class),
|
any(String.class),
|
||||||
any(String.class))).thenReturn(auth);
|
any(String.class)))
|
||||||
|
.thenReturn(auth);
|
||||||
when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
|
when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
|
||||||
|
|
||||||
ProxyParameters detected = proxyDetector.proxyFor(destination);
|
ProxyParameters detected = proxyDetector.proxyFor(destination);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.isA;
|
import static org.mockito.Matchers.isA;
|
||||||
import static org.mockito.Matchers.same;
|
import static org.mockito.Matchers.same;
|
||||||
|
|
@ -437,8 +438,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase<NettyClientStream
|
||||||
Mockito.reset(writeQueue);
|
Mockito.reset(writeQueue);
|
||||||
ChannelPromise completedPromise = new DefaultChannelPromise(channel)
|
ChannelPromise completedPromise = new DefaultChannelPromise(channel)
|
||||||
.setSuccess();
|
.setSuccess();
|
||||||
when(writeQueue.enqueue(any(QueuedCommand.class), any(boolean.class)))
|
when(writeQueue.enqueue(any(QueuedCommand.class), anyBoolean())).thenReturn(completedPromise);
|
||||||
.thenReturn(completedPromise);
|
|
||||||
|
|
||||||
stream = new NettyClientStream(
|
stream = new NettyClientStream(
|
||||||
new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE),
|
new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE),
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.AdditionalAnswers.delegatesTo;
|
import static org.mockito.AdditionalAnswers.delegatesTo;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Matchers.anyLong;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
|
|
@ -690,8 +692,12 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase<NettyServerHand
|
||||||
fakeClock().forwardTime(20, TimeUnit.MINUTES);
|
fakeClock().forwardTime(20, TimeUnit.MINUTES);
|
||||||
|
|
||||||
// GO_AWAY not sent yet
|
// GO_AWAY not sent yet
|
||||||
verifyWrite(never()).writeGoAway(
|
verifyWrite(never())
|
||||||
any(ChannelHandlerContext.class), any(Integer.class), any(Long.class), any(ByteBuf.class),
|
.writeGoAway(
|
||||||
|
any(ChannelHandlerContext.class),
|
||||||
|
anyInt(),
|
||||||
|
anyLong(),
|
||||||
|
any(ByteBuf.class),
|
||||||
any(ChannelPromise.class));
|
any(ChannelPromise.class));
|
||||||
assertTrue(channel().isOpen());
|
assertTrue(channel().isOpen());
|
||||||
}
|
}
|
||||||
|
|
@ -770,8 +776,12 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase<NettyServerHand
|
||||||
fakeClock().forwardNanos(maxConnectionIdleInNanos);
|
fakeClock().forwardNanos(maxConnectionIdleInNanos);
|
||||||
|
|
||||||
// GO_AWAY not sent when active
|
// GO_AWAY not sent when active
|
||||||
verifyWrite(never()).writeGoAway(
|
verifyWrite(never())
|
||||||
any(ChannelHandlerContext.class), any(Integer.class), any(Long.class), any(ByteBuf.class),
|
.writeGoAway(
|
||||||
|
any(ChannelHandlerContext.class),
|
||||||
|
anyInt(),
|
||||||
|
anyLong(),
|
||||||
|
any(ByteBuf.class),
|
||||||
any(ChannelPromise.class));
|
any(ChannelPromise.class));
|
||||||
assertTrue(channel().isOpen());
|
assertTrue(channel().isOpen());
|
||||||
|
|
||||||
|
|
@ -810,8 +820,12 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase<NettyServerHand
|
||||||
fakeClock().forwardNanos(maxConnectionIdleInNanos);
|
fakeClock().forwardNanos(maxConnectionIdleInNanos);
|
||||||
|
|
||||||
// GO_AWAY not sent when active
|
// GO_AWAY not sent when active
|
||||||
verifyWrite(never()).writeGoAway(
|
verifyWrite(never())
|
||||||
any(ChannelHandlerContext.class), any(Integer.class), any(Long.class), any(ByteBuf.class),
|
.writeGoAway(
|
||||||
|
any(ChannelHandlerContext.class),
|
||||||
|
anyInt(),
|
||||||
|
anyLong(),
|
||||||
|
any(ByteBuf.class),
|
||||||
any(ChannelPromise.class));
|
any(ChannelPromise.class));
|
||||||
assertTrue(channel().isOpen());
|
assertTrue(channel().isOpen());
|
||||||
|
|
||||||
|
|
@ -849,8 +863,12 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase<NettyServerHand
|
||||||
fakeClock().forwardTime(20, TimeUnit.MINUTES);
|
fakeClock().forwardTime(20, TimeUnit.MINUTES);
|
||||||
|
|
||||||
// GO_AWAY not sent yet
|
// GO_AWAY not sent yet
|
||||||
verifyWrite(never()).writeGoAway(
|
verifyWrite(never())
|
||||||
any(ChannelHandlerContext.class), any(Integer.class), any(Long.class), any(ByteBuf.class),
|
.writeGoAway(
|
||||||
|
any(ChannelHandlerContext.class),
|
||||||
|
anyInt(),
|
||||||
|
anyLong(),
|
||||||
|
any(ByteBuf.class),
|
||||||
any(ChannelPromise.class));
|
any(ChannelPromise.class));
|
||||||
assertTrue(channel().isOpen());
|
assertTrue(channel().isOpen());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ 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.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyLong;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.isNull;
|
import static org.mockito.Matchers.isNull;
|
||||||
import static org.mockito.Matchers.same;
|
import static org.mockito.Matchers.same;
|
||||||
|
|
@ -1004,14 +1005,15 @@ public final class BinlogHelperTest {
|
||||||
});
|
});
|
||||||
call.start(mockListener, new Metadata());
|
call.start(mockListener, new Metadata());
|
||||||
ArgumentCaptor<Duration> callOptTimeoutCaptor = ArgumentCaptor.forClass(Duration.class);
|
ArgumentCaptor<Duration> callOptTimeoutCaptor = ArgumentCaptor.forClass(Duration.class);
|
||||||
verify(mockSinkWriter).logClientHeader(
|
verify(mockSinkWriter)
|
||||||
any(Integer.class),
|
.logClientHeader(
|
||||||
|
anyLong(),
|
||||||
any(String.class),
|
any(String.class),
|
||||||
any(String.class),
|
any(String.class),
|
||||||
callOptTimeoutCaptor.capture(),
|
callOptTimeoutCaptor.capture(),
|
||||||
any(Metadata.class),
|
any(Metadata.class),
|
||||||
any(GrpcLogEntry.Logger.class),
|
any(GrpcLogEntry.Logger.class),
|
||||||
any(Long.class),
|
anyLong(),
|
||||||
any(SocketAddress.class));
|
any(SocketAddress.class));
|
||||||
Duration timeout = callOptTimeoutCaptor.getValue();
|
Duration timeout = callOptTimeoutCaptor.getValue();
|
||||||
assertThat(TimeUnit.SECONDS.toNanos(1) - Durations.toNanos(timeout))
|
assertThat(TimeUnit.SECONDS.toNanos(1) - Durations.toNanos(timeout))
|
||||||
|
|
@ -1060,14 +1062,15 @@ public final class BinlogHelperTest {
|
||||||
ClientCall.Listener<byte[]> mockListener = mock(ClientCall.Listener.class);
|
ClientCall.Listener<byte[]> mockListener = mock(ClientCall.Listener.class);
|
||||||
callFuture.get().start(mockListener, new Metadata());
|
callFuture.get().start(mockListener, new Metadata());
|
||||||
ArgumentCaptor<Duration> callOptTimeoutCaptor = ArgumentCaptor.forClass(Duration.class);
|
ArgumentCaptor<Duration> callOptTimeoutCaptor = ArgumentCaptor.forClass(Duration.class);
|
||||||
verify(mockSinkWriter).logClientHeader(
|
verify(mockSinkWriter)
|
||||||
any(Integer.class),
|
.logClientHeader(
|
||||||
|
anyLong(),
|
||||||
any(String.class),
|
any(String.class),
|
||||||
any(String.class),
|
any(String.class),
|
||||||
callOptTimeoutCaptor.capture(),
|
callOptTimeoutCaptor.capture(),
|
||||||
any(Metadata.class),
|
any(Metadata.class),
|
||||||
any(GrpcLogEntry.Logger.class),
|
any(GrpcLogEntry.Logger.class),
|
||||||
any(Long.class),
|
anyLong(),
|
||||||
any(SocketAddress.class));
|
any(SocketAddress.class));
|
||||||
Duration timeout = callOptTimeoutCaptor.getValue();
|
Duration timeout = callOptTimeoutCaptor.getValue();
|
||||||
assertThat(TimeUnit.SECONDS.toNanos(1) - Durations.toNanos(timeout))
|
assertThat(TimeUnit.SECONDS.toNanos(1) - Durations.toNanos(timeout))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue