Fix inspection warnings related with JUnit usage

This commit is contained in:
Trustin Lee 2012-11-12 12:45:06 +09:00
parent 669fa64829
commit 369574078b
14 changed files with 69 additions and 61 deletions

View File

@ -1267,7 +1267,7 @@ public abstract class AbstractChannelBufferTest {
// Make sure if it is a sliced buffer.
slice.setByte(0, (byte) (slice.getByte(0) + 1));
assertTrue(buffer.getByte(0) == slice.getByte(0));
assertEquals(buffer.getByte(0), slice.getByte(0));
}
@Test
@ -1462,9 +1462,9 @@ public abstract class AbstractChannelBufferTest {
// Make sure the buffer content is shared.
buffer.setByte(readerIndex, (byte) (buffer.getByte(readerIndex) + 1));
assertTrue(buffer.getByte(readerIndex) == duplicate.getByte(readerIndex));
assertEquals(buffer.getByte(readerIndex), duplicate.getByte(readerIndex));
duplicate.setByte(1, (byte) (duplicate.getByte(1) + 1));
assertTrue(buffer.getByte(1) == duplicate.getByte(1));
assertEquals(buffer.getByte(1), duplicate.getByte(1));
}
@Test

View File

@ -15,15 +15,15 @@
*/
package org.jboss.netty.buffer;
import static org.jboss.netty.buffer.ChannelBuffers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import static org.jboss.netty.buffer.ChannelBuffers.*;
import static org.junit.Assert.*;
/**
* An abstract test class for composite channel buffers
@ -95,7 +95,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
CompositeChannelBuffer buf = (CompositeChannelBuffer) wrappedBuffer(new byte[]{1, 2, 3, 4, 5}, new byte[]{4, 5, 6, 7, 8, 9, 26});
//Ensure that a random place will be fine
assertEquals(buf.getBuffer(2).capacity(), 5);
assertEquals(5, buf.getBuffer(2).capacity());
//Loop through each byte
byte index = 0;
@ -158,8 +158,8 @@ public abstract class AbstractCompositeChannelBufferTest extends
ChannelBuffer buffer = wrappedBuffer(header, payload);
assertTrue(header.readableBytes() == 12);
assertTrue(payload.readableBytes() == 512);
assertEquals(12, header.readableBytes());
assertEquals(512, payload.readableBytes());
assertEquals(12 + 512, buffer.readableBytes());

View File

@ -46,8 +46,8 @@ public class ChannelBuffersTest {
ChannelBuffer buffer = wrappedBuffer(header, payload);
assertTrue(header.readableBytes() == 12);
assertTrue(payload.readableBytes() == 512);
assertEquals(12, header.readableBytes());
assertEquals(512, payload.readableBytes());
assertEquals(12 + 512, buffer.readableBytes());

View File

@ -28,21 +28,21 @@ public class DefaultChannelPipelineTest {
pipeline.addLast("handler1", handler1);
pipeline.addLast("handler2", handler1);
pipeline.addLast("handler3", handler1);
assertTrue(pipeline.get("handler1") == handler1);
assertTrue(pipeline.get("handler2") == handler1);
assertTrue(pipeline.get("handler3") == handler1);
assertSame(pipeline.get("handler1"), handler1);
assertSame(pipeline.get("handler2"), handler1);
assertSame(pipeline.get("handler3"), handler1);
SimpleChannelHandler newHandler1 = new SimpleChannelHandler();
pipeline.replace("handler1", "handler1", newHandler1);
assertTrue(pipeline.get("handler1") == newHandler1);
assertSame(pipeline.get("handler1"), newHandler1);
SimpleChannelHandler newHandler3 = new SimpleChannelHandler();
pipeline.replace("handler3", "handler3", newHandler3);
assertTrue(pipeline.get("handler3") == newHandler3);
assertSame(pipeline.get("handler3"), newHandler3);
SimpleChannelHandler newHandler2 = new SimpleChannelHandler();
pipeline.replace("handler2", "handler2", newHandler2);
assertTrue(pipeline.get("handler2") == newHandler2);
assertSame(pipeline.get("handler2"), newHandler2);
}
// Test for #505

View File

@ -15,12 +15,11 @@
*/
package org.jboss.netty.channel;
import java.util.Map;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
@SuppressWarnings("deprecation")
public class StaticChannelPipelineTest {

View File

@ -27,6 +27,8 @@ import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertNull;
public class LocalAddressTest {
private static final String LOCAL_ADDR_ID = "test.id";
@ -80,7 +82,7 @@ public class LocalAddressTest {
sb.releaseExternalResources();
cb.releaseExternalResources();
Assert.assertTrue(String.format("Expected null, got channel '%s' for local address '%s'", LocalChannelRegistry.getChannel(addr), addr), LocalChannelRegistry.getChannel(addr) == null);
assertNull(String.format("Expected null, got channel '%s' for local address '%s'", LocalChannelRegistry.getChannel(addr), addr), LocalChannelRegistry.getChannel(addr));
}
@Test
@ -133,7 +135,7 @@ public class LocalAddressTest {
sb.releaseExternalResources();
cb.releaseExternalResources();
Assert.assertTrue(String.format("Expected null, got channel '%s' for local address '%s'", LocalChannelRegistry.getChannel(addr), addr), LocalChannelRegistry.getChannel(addr) == null);
assertNull(String.format("Expected null, got channel '%s' for local address '%s'", LocalChannelRegistry.getChannel(addr), addr), LocalChannelRegistry.getChannel(addr));
}
public static class TestHandler

View File

@ -16,7 +16,6 @@
package org.jboss.netty.channel.socket.nio;
import static org.easymock.EasyMock.*;
import static junit.framework.Assert.*;
import java.util.concurrent.Executor;
@ -26,6 +25,7 @@ import java.util.concurrent.RejectedExecutionException;
import org.jboss.netty.channel.ChannelFuture;
import org.junit.Assert;
import org.junit.Test;
public abstract class AbstractNioWorkerTest {
@ -48,7 +48,7 @@ public abstract class AbstractNioWorkerTest {
Thread.sleep(SelectorUtil.DEFAULT_SELECT_TIMEOUT * 10);
try {
worker.register(mockChannel, mockFuture);
fail();
Assert.fail();
} catch (RejectedExecutionException e) {
// expected
}

View File

@ -15,6 +15,10 @@
*/
package org.jboss.netty.channel.socket.nio;
import org.jboss.netty.util.internal.DetectionUtil;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
@ -23,10 +27,7 @@ import java.net.StandardProtocolFamily;
import java.nio.channels.DatagramChannel;
import java.util.Enumeration;
import junit.framework.Assert;
import org.jboss.netty.util.internal.DetectionUtil;
import org.junit.Test;
import static org.junit.Assert.*;
public class DefaultNioDatagramChannelConfigTest {
@ -63,16 +64,16 @@ public class DefaultNioDatagramChannelConfigTest {
DefaultNioDatagramChannelConfig config = new DefaultNioDatagramChannelConfig(DatagramChannel.open(family));
config.setNetworkInterface(inf);
Assert.assertEquals(inf, config.getNetworkInterface());
assertEquals(inf, config.getNetworkInterface());
InetAddress localhost = inf.getInetAddresses().nextElement();
config.setInterface(localhost);
Assert.assertEquals(localhost, config.getInterface());
assertEquals(localhost, config.getInterface());
config.setTimeToLive(100);
Assert.assertEquals(100, config.getTimeToLive());
assertEquals(100, config.getTimeToLive());
config.setLoopbackModeDisabled(false);
Assert.assertEquals(false, config.isLoopbackModeDisabled());
assertFalse(config.isLoopbackModeDisabled());
}
}

View File

@ -15,7 +15,6 @@
*/
package org.jboss.netty.handler.codec.marshalling;
import junit.framework.Assert;
import org.jboss.marshalling.Marshaller;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
@ -58,9 +57,9 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
String unmarshalled = (String) decoder.poll();
Assert.assertEquals(testObject, unmarshalled);
assertEquals(testObject, unmarshalled);
Assert.assertNull(decoder.poll());
assertNull(decoder.poll());
}
protected ChannelBuffer input(byte[] input) {
@ -93,9 +92,9 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
String unmarshalled = (String) decoder.poll();
Assert.assertEquals(testObject, unmarshalled);
assertEquals(testObject, unmarshalled);
Assert.assertNull(decoder.poll());
assertNull(decoder.poll());
}
@Test

View File

@ -15,7 +15,6 @@
*/
package org.jboss.netty.handler.codec.marshalling;
import junit.framework.Assert;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;

View File

@ -16,6 +16,7 @@
package org.jboss.netty.handler.codec.spdy;
import static org.jboss.netty.handler.codec.spdy.SpdyCodecUtil.*;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.Map;
@ -54,16 +55,16 @@ public class SpdySessionHandlerTest {
Assert.assertNotNull(msg);
Assert.assertTrue(msg instanceof SpdyDataFrame);
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
Assert.assertTrue(spdyDataFrame.getStreamId() == streamID);
Assert.assertTrue(spdyDataFrame.isLast() == last);
assertEquals(spdyDataFrame.getStreamId(), streamID);
assertEquals(spdyDataFrame.isLast(), last);
}
private static void assertSynReply(Object msg, int streamID, boolean last, SpdyHeaderBlock headers) {
Assert.assertNotNull(msg);
Assert.assertTrue(msg instanceof SpdySynReplyFrame);
SpdySynReplyFrame spdySynReplyFrame = (SpdySynReplyFrame) msg;
Assert.assertTrue(spdySynReplyFrame.getStreamId() == streamID);
Assert.assertTrue(spdySynReplyFrame.isLast() == last);
assertEquals(spdySynReplyFrame.getStreamId(), streamID);
assertEquals(spdySynReplyFrame.isLast(), last);
assertHeaderBlock(spdySynReplyFrame, headers);
}
@ -71,29 +72,29 @@ public class SpdySessionHandlerTest {
Assert.assertNotNull(msg);
Assert.assertTrue(msg instanceof SpdyRstStreamFrame);
SpdyRstStreamFrame spdyRstStreamFrame = (SpdyRstStreamFrame) msg;
Assert.assertTrue(spdyRstStreamFrame.getStreamId() == streamID);
Assert.assertTrue(spdyRstStreamFrame.getStatus().equals(status));
assertEquals(spdyRstStreamFrame.getStreamId(), streamID);
assertEquals(spdyRstStreamFrame.getStatus(), status);
}
private static void assertPing(Object msg, int ID) {
Assert.assertNotNull(msg);
Assert.assertTrue(msg instanceof SpdyPingFrame);
SpdyPingFrame spdyPingFrame = (SpdyPingFrame) msg;
Assert.assertTrue(spdyPingFrame.getId() == ID);
assertEquals(spdyPingFrame.getId(), ID);
}
private static void assertGoAway(Object msg, int lastGoodStreamID) {
Assert.assertNotNull(msg);
Assert.assertTrue(msg instanceof SpdyGoAwayFrame);
SpdyGoAwayFrame spdyGoAwayFrame = (SpdyGoAwayFrame) msg;
Assert.assertTrue(spdyGoAwayFrame.getLastGoodStreamId() == lastGoodStreamID);
assertEquals(spdyGoAwayFrame.getLastGoodStreamId(), lastGoodStreamID);
}
private static void assertHeaders(Object msg, int streamID, SpdyHeaderBlock headers) {
Assert.assertNotNull(msg);
Assert.assertTrue(msg instanceof SpdyHeadersFrame);
SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
Assert.assertTrue(spdyHeadersFrame.getStreamId() == streamID);
assertEquals(spdyHeadersFrame.getStreamId(), streamID);
assertHeaderBlock(spdyHeadersFrame, headers);
}

View File

@ -15,12 +15,6 @@
*/
package org.jboss.netty.handler.ipfilter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import junit.framework.TestCase;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelConfig;
import org.jboss.netty.channel.ChannelEvent;
@ -32,7 +26,13 @@ import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.UpstreamMessageEvent;
import org.junit.Test;
public class IpFilterRuleTest extends TestCase {
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import static org.junit.Assert.*;
public class IpFilterRuleTest {
public static boolean accept(IpFilterRuleHandler h, InetSocketAddress addr) throws Exception {
return h.accept(new ChannelHandlerContext() {
@ -174,6 +174,14 @@ public class IpFilterRuleTest extends TestCase {
return 0;
}
public int hashCode() {
return 0;
}
public boolean equals(Object o) {
return this == o;
}
public Object getAttachment() {
return null;
}

View File

@ -19,8 +19,6 @@ import java.net.InetSocketAddress;
import javax.net.ssl.SSLEngine;
import junit.framework.Assert;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffers;
@ -32,6 +30,7 @@ import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.example.securechat.SecureChatSslContextFactory;
import org.jboss.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
public class SslCloseTest {

View File

@ -15,7 +15,6 @@
*/
package org.jboss.netty.handler.stream;
import junit.framework.Assert;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelFuture;
@ -25,6 +24,7 @@ import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelDownstreamHandler;
import org.jboss.netty.handler.codec.embedder.EncoderEmbedder;
import org.jboss.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import java.io.ByteArrayInputStream;
@ -172,7 +172,7 @@ public class ChunkedWriteHandlerTest {
embedder.offer(input);
}
Assert.assertTrue(embedder.finish());
assertTrue(embedder.finish());
int i = 0;
int read = 0;
@ -182,7 +182,7 @@ public class ChunkedWriteHandlerTest {
break;
}
while (buffer.readable()) {
Assert.assertEquals(BYTES[i++], buffer.readByte());
assertEquals(BYTES[i++], buffer.readByte());
read++;
if (i == BYTES.length) {
i = 0;
@ -190,6 +190,6 @@ public class ChunkedWriteHandlerTest {
}
}
Assert.assertEquals(BYTES.length * inputs.length, read);
assertEquals(BYTES.length * inputs.length, read);
}
}