Remove deprecated usage of Mockito methods

Motivation:

We used some deprecated Mockito methods.

Modifications:

- Replace deprecated method usage
- Some cleanup

Result:

No more usage of deprecated Mockito methods. Fixes [#6482].
This commit is contained in:
Norman Maurer 2017-03-09 17:10:38 +01:00
parent 01012fc5b7
commit e12f504ac1
18 changed files with 117 additions and 122 deletions

View File

@ -28,7 +28,7 @@ import org.junit.Test;
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View File

@ -31,7 +31,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.HttpVersion;
import org.mockito.ArgumentMatcher; import org.mockito.ArgumentMatcher;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.argThat;
public final class WebSocketExtensionTestUtil { public final class WebSocketExtensionTestUtil {

View File

@ -27,9 +27,7 @@ import java.util.Random;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.SPDY_HEADER_SIZE; import static io.netty.handler.codec.spdy.SpdyCodecUtil.SPDY_HEADER_SIZE;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
public class SpdyFrameDecoderTest { public class SpdyFrameDecoderTest {

View File

@ -55,11 +55,11 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View File

@ -45,13 +45,13 @@ import static io.netty.util.CharsetUtil.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
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.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.anyLong;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;

View File

@ -54,12 +54,12 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
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.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.anyLong;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -29,6 +29,7 @@ import org.junit.BeforeClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
@ -43,11 +44,10 @@ 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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.anyLong;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -167,7 +167,7 @@ public class DefaultHttp2ConnectionTest {
final CountDownLatch latch = new CountDownLatch(client.numActiveStreams()); final CountDownLatch latch = new CountDownLatch(client.numActiveStreams());
client.forEachActiveStream(new Http2StreamVisitor() { client.forEachActiveStream(new Http2StreamVisitor() {
@Override @Override
public boolean visit(Http2Stream stream) throws Http2Exception { public boolean visit(Http2Stream stream) {
client.close(promise).addListener(new FutureListener<Void>() { client.close(promise).addListener(new FutureListener<Void>() {
@Override @Override
public void operationComplete(Future<Void> future) throws Exception { public void operationComplete(Future<Void> future) throws Exception {
@ -578,7 +578,8 @@ public class DefaultHttp2ConnectionTest {
assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(latch.await(5, TimeUnit.SECONDS));
} }
private void incrementAndGetStreamShouldRespectOverflow(Endpoint<?> endpoint, int streamId) throws Http2Exception { private static void incrementAndGetStreamShouldRespectOverflow(Endpoint<?> endpoint, int streamId)
throws Http2Exception {
assertTrue(streamId > 0); assertTrue(streamId > 0);
try { try {
endpoint.createStream(streamId, true); endpoint.createStream(streamId, true);
@ -590,7 +591,7 @@ public class DefaultHttp2ConnectionTest {
endpoint.createStream(streamId, true); endpoint.createStream(streamId, true);
} }
private void incrementAndGetStreamShouldSucceed(Endpoint<?> endpoint) throws Http2Exception { private static void incrementAndGetStreamShouldSucceed(Endpoint<?> endpoint) throws Http2Exception {
Http2Stream streamA = endpoint.createStream(endpoint.incrementAndGetNextStreamId(), true); Http2Stream streamA = endpoint.createStream(endpoint.incrementAndGetNextStreamId(), true);
Http2Stream streamB = endpoint.createStream(streamA.id() + 2, true); Http2Stream streamB = endpoint.createStream(streamA.id() + 2, true);
Http2Stream streamC = endpoint.createStream(endpoint.incrementAndGetNextStreamId(), true); Http2Stream streamC = endpoint.createStream(endpoint.incrementAndGetNextStreamId(), true);
@ -633,6 +634,6 @@ public class DefaultHttp2ConnectionTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T> T streamEq(T stream) { private static <T> T streamEq(T stream) {
return (T) (stream == null ? isNull(Http2Stream.class) : eq(stream)); return (T) (stream == null ? ArgumentMatchers.<Http2Stream>isNull() : eq(stream));
} }
} }

View File

@ -21,9 +21,9 @@ import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_WINDOW_SIZE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -49,9 +49,6 @@ public class DefaultHttp2LocalFlowControllerTest {
private DefaultHttp2LocalFlowController controller; private DefaultHttp2LocalFlowController controller;
@Mock
private ByteBuf buffer;
@Mock @Mock
private Http2FrameWriter frameWriter; private Http2FrameWriter frameWriter;
@ -369,7 +366,7 @@ public class DefaultHttp2LocalFlowControllerTest {
any(ChannelPromise.class)); any(ChannelPromise.class));
} }
private int window(int streamId) throws Http2Exception { private int window(int streamId) {
return controller.windowSize(stream(streamId)); return controller.windowSize(stream(streamId));
} }

View File

@ -39,8 +39,8 @@ import static org.junit.Assert.assertNotNull;
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.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
@ -939,7 +939,7 @@ public abstract class DefaultHttp2RemoteFlowControllerTest {
return flowControlled; return flowControlled;
} }
private void sendData(int streamId, FakeFlowControlled data) throws Http2Exception { private void sendData(int streamId, FakeFlowControlled data) {
Http2Stream stream = stream(streamId); Http2Stream stream = stream(streamId);
controller.addFlowControlled(stream, data); controller.addFlowControlled(stream, data);
} }
@ -948,7 +948,7 @@ public abstract class DefaultHttp2RemoteFlowControllerTest {
incrementWindowSize(streamId, -window(streamId)); incrementWindowSize(streamId, -window(streamId));
} }
private int window(int streamId) throws Http2Exception { private int window(int streamId) {
return controller.windowSize(stream(streamId)); return controller.windowSize(stream(streamId));
} }

View File

@ -36,7 +36,7 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Matchers; import org.mockito.ArgumentMatchers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
@ -56,11 +56,11 @@ import static io.netty.util.CharsetUtil.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.anyLong;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -281,7 +281,7 @@ public class Http2ConnectionHandlerTest {
ByteBuf prefacePlusSome = addSettingsHeader(Unpooled.buffer().writeBytes(connectionPrefaceBuf())); ByteBuf prefacePlusSome = addSettingsHeader(Unpooled.buffer().writeBytes(connectionPrefaceBuf()));
handler.channelRead(ctx, prefacePlusSome); handler.channelRead(ctx, prefacePlusSome);
verify(decoder, atLeastOnce()).decodeFrame(any(ChannelHandlerContext.class), verify(decoder, atLeastOnce()).decodeFrame(any(ChannelHandlerContext.class),
any(ByteBuf.class), Matchers.<List<Object>>any()); any(ByteBuf.class), ArgumentMatchers.<List<Object>>any());
} }
@Test @Test
@ -293,7 +293,7 @@ public class Http2ConnectionHandlerTest {
ByteBuf preface = connectionPrefaceBuf(); ByteBuf preface = connectionPrefaceBuf();
handler.channelRead(ctx, preface); handler.channelRead(ctx, preface);
verify(decoder, never()).decodeFrame(any(ChannelHandlerContext.class), verify(decoder, never()).decodeFrame(any(ChannelHandlerContext.class),
any(ByteBuf.class), Matchers.<List<Object>>any()); any(ByteBuf.class), ArgumentMatchers.<List<Object>>any());
// Now remove and add the handler...this is setting up the test condition. // Now remove and add the handler...this is setting up the test condition.
handler.handlerRemoved(ctx); handler.handlerRemoved(ctx);
@ -302,7 +302,7 @@ public class Http2ConnectionHandlerTest {
// Now verify we can continue as normal, reading connection preface plus more. // Now verify we can continue as normal, reading connection preface plus more.
ByteBuf prefacePlusSome = addSettingsHeader(Unpooled.buffer().writeBytes(connectionPrefaceBuf())); ByteBuf prefacePlusSome = addSettingsHeader(Unpooled.buffer().writeBytes(connectionPrefaceBuf()));
handler.channelRead(ctx, prefacePlusSome); handler.channelRead(ctx, prefacePlusSome);
verify(decoder, atLeastOnce()).decodeFrame(eq(ctx), any(ByteBuf.class), Matchers.<List<Object>>any()); verify(decoder, atLeastOnce()).decodeFrame(eq(ctx), any(ByteBuf.class), ArgumentMatchers.<List<Object>>any());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -329,7 +329,7 @@ public class Http2ConnectionHandlerTest {
public void serverShouldSend431OnHeaderSizeErrorWhenDecodingInitialHeaders() throws Exception { public void serverShouldSend431OnHeaderSizeErrorWhenDecodingInitialHeaders() throws Exception {
int padding = 0; int padding = 0;
handler = newHandler(); handler = newHandler();
Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, Http2Error.PROTOCOL_ERROR, Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, PROTOCOL_ERROR,
"Header size exceeded max allowed size 8196", true); "Header size exceeded max allowed size 8196", true);
when(stream.id()).thenReturn(STREAM_ID); when(stream.id()).thenReturn(STREAM_ID);
@ -337,7 +337,7 @@ public class Http2ConnectionHandlerTest {
when(stream.isHeadersSent()).thenReturn(false); when(stream.isHeadersSent()).thenReturn(false);
when(remote.lastStreamCreated()).thenReturn(STREAM_ID); when(remote.lastStreamCreated()).thenReturn(STREAM_ID);
when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID),
eq(Http2Error.PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future); eq(PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future);
handler.exceptionCaught(ctx, e); handler.exceptionCaught(ctx, e);
@ -346,14 +346,14 @@ public class Http2ConnectionHandlerTest {
captor.capture(), eq(padding), eq(true), eq(promise)); captor.capture(), eq(padding), eq(true), eq(promise));
Http2Headers headers = captor.getValue(); Http2Headers headers = captor.getValue();
assertEquals(HttpResponseStatus.REQUEST_HEADER_FIELDS_TOO_LARGE.codeAsText(), headers.status()); assertEquals(HttpResponseStatus.REQUEST_HEADER_FIELDS_TOO_LARGE.codeAsText(), headers.status());
verify(frameWriter).writeRstStream(ctx, STREAM_ID, Http2Error.PROTOCOL_ERROR.code(), promise); verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
} }
@Test @Test
public void serverShouldNeverSend431HeaderSizeErrorWhenEncoding() throws Exception { public void serverShouldNeverSend431HeaderSizeErrorWhenEncoding() throws Exception {
int padding = 0; int padding = 0;
handler = newHandler(); handler = newHandler();
Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, Http2Error.PROTOCOL_ERROR, Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, PROTOCOL_ERROR,
"Header size exceeded max allowed size 8196", false); "Header size exceeded max allowed size 8196", false);
when(stream.id()).thenReturn(STREAM_ID); when(stream.id()).thenReturn(STREAM_ID);
@ -361,20 +361,20 @@ public class Http2ConnectionHandlerTest {
when(stream.isHeadersSent()).thenReturn(false); when(stream.isHeadersSent()).thenReturn(false);
when(remote.lastStreamCreated()).thenReturn(STREAM_ID); when(remote.lastStreamCreated()).thenReturn(STREAM_ID);
when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID),
eq(Http2Error.PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future); eq(PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future);
handler.exceptionCaught(ctx, e); handler.exceptionCaught(ctx, e);
verify(encoder, never()).writeHeaders(eq(ctx), eq(STREAM_ID), verify(encoder, never()).writeHeaders(eq(ctx), eq(STREAM_ID),
any(Http2Headers.class), eq(padding), eq(true), eq(promise)); any(Http2Headers.class), eq(padding), eq(true), eq(promise));
verify(frameWriter).writeRstStream(ctx, STREAM_ID, Http2Error.PROTOCOL_ERROR.code(), promise); verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
} }
@Test @Test
public void clientShouldNeverSend431WhenHeadersAreTooLarge() throws Exception { public void clientShouldNeverSend431WhenHeadersAreTooLarge() throws Exception {
int padding = 0; int padding = 0;
handler = newHandler(); handler = newHandler();
Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, Http2Error.PROTOCOL_ERROR, Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, PROTOCOL_ERROR,
"Header size exceeded max allowed size 8196", true); "Header size exceeded max allowed size 8196", true);
when(stream.id()).thenReturn(STREAM_ID); when(stream.id()).thenReturn(STREAM_ID);
@ -382,20 +382,20 @@ public class Http2ConnectionHandlerTest {
when(stream.isHeadersSent()).thenReturn(false); when(stream.isHeadersSent()).thenReturn(false);
when(remote.lastStreamCreated()).thenReturn(STREAM_ID); when(remote.lastStreamCreated()).thenReturn(STREAM_ID);
when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID),
eq(Http2Error.PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future); eq(PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future);
handler.exceptionCaught(ctx, e); handler.exceptionCaught(ctx, e);
verify(encoder, never()).writeHeaders(eq(ctx), eq(STREAM_ID), verify(encoder, never()).writeHeaders(eq(ctx), eq(STREAM_ID),
any(Http2Headers.class), eq(padding), eq(true), eq(promise)); any(Http2Headers.class), eq(padding), eq(true), eq(promise));
verify(frameWriter).writeRstStream(ctx, STREAM_ID, Http2Error.PROTOCOL_ERROR.code(), promise); verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
} }
@Test @Test
public void serverShouldNeverSend431IfHeadersAlreadySent() throws Exception { public void serverShouldNeverSend431IfHeadersAlreadySent() throws Exception {
int padding = 0; int padding = 0;
handler = newHandler(); handler = newHandler();
Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, Http2Error.PROTOCOL_ERROR, Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, PROTOCOL_ERROR,
"Header size exceeded max allowed size 8196", true); "Header size exceeded max allowed size 8196", true);
when(stream.id()).thenReturn(STREAM_ID); when(stream.id()).thenReturn(STREAM_ID);
@ -403,20 +403,20 @@ public class Http2ConnectionHandlerTest {
when(stream.isHeadersSent()).thenReturn(true); when(stream.isHeadersSent()).thenReturn(true);
when(remote.lastStreamCreated()).thenReturn(STREAM_ID); when(remote.lastStreamCreated()).thenReturn(STREAM_ID);
when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID),
eq(Http2Error.PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future); eq(PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future);
handler.exceptionCaught(ctx, e); handler.exceptionCaught(ctx, e);
verify(encoder, never()).writeHeaders(eq(ctx), eq(STREAM_ID), verify(encoder, never()).writeHeaders(eq(ctx), eq(STREAM_ID),
any(Http2Headers.class), eq(padding), eq(true), eq(promise)); any(Http2Headers.class), eq(padding), eq(true), eq(promise));
verify(frameWriter).writeRstStream(ctx, STREAM_ID, Http2Error.PROTOCOL_ERROR.code(), promise); verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
} }
@Test @Test
public void serverShouldCreateStreamIfNeededBeforeSending431() throws Exception { public void serverShouldCreateStreamIfNeededBeforeSending431() throws Exception {
int padding = 0; int padding = 0;
handler = newHandler(); handler = newHandler();
Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, Http2Error.PROTOCOL_ERROR, Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, PROTOCOL_ERROR,
"Header size exceeded max allowed size 8196", true); "Header size exceeded max allowed size 8196", true);
when(connection.stream(STREAM_ID)).thenReturn(null); when(connection.stream(STREAM_ID)).thenReturn(null);
@ -434,7 +434,7 @@ public class Http2ConnectionHandlerTest {
verify(encoder).writeHeaders(eq(ctx), eq(STREAM_ID), verify(encoder).writeHeaders(eq(ctx), eq(STREAM_ID),
any(Http2Headers.class), eq(padding), eq(true), eq(promise)); any(Http2Headers.class), eq(padding), eq(true), eq(promise));
verify(frameWriter).writeRstStream(ctx, STREAM_ID, Http2Error.PROTOCOL_ERROR.code(), promise); verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
} }
@Test @Test

View File

@ -62,12 +62,12 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; 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.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.anyLong;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -862,6 +862,7 @@ public class Http2ConnectionRoundtripTest {
.gracefulShutdownTimeoutMillis(0) .gracefulShutdownTimeoutMillis(0)
.build()); .build());
p.addLast(new ChannelInboundHandlerAdapter() { p.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof Http2ConnectionPrefaceWrittenEvent) { if (evt instanceof Http2ConnectionPrefaceWrittenEvent) {
prefaceWrittenLatch.countDown(); prefaceWrittenLatch.countDown();

View File

@ -50,12 +50,12 @@ import static java.lang.Math.min;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Matchers.isA; import static org.mockito.Mockito.isA;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -88,7 +88,7 @@ public class Http2FrameRoundtripTest {
private Http2FrameWriter writer; private Http2FrameWriter writer;
private Http2FrameReader reader; private Http2FrameReader reader;
private List<ByteBuf> needReleasing = new LinkedList<ByteBuf>(); private final List<ByteBuf> needReleasing = new LinkedList<ByteBuf>();
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
@ -428,7 +428,7 @@ public class Http2FrameRoundtripTest {
reader.readFrame(ctx, write, listener); reader.readFrame(ctx, write, listener);
} }
private ByteBuf data(int size) { private static ByteBuf data(int size) {
byte[] data = new byte[size]; byte[] data = new byte[size];
for (int ix = 0; ix < data.length;) { for (int ix = 0; ix < data.length;) {
int length = min(MESSAGE.length, data.length - ix); int length = min(MESSAGE.length, data.length - ix);
@ -438,7 +438,7 @@ public class Http2FrameRoundtripTest {
return buf(data); return buf(data);
} }
private ByteBuf buf(byte[] bytes) { private static ByteBuf buf(byte[] bytes) {
return Unpooled.wrappedBuffer(bytes); return Unpooled.wrappedBuffer(bytes);
} }
@ -474,7 +474,7 @@ public class Http2FrameRoundtripTest {
return headers; return headers;
} }
private Http2Headers headersOfSize(final int minSize) { private static Http2Headers headersOfSize(final int minSize) {
final AsciiString singleByte = new AsciiString(new byte[]{0}, false); final AsciiString singleByte = new AsciiString(new byte[]{0}, false);
DefaultHttp2Headers headers = new DefaultHttp2Headers(false); DefaultHttp2Headers headers = new DefaultHttp2Headers(false);
for (int size = 0; size < minSize; size += 2) { for (int size = 0; size < minSize; size += 2) {

View File

@ -53,7 +53,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static io.netty.handler.codec.http.HttpMethod.CONNECT; import static io.netty.handler.codec.http.HttpMethod.CONNECT;
import static io.netty.handler.codec.http.HttpMethod.GET; import static io.netty.handler.codec.http.HttpMethod.GET;
@ -67,11 +66,11 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -540,6 +539,7 @@ public class HttpToHttp2ConnectionHandlerTest {
.build(); .build();
p.addLast(handler); p.addLast(handler);
p.addLast(new ChannelInboundHandlerAdapter() { p.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof Http2ConnectionPrefaceWrittenEvent) { if (evt instanceof Http2ConnectionPrefaceWrittenEvent) {
prefaceWrittenLatch.countDown(); prefaceWrittenLatch.countDown();
@ -556,7 +556,7 @@ public class HttpToHttp2ConnectionHandlerTest {
assertTrue(ccf.awaitUninterruptibly().isSuccess()); assertTrue(ccf.awaitUninterruptibly().isSuccess());
clientChannel = ccf.channel(); clientChannel = ccf.channel();
assertTrue(prefaceWrittenLatch.await(5, SECONDS)); assertTrue(prefaceWrittenLatch.await(5, SECONDS));
assertTrue(serverChannelLatch.await(WAIT_TIME_SECONDS, TimeUnit.SECONDS)); assertTrue(serverChannelLatch.await(WAIT_TIME_SECONDS, SECONDS));
} }
private void verifyHeadersOnly(Http2Headers expected, ChannelPromise writePromise, ChannelFuture writeFuture) private void verifyHeadersOnly(Http2Headers expected, ChannelPromise writePromise, ChannelFuture writeFuture)

View File

@ -25,12 +25,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.anyLong;
import static org.mockito.Matchers.anyShort; import static org.mockito.Mockito.anyShort;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;

View File

@ -30,10 +30,10 @@ import static org.junit.Assert.assertFalse;
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.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Matchers.same; import static org.mockito.Mockito.same;
import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
@ -46,7 +46,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
* Tests for {@link UniformStreamByteDistributor}. * Tests for {@link UniformStreamByteDistributor}.
*/ */
public class UniformStreamByteDistributorTest { public class UniformStreamByteDistributorTest {
private static int CHUNK_SIZE = DEFAULT_MIN_ALLOCATION_CHUNK; private static final int CHUNK_SIZE = DEFAULT_MIN_ALLOCATION_CHUNK;
private static final int STREAM_A = 1; private static final int STREAM_A = 1;
private static final int STREAM_B = 3; private static final int STREAM_B = 3;
@ -258,7 +258,7 @@ public class UniformStreamByteDistributorTest {
}); });
} }
private void setPriority(int streamId, int parent, int weight, boolean exclusive) throws Http2Exception { private void setPriority(int streamId, int parent, int weight, boolean exclusive) {
distributor.updateDependencyTree(streamId, parent, (short) weight, exclusive); distributor.updateDependencyTree(streamId, parent, (short) weight, exclusive);
} }

View File

@ -25,8 +25,8 @@ import static io.netty.handler.codec.http2.WeightedFairQueueByteDistributor.INIT
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
public class WeightedFairQueueByteDistributorDependencyTreeTest extends public class WeightedFairQueueByteDistributorDependencyTreeTest extends
@ -67,12 +67,12 @@ public class WeightedFairQueueByteDistributorDependencyTreeTest extends
final Http2Stream streamA = connection.local().createStream(3, false); final Http2Stream streamA = connection.local().createStream(3, false);
final Http2Stream streamB = connection.local().createStream(5, false); final Http2Stream streamB = connection.local().createStream(5, false);
final Http2Stream streamC = connection.local().createStream(7, false); final Http2Stream streamC = connection.local().createStream(7, false);
setPriority(streamB.id(), streamA.id(), Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT, false); setPriority(streamB.id(), streamA.id(), DEFAULT_PRIORITY_WEIGHT, false);
connection.forEachActiveStream(new Http2StreamVisitor() { connection.forEachActiveStream(new Http2StreamVisitor() {
@Override @Override
public boolean visit(Http2Stream stream) throws Http2Exception { public boolean visit(Http2Stream stream) throws Http2Exception {
streamA.close(); streamA.close();
setPriority(streamB.id(), streamC.id(), Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT, false); setPriority(streamB.id(), streamC.id(), DEFAULT_PRIORITY_WEIGHT, false);
return true; return true;
} }
}); });
@ -584,8 +584,8 @@ public class WeightedFairQueueByteDistributorDependencyTreeTest extends
setPriority(streamC.id(), streamA.id(), DEFAULT_PRIORITY_WEIGHT, false); setPriority(streamC.id(), streamA.id(), DEFAULT_PRIORITY_WEIGHT, false);
setPriority(streamD.id(), streamA.id(), DEFAULT_PRIORITY_WEIGHT, true); setPriority(streamD.id(), streamA.id(), DEFAULT_PRIORITY_WEIGHT, true);
boolean[] exclusives = new boolean[] {true, false}; boolean[] exclusives = { true, false };
short[] weights = new short[] { DEFAULT_PRIORITY_WEIGHT/*, 100, 200, DEFAULT_PRIORITY_WEIGHT */}; short[] weights = { DEFAULT_PRIORITY_WEIGHT, 100, 200, DEFAULT_PRIORITY_WEIGHT };
assertEquals(4, connection.numActiveStreams()); assertEquals(4, connection.numActiveStreams());

View File

@ -18,8 +18,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.mockito.verification.VerificationMode; import org.mockito.verification.VerificationMode;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
@ -28,10 +26,10 @@ import static org.junit.Assert.assertFalse;
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.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Matchers.same; import static org.mockito.Mockito.same;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;

View File

@ -22,8 +22,8 @@ import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.any; import static org.mockito.Mockito.any;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -33,7 +33,7 @@ public class PromiseCombinerTest {
@Mock @Mock
private Promise<Void> p1; private Promise<Void> p1;
private GenericFutureListener<Future<Void>> l1; private GenericFutureListener<Future<Void>> l1;
private GenericFutureListenerConsumer l1Consumer = new GenericFutureListenerConsumer() { private final GenericFutureListenerConsumer l1Consumer = new GenericFutureListenerConsumer() {
@Override @Override
public void accept(GenericFutureListener<Future<Void>> listener) { public void accept(GenericFutureListener<Future<Void>> listener) {
l1 = listener; l1 = listener;
@ -42,7 +42,7 @@ public class PromiseCombinerTest {
@Mock @Mock
private Promise<Void> p2; private Promise<Void> p2;
private GenericFutureListener<Future<Void>> l2; private GenericFutureListener<Future<Void>> l2;
private GenericFutureListenerConsumer l2Consumer = new GenericFutureListenerConsumer() { private final GenericFutureListenerConsumer l2Consumer = new GenericFutureListenerConsumer() {
@Override @Override
public void accept(GenericFutureListener<Future<Void>> listener) { public void accept(GenericFutureListener<Future<Void>> listener) {
l2 = listener; l2 = listener;
@ -148,28 +148,28 @@ public class PromiseCombinerTest {
verifyFail(p3, e1); verifyFail(p3, e1);
} }
private void verifyFail(Promise<Void> p, Throwable cause) { private static void verifyFail(Promise<Void> p, Throwable cause) {
verify(p).tryFailure(eq(cause)); verify(p).tryFailure(eq(cause));
} }
private void verifySuccess(Promise<Void> p) { private static void verifySuccess(Promise<Void> p) {
verify(p).trySuccess(null); verify(p).trySuccess(null);
} }
private void verifyNotCompleted(Promise<Void> p) { private static void verifyNotCompleted(Promise<Void> p) {
verify(p, never()).trySuccess(any(Void.class)); verify(p, never()).trySuccess(any(Void.class));
verify(p, never()).tryFailure(any(Throwable.class)); verify(p, never()).tryFailure(any(Throwable.class));
verify(p, never()).setSuccess(any(Void.class)); verify(p, never()).setSuccess(any(Void.class));
verify(p, never()).setFailure(any(Throwable.class)); verify(p, never()).setFailure(any(Throwable.class));
} }
private void mockSuccessPromise(Promise<Void> p, GenericFutureListenerConsumer consumer) { private static void mockSuccessPromise(Promise<Void> p, GenericFutureListenerConsumer consumer) {
when(p.isDone()).thenReturn(true); when(p.isDone()).thenReturn(true);
when(p.isSuccess()).thenReturn(true); when(p.isSuccess()).thenReturn(true);
mockListener(p, consumer); mockListener(p, consumer);
} }
private void mockFailedPromise(Promise<Void> p, Throwable cause, GenericFutureListenerConsumer consumer) { private static void mockFailedPromise(Promise<Void> p, Throwable cause, GenericFutureListenerConsumer consumer) {
when(p.isDone()).thenReturn(true); when(p.isDone()).thenReturn(true);
when(p.isSuccess()).thenReturn(false); when(p.isSuccess()).thenReturn(false);
when(p.cause()).thenReturn(cause); when(p.cause()).thenReturn(cause);
@ -177,7 +177,7 @@ public class PromiseCombinerTest {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void mockListener(final Promise<Void> p, final GenericFutureListenerConsumer consumer) { private static void mockListener(final Promise<Void> p, final GenericFutureListenerConsumer consumer) {
doAnswer(new Answer<Promise<Void>>() { doAnswer(new Answer<Promise<Void>>() {
@SuppressWarnings({ "unchecked", "raw-types" }) @SuppressWarnings({ "unchecked", "raw-types" })
@Override @Override