Switched to JUnit 4 @nnotations
git-svn-id: https://svn.apache.org/repos/asf/mina/trunk@901509 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/test/java/org/apache/mina/filter/buffer/BufferedWriteFilterTest.java b/core/src/test/java/org/apache/mina/filter/buffer/BufferedWriteFilterTest.java
index 570d7ee..5439af5 100644
--- a/core/src/test/java/org/apache/mina/filter/buffer/BufferedWriteFilterTest.java
+++ b/core/src/test/java/org/apache/mina/filter/buffer/BufferedWriteFilterTest.java
@@ -19,15 +19,15 @@
*/
package org.apache.mina.filter.buffer;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.filterchain.IoFilterAdapter;
import org.apache.mina.core.session.DummySession;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRequest;
-import org.apache.mina.filter.buffer.BufferedWriteFilter;
import org.apache.mina.filter.logging.LoggingFilter;
+import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,15 +37,17 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
* @since MINA 2.0.0-M2
*/
-public class BufferedWriteFilterTest extends TestCase {
+public class BufferedWriteFilterTest {
static final Logger LOGGER = LoggerFactory
.getLogger(BufferedWriteFilterTest.class);
+ @Test
public void testNonExpandableBuffer() throws Exception {
IoBuffer dest = IoBuffer.allocate(1);
assertEquals(false, dest.isAutoExpand());
}
+ @Test
public void testBasicBuffering() {
DummySession sess = new DummySession();
sess.getFilterChain().addFirst("peer", new IoFilterAdapter() {
diff --git a/core/src/test/java/org/apache/mina/filter/codec/serialization/ObjectSerializationTest.java b/core/src/test/java/org/apache/mina/filter/codec/serialization/ObjectSerializationTest.java
index e3e2556..f614036 100644
--- a/core/src/test/java/org/apache/mina/filter/codec/serialization/ObjectSerializationTest.java
+++ b/core/src/test/java/org/apache/mina/filter/codec/serialization/ObjectSerializationTest.java
@@ -19,10 +19,9 @@
*/
package org.apache.mina.filter.codec.serialization;
-import java.io.ByteArrayOutputStream;
+import static org.junit.Assert.assertEquals;
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.filter.codec.ProtocolCodecSession;
@@ -30,13 +29,15 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.junit.Test;
/**
* Tests object serialization codec and streams.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class ObjectSerializationTest extends TestCase {
+public class ObjectSerializationTest {
+ @Test
public void testEncoder() throws Exception {
final String expected = "1234";
@@ -46,12 +47,13 @@
ProtocolEncoder encoder = new ObjectSerializationEncoder();
encoder.encode(session, expected, out);
- Assert.assertEquals(1, session.getEncoderOutputQueue().size());
+ assertEquals(1, session.getEncoderOutputQueue().size());
IoBuffer buf = (IoBuffer) session.getEncoderOutputQueue().poll();
testDecoderAndInputStream(expected, buf);
}
+ @Test
public void testOutputStream() throws Exception {
final String expected = "1234";
@@ -80,7 +82,7 @@
ProtocolDecoderOutput decoderOut = session.getDecoderOutput();
decoder.decode(session, in.duplicate(), decoderOut);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals(expected, session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals(expected, session.getDecoderOutputQueue().poll());
}
}
diff --git a/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java b/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
index a2f891e..10fef7d 100644
--- a/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
+++ b/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
@@ -19,27 +19,27 @@
*/
package org.apache.mina.filter.codec.textline;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.filter.codec.ProtocolCodecSession;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.apache.mina.filter.codec.RecoverableProtocolDecoderException;
+import org.junit.Test;
+
/**
* Tests {@link TextLineDecoder}.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class TextLineDecoderTest extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(TextLineDecoderTest.class);
- }
-
+public class TextLineDecoderTest {
+ @Test
public void testNormalDecode() throws Exception {
TextLineDecoder decoder = new TextLineDecoder(Charset.forName("UTF-8"),
LineDelimiter.WINDOWS);
@@ -53,38 +53,38 @@
in.putString("ABC\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("ABC", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("ABC", session.getDecoderOutputQueue().poll());
// Test two decode and one output
in.clear();
in.putString("DEF", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("GHI\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("DEFGHI", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("DEFGHI", session.getDecoderOutputQueue().poll());
// Test one decode and two output
in.clear();
in.putString("JKL\r\nMNO\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(2, session.getDecoderOutputQueue().size());
- Assert.assertEquals("JKL", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("MNO", session.getDecoderOutputQueue().poll());
+ assertEquals(2, session.getDecoderOutputQueue().size());
+ assertEquals("JKL", session.getDecoderOutputQueue().poll());
+ assertEquals("MNO", session.getDecoderOutputQueue().poll());
// Test aborted delimiter (DIRMINA-506)
in.clear();
in.putString("ABC\r\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("ABC\r", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("ABC\r", session.getDecoderOutputQueue().poll());
// Test splitted long delimiter
decoder = new TextLineDecoder(Charset.forName("UTF-8"),
@@ -93,18 +93,18 @@
in.putString("PQR\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("PQR", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("PQR", session.getDecoderOutputQueue().poll());
// Test splitted long delimiter which produces two output
decoder = new TextLineDecoder(Charset.forName("UTF-8"),
@@ -113,19 +113,19 @@
in.putString("PQR\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\nSTU\n\n\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(2,session.getDecoderOutputQueue().size());
- Assert.assertEquals("PQR", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("STU", session.getDecoderOutputQueue().poll());
+ assertEquals(2,session.getDecoderOutputQueue().size());
+ assertEquals("PQR", session.getDecoderOutputQueue().poll());
+ assertEquals("STU", session.getDecoderOutputQueue().poll());
// Test splitted long delimiter mixed with partial non-delimiter.
decoder = new TextLineDecoder(Charset.forName("UTF-8"),
@@ -134,19 +134,19 @@
in.putString("PQR\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("X\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\n\nSTU\n\n\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(2, session.getDecoderOutputQueue().size());
- Assert.assertEquals("PQR\nX", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("STU", session.getDecoderOutputQueue().poll());
+ assertEquals(2, session.getDecoderOutputQueue().size());
+ assertEquals("PQR\nX", session.getDecoderOutputQueue().poll());
+ assertEquals("STU", session.getDecoderOutputQueue().poll());
}
public void testAutoDecode() throws Exception {
@@ -162,96 +162,96 @@
in.putString("ABC\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("ABC", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("ABC", session.getDecoderOutputQueue().poll());
// Test two decode and one output
in.clear();
in.putString("DEF", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("GHI\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("DEFGHI", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("DEFGHI", session.getDecoderOutputQueue().poll());
// Test one decode and two output
in.clear();
in.putString("JKL\r\nMNO\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(2, session.getDecoderOutputQueue().size());
- Assert.assertEquals("JKL", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("MNO", session.getDecoderOutputQueue().poll());
+ assertEquals(2, session.getDecoderOutputQueue().size());
+ assertEquals("JKL", session.getDecoderOutputQueue().poll());
+ assertEquals("MNO", session.getDecoderOutputQueue().poll());
// Test multiple '\n's
in.clear();
in.putString("\n\n\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(3, session.getDecoderOutputQueue().size());
- Assert.assertEquals("", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("", session.getDecoderOutputQueue().poll());
+ assertEquals(3, session.getDecoderOutputQueue().size());
+ assertEquals("", session.getDecoderOutputQueue().poll());
+ assertEquals("", session.getDecoderOutputQueue().poll());
+ assertEquals("", session.getDecoderOutputQueue().poll());
// Test splitted long delimiter (\r\r\n)
in.clear();
in.putString("PQR\r", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\r", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("PQR", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("PQR", session.getDecoderOutputQueue().poll());
// Test splitted long delimiter (\r\r\n) which produces two output
in.clear();
in.putString("PQR\r", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\r", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\nSTU\r\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(2, session.getDecoderOutputQueue().size());
- Assert.assertEquals("PQR", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("STU", session.getDecoderOutputQueue().poll());
+ assertEquals(2, session.getDecoderOutputQueue().size());
+ assertEquals("PQR", session.getDecoderOutputQueue().poll());
+ assertEquals("STU", session.getDecoderOutputQueue().poll());
// Test splitted long delimiter mixed with partial non-delimiter.
in.clear();
in.putString("PQR\r", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("X\r", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear();
in.putString("\r\nSTU\r\r\n", encoder);
in.flip();
decoder.decode(session, in, out);
- Assert.assertEquals(2, session.getDecoderOutputQueue().size());
- Assert.assertEquals("PQR\rX", session.getDecoderOutputQueue().poll());
- Assert.assertEquals("STU", session.getDecoderOutputQueue().poll());
+ assertEquals(2, session.getDecoderOutputQueue().size());
+ assertEquals("PQR\rX", session.getDecoderOutputQueue().poll());
+ assertEquals("STU", session.getDecoderOutputQueue().poll());
}
public void testOverflow() throws Exception {
@@ -268,54 +268,56 @@
// the delimiter is encountered.
in.putString("A", encoder).flip().mark();
decoder.decode(session, in.reset().mark(), out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
decoder.decode(session, in.reset().mark(), out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
decoder.decode(session, in.reset().mark(), out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
decoder.decode(session, in.reset().mark(), out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.clear().putString("A\r\nB\r\n", encoder).flip();
+
try {
decoder.decode(session, in, out);
- Assert.fail();
+ fail();
} catch (RecoverableProtocolDecoderException e) {
// signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("B", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("B", session.getDecoderOutputQueue().poll());
// Make sure OOM is not thrown.
System.gc();
long oldFreeMemory = Runtime.getRuntime().freeMemory();
in = IoBuffer.allocate(1048576 * 16).sweep((byte) ' ').mark();
+
for (int i = 0; i < 10; i ++) {
decoder.decode(session, in.reset().mark(), out);
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
// Memory consumption should be minimal.
- Assert.assertTrue(Runtime.getRuntime().freeMemory() - oldFreeMemory < 1048576);
+ assertTrue(Runtime.getRuntime().freeMemory() - oldFreeMemory < 1048576);
}
in.clear().putString("C\r\nD\r\n", encoder).flip();
try {
decoder.decode(session, in, out);
- Assert.fail();
+ fail();
} catch (RecoverableProtocolDecoderException e) {
// signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
decoder.decode(session, in, out);
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("D", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("D", session.getDecoderOutputQueue().poll());
// Memory consumption should be minimal.
- Assert.assertTrue(Runtime.getRuntime().freeMemory() - oldFreeMemory < 1048576);
+ assertTrue(Runtime.getRuntime().freeMemory() - oldFreeMemory < 1048576);
}
public void testSMTPDataBounds() throws Exception {
@@ -328,10 +330,10 @@
in.putString("\r\n", encoder).flip().mark();
decoder.decode(session, in.reset().mark(), session.getDecoderOutput());
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(0, session.getDecoderOutputQueue().size());
in.putString("Body\r\n.\r\n", encoder).flip().mark();
decoder.decode(session, in.reset().mark(), session.getDecoderOutput());
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals("\r\n\r\nBody", session.getDecoderOutputQueue().poll());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals("\r\n\r\nBody", session.getDecoderOutputQueue().poll());
}
}
diff --git a/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java b/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java
index 8615f20..f386fbc 100644
--- a/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java
+++ b/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java
@@ -19,25 +19,22 @@
*/
package org.apache.mina.filter.codec.textline;
-import java.nio.charset.Charset;
+import static org.junit.Assert.assertEquals;
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import java.nio.charset.Charset;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.filter.codec.ProtocolCodecSession;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.junit.Test;
/**
* Tests {@link TextLineEncoder}.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class TextLineEncoderTest extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(TextLineEncoderTest.class);
- }
-
+public class TextLineEncoderTest {
+ @Test
public void testEncode() throws Exception {
TextLineEncoder encoder = new TextLineEncoder(Charset.forName("UTF-8"),
LineDelimiter.WINDOWS);
@@ -45,13 +42,13 @@
ProtocolEncoderOutput out = session.getEncoderOutput();
encoder.encode(session, "ABC", out);
- Assert.assertEquals(1, session.getEncoderOutputQueue().size());
+ assertEquals(1, session.getEncoderOutputQueue().size());
IoBuffer buf = (IoBuffer) session.getEncoderOutputQueue().poll();
- Assert.assertEquals(5, buf.remaining());
- Assert.assertEquals('A', buf.get());
- Assert.assertEquals('B', buf.get());
- Assert.assertEquals('C', buf.get());
- Assert.assertEquals('\r', buf.get());
- Assert.assertEquals('\n', buf.get());
+ assertEquals(5, buf.remaining());
+ assertEquals('A', buf.get());
+ assertEquals('B', buf.get());
+ assertEquals('C', buf.get());
+ assertEquals('\r', buf.get());
+ assertEquals('\n', buf.get());
}
}
diff --git a/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java b/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
index 3184e60..baa3dda 100644
--- a/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
+++ b/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
@@ -19,41 +19,44 @@
*/
package org.apache.mina.filter.executor;
+import static org.junit.Assert.assertEquals;
+
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
import org.apache.mina.core.session.DummySession;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRequest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* TODO Add documentation
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class ExecutorFilterRegressionTest extends TestCase {
+public class ExecutorFilterRegressionTest {
private ExecutorFilter filter;
public ExecutorFilterRegressionTest() {
// Do nothing
}
- @Override
+ @Before
public void setUp() throws Exception {
filter = new ExecutorFilter(8);
}
- @Override
+ @After
public void tearDown() throws Exception {
((ExecutorService) filter.getExecutor()).shutdown();
filter = null;
}
+ @Test
public void testEventOrder() throws Throwable {
final EventOrderChecker nextFilter = new EventOrderChecker();
final EventOrderCounter[] sessions = new EventOrderCounter[] {
@@ -84,7 +87,7 @@
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
for (int i = end; i >= 0; i--) {
- Assert.assertEquals(loop - 1, sessions[i].lastCount.intValue());
+ assertEquals(loop - 1, sessions[i].lastCount.intValue());
}
}
@@ -100,7 +103,7 @@
public synchronized void setLastCount(Integer newCount) {
if (lastCount != null) {
- Assert.assertEquals(lastCount.intValue() + 1, newCount
+ assertEquals(lastCount.intValue() + 1, newCount
.intValue());
}
@@ -160,8 +163,4 @@
// Do nothing
}
}
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(ExecutorFilterRegressionTest.class);
- }
}
diff --git a/core/src/test/java/org/apache/mina/filter/firewall/ConnectionThrottleFilterTest.java b/core/src/test/java/org/apache/mina/filter/firewall/ConnectionThrottleFilterTest.java
index 0326544..0ce0f98 100644
--- a/core/src/test/java/org/apache/mina/filter/firewall/ConnectionThrottleFilterTest.java
+++ b/core/src/test/java/org/apache/mina/filter/firewall/ConnectionThrottleFilterTest.java
@@ -20,26 +20,31 @@
package org.apache.mina.filter.firewall;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.net.InetSocketAddress;
-import junit.framework.TestCase;
-
import org.apache.mina.core.session.DummySession;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
/**
* TODO Add documentation
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class ConnectionThrottleFilterTest extends TestCase
+public class ConnectionThrottleFilterTest
{
private ConnectionThrottleFilter filter;
private DummySession sessionOne;
private DummySession sessionTwo;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
filter = new ConnectionThrottleFilter();
@@ -49,15 +54,17 @@
sessionTwo.setRemoteAddress( new InetSocketAddress(1235) );
}
- @Override
- protected void tearDown() throws Exception
+ @After
+ public void tearDown() throws Exception
{
filter = null;
}
+ @Test
public void testGoodConnection(){
filter.setAllowedInterval( 100 );
filter.isConnectionOk( sessionOne );
+
try
{
Thread.sleep( 1000 );
@@ -71,13 +78,10 @@
assertTrue( result );
}
+ @Test
public void testBadConnection(){
filter.setAllowedInterval( 1000 );
filter.isConnectionOk( sessionTwo );
assertFalse(filter.isConnectionOk( sessionTwo ));
}
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run( ConnectionThrottleFilterTest.class );
- }
}
diff --git a/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv4Test.java b/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv4Test.java
index 28a8910..b422240 100644
--- a/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv4Test.java
+++ b/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv4Test.java
@@ -20,18 +20,22 @@
package org.apache.mina.filter.firewall;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.net.InetAddress;
import java.net.UnknownHostException;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* TODO Add documentation
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class SubnetIPv4Test extends TestCase {
-
+public class SubnetIPv4Test {
+ @Test
public void test24() throws UnknownHostException {
InetAddress a = InetAddress.getByName("127.2.3.0");
InetAddress b = InetAddress.getByName("127.2.3.4");
@@ -46,6 +50,7 @@
assertFalse(mask.inSubnet(d));
}
+ @Test
public void test16() throws UnknownHostException {
InetAddress a = InetAddress.getByName("127.2.0.0");
InetAddress b = InetAddress.getByName("127.2.3.4");
@@ -60,6 +65,7 @@
assertFalse(mask.inSubnet(d));
}
+ @Test
public void testSingleIp() throws UnknownHostException {
InetAddress a = InetAddress.getByName("127.2.3.4");
InetAddress b = InetAddress.getByName("127.2.3.3");
@@ -74,6 +80,7 @@
assertFalse(mask.inSubnet(d));
}
+ @Test
public void testToString() throws UnknownHostException {
InetAddress a = InetAddress.getByName("127.2.3.0");
Subnet mask = new Subnet(a, 24);
@@ -81,6 +88,7 @@
assertEquals("127.2.3.0/24", mask.toString());
}
+ @Test
public void testToStringLiteral() throws UnknownHostException {
InetAddress a = InetAddress.getByName("localhost");
Subnet mask = new Subnet(a, 32);
@@ -89,6 +97,7 @@
}
+ @Test
public void testEquals() throws UnknownHostException {
Subnet a = new Subnet(InetAddress.getByName("127.2.3.4"), 32);
Subnet b = new Subnet(InetAddress.getByName("127.2.3.4"), 32);
diff --git a/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv6Test.java b/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv6Test.java
index 5db1c52..6e1de22 100644
--- a/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv6Test.java
+++ b/core/src/test/java/org/apache/mina/filter/firewall/SubnetIPv6Test.java
@@ -20,33 +20,37 @@
package org.apache.mina.filter.firewall;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import junit.framework.TestCase;
-import junit.framework.Assert;
+import org.junit.Test;
/**
* TODO Add documentation
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class SubnetIPv6Test extends TestCase {
+public class SubnetIPv6Test {
// Test Data
private static final String TEST_V6ADDRESS = "1080:0:0:0:8:800:200C:417A";
+ @Test
public void testIPv6() throws UnknownHostException {
InetAddress a = InetAddress.getByName(TEST_V6ADDRESS);
assertTrue(a instanceof Inet6Address);
+
try {
new Subnet(a, 24);
fail("IPv6 not supported");
} catch(IllegalArgumentException e) {
// signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
}
}
diff --git a/core/src/test/java/org/apache/mina/filter/keepalive/KeepAliveFilterTest.java b/core/src/test/java/org/apache/mina/filter/keepalive/KeepAliveFilterTest.java
index f8995ba..1bef621 100644
--- a/core/src/test/java/org/apache/mina/filter/keepalive/KeepAliveFilterTest.java
+++ b/core/src/test/java/org/apache/mina/filter/keepalive/KeepAliveFilterTest.java
@@ -19,13 +19,13 @@
*/
package org.apache.mina.filter.keepalive;
-import static org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler.*;
+import static org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler.EXCEPTION;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;
-import junit.framework.TestCase;
-
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoHandlerAdapter;
@@ -33,6 +33,9 @@
import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests {@link KeepAliveFilter} used by the connector with different
@@ -40,7 +43,7 @@
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class KeepAliveFilterTest extends TestCase {
+public class KeepAliveFilterTest {
// Constants -----------------------------------------------------
static final IoBuffer PING = IoBuffer.wrap(new byte[] { 1 });
static final IoBuffer PONG = IoBuffer.wrap(new byte[] { 2 });
@@ -50,10 +53,8 @@
private int port;
private NioSocketAcceptor acceptor;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
acceptor = new NioSocketAcceptor();
KeepAliveMessageFactory factory = new ServerFactory();
KeepAliveFilter filter = new KeepAliveFilter(factory,
@@ -65,21 +66,23 @@
port = acceptor.getLocalAddress().getPort();
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
acceptor.unbind();
acceptor.dispose();
- super.tearDown();
}
+ @Test
public void testKeepAliveFilterForReaderIdle() throws Exception {
keepAliveFilterForIdleStatus(IdleStatus.READER_IDLE);
}
+ @Test
public void testKeepAliveFilterForBothIdle() throws Exception {
keepAliveFilterForIdleStatus(IdleStatus.BOTH_IDLE);
}
+ @Test
public void testKeepAliveFilterForWriterIdle() throws Exception {
keepAliveFilterForIdleStatus(IdleStatus.WRITER_IDLE);
}
diff --git a/core/src/test/java/org/apache/mina/filter/reqres/RequestResponseFilterTest.java b/core/src/test/java/org/apache/mina/filter/reqres/RequestResponseFilterTest.java
index 3b86f5f..df3ce2f 100644
--- a/core/src/test/java/org/apache/mina/filter/reqres/RequestResponseFilterTest.java
+++ b/core/src/test/java/org/apache/mina/filter/reqres/RequestResponseFilterTest.java
@@ -19,12 +19,15 @@
*/
package org.apache.mina.filter.reqres;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.NoSuchElementException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import junit.framework.TestCase;
-
import org.apache.mina.core.filterchain.IoFilterChain;
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
import org.apache.mina.core.session.DummySession;
@@ -34,7 +37,6 @@
import org.easymock.AbstractMatcher;
import org.easymock.MockControl;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +45,7 @@
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class RequestResponseFilterTest extends TestCase {
+public class RequestResponseFilterTest {
private ScheduledExecutorService scheduler;
@@ -59,7 +61,6 @@
private final WriteRequestMatcher matcher = new WriteRequestMatcher();
- @Override
@Before
public void setUp() throws Exception {
scheduler = Executors.newScheduledThreadPool(1);
@@ -74,10 +75,9 @@
// Initialize the filter.
filter.onPreAdd(chain, "reqres", nextFilter);
filter.onPostAdd(chain, "reqres", nextFilter);
- Assert.assertFalse(session.getAttributeKeys().isEmpty());
+ assertFalse(session.getAttributeKeys().isEmpty());
}
- @Override
@After
public void tearDown() throws Exception {
// Destroy the filter.
@@ -111,7 +111,7 @@
// Verify
nextFilterControl.verify();
- Assert.assertEquals(res, req.awaitResponse());
+ assertEquals(res, req.awaitResponse());
assertNoSuchElementException(req);
}
@@ -120,10 +120,10 @@
// Make sure if an exception is thrown if a user waits one more time.
try {
req.awaitResponse();
- Assert.fail();
+ fail();
} catch (NoSuchElementException e) {
// Signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
}
@@ -155,8 +155,8 @@
// Verify
nextFilterControl.verify();
- Assert.assertEquals(res1, req.awaitResponse());
- Assert.assertEquals(res2, req.awaitResponse());
+ assertEquals(res1, req.awaitResponse());
+ assertEquals(res2, req.awaitResponse());
assertNoSuchElementException(req);
}
@@ -192,10 +192,10 @@
throws InterruptedException {
try {
req.awaitResponse();
- Assert.fail();
+ fail();
} catch (RequestTimeoutException e) {
// Signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
}
@@ -228,7 +228,7 @@
// Verify
nextFilterControl.verify();
- Assert.assertEquals(res1, req.awaitResponse());
+ assertEquals(res1, req.awaitResponse());
assertRequestTimeoutException(req);
assertNoSuchElementException(req);
}
diff --git a/core/src/test/java/org/apache/mina/filter/ssl/KeyStoreFactoryTest.java b/core/src/test/java/org/apache/mina/filter/ssl/KeyStoreFactoryTest.java
index aaf5a86..9a6515d 100644
--- a/core/src/test/java/org/apache/mina/filter/ssl/KeyStoreFactoryTest.java
+++ b/core/src/test/java/org/apache/mina/filter/ssl/KeyStoreFactoryTest.java
@@ -25,14 +25,15 @@
import java.io.OutputStream;
import java.security.KeyStore;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests {@link KeyStoreFactory}.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class KeyStoreFactoryTest extends TestCase {
+public class KeyStoreFactoryTest {
+ @Test
public void testCreateInstanceFromResource() throws Exception {
// Test using default for now.
KeyStoreFactory factory = new KeyStoreFactory();
@@ -45,6 +46,7 @@
ks.getKey("bogus", "boguspw".toCharArray());
}
+ @Test
public void testCreateInstanceFromFile() throws Exception {
// Copy the keystore from the class path to a temporary file.
File file = File.createTempFile("keystoretest ", null);
@@ -52,9 +54,11 @@
InputStream in = getClass().getResourceAsStream("keystore.cert");
OutputStream out = new FileOutputStream(file);
int b;
+
while ((b = in.read()) != -1) {
out.write(b);
}
+
in.close();
out.close();
@@ -68,5 +72,4 @@
ks.getCertificate("bogus");
ks.getKey("bogus", "boguspw".toCharArray());
}
-
}
diff --git a/core/src/test/java/org/apache/mina/filter/stream/AbstractStreamWriteFilterTest.java b/core/src/test/java/org/apache/mina/filter/stream/AbstractStreamWriteFilterTest.java
index 776af91..ec54f3c 100644
--- a/core/src/test/java/org/apache/mina/filter/stream/AbstractStreamWriteFilterTest.java
+++ b/core/src/test/java/org/apache/mina/filter/stream/AbstractStreamWriteFilterTest.java
@@ -19,6 +19,11 @@
*/
package org.apache.mina.filter.stream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.MessageDigest;
@@ -28,9 +33,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import junit.framework.TestCase;
-import junit.framework.Assert;
-
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
import org.apache.mina.core.future.IoFutureListener;
@@ -46,13 +48,14 @@
import org.apache.mina.util.AvailablePortFinder;
import org.easymock.IArgumentMatcher;
import org.easymock.classextension.EasyMock;
+import org.junit.Test;
/**
* TODO Add documentation
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public abstract class AbstractStreamWriteFilterTest<M, U extends AbstractStreamWriteFilter<M>> extends TestCase {
+public abstract class AbstractStreamWriteFilterTest<M, U extends AbstractStreamWriteFilter<M>> {
protected final IoSession session = new DummySession();
@@ -60,6 +63,7 @@
abstract protected M createMessage(byte[] data) throws Exception;
+ @Test
public void testWriteEmptyFile() throws Exception {
AbstractStreamWriteFilter<M> filter = createFilter();
M message = createMessage(new byte[0]);
@@ -94,6 +98,7 @@
*
* @throws Exception when something goes wrong
*/
+ @Test
public void testWriteNonFileRegionMessage() throws Exception {
AbstractStreamWriteFilter<M> filter = createFilter();
@@ -127,6 +132,7 @@
*
* @throws Exception when something goes wrong
*/
+ @Test
public void testWriteSingleBufferFile() throws Exception {
byte[] data = new byte[] { 1, 2, 3, 4 };
@@ -165,6 +171,7 @@
*
* @throws Exception when something goes wrong
*/
+ @Test
public void testWriteSeveralBuffersStream() throws Exception {
AbstractStreamWriteFilter<M> filter = createFilter();
filter.setWriteBufferSize(4);
@@ -212,6 +219,7 @@
assertTrue(writeRequest.getFuture().isWritten());
}
+ @Test
public void testWriteWhileWriteInProgress() throws Exception {
AbstractStreamWriteFilter<M> filter = createFilter();
M message = createMessage(new byte[5]);
@@ -245,6 +253,7 @@
session.removeAttribute(filter.WRITE_REQUEST_QUEUE);
}
+ @Test
public void testWritesWriteRequestQueueWhenFinished() throws Exception {
AbstractStreamWriteFilter<M> filter = createFilter();
M message = createMessage(new byte[0]);
@@ -294,6 +303,7 @@
* Tests that {@link StreamWriteFilter#setWriteBufferSize(int)} checks the
* specified size.
*/
+ @Test
public void testSetWriteBufferSize() {
AbstractStreamWriteFilter<M> filter = createFilter();
@@ -303,7 +313,7 @@
} catch (IllegalArgumentException iae) {
// Pass, exception was thrown
// Signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
try {
@@ -312,7 +322,7 @@
} catch (IllegalArgumentException iae) {
// Pass, exception was thrown
// Signifies a successful test execution
- Assert.assertTrue(true);
+ assertTrue(true);
}
filter.setWriteBufferSize(1);
@@ -321,6 +331,7 @@
assertEquals(1024, filter.getWriteBufferSize());
}
+ @Test
public void testWriteUsingSocketTransport() throws Exception {
NioSocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.setReuseAddress(true);
diff --git a/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java b/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java
index 28ace6e..d0a5eaa 100644
--- a/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java
+++ b/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java
@@ -19,11 +19,11 @@
*/
package org.apache.mina.filter.util;
+import static org.junit.Assert.assertEquals;
+
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.mina.core.filterchain.IoFilter;
import org.apache.mina.core.filterchain.IoFilterEvent;
import org.apache.mina.core.session.DummySession;
@@ -33,6 +33,8 @@
import org.apache.mina.core.write.DefaultWriteRequest;
import org.apache.mina.core.write.WriteRequest;
import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests {@link CommonEventFilter}.
@@ -40,14 +42,13 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class WrappingFilterTest extends TestCase {
+public class WrappingFilterTest {
private IoSession session;
private IoFilter.NextFilter nextFilter;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
/*
* Create the mocks.
*/
@@ -56,6 +57,7 @@
//nextFilter = (IoFilter.NextFilter) mockNextFilter.getClass();
}
+ @Test
public void testFilter() throws Exception {
MyWrappingFilter wrappingFilter = new MyWrappingFilter();
diff --git a/core/src/test/java/org/apache/mina/util/CircularQueueTest.java b/core/src/test/java/org/apache/mina/util/CircularQueueTest.java
index 032bb8d..043cb04 100644
--- a/core/src/test/java/org/apache/mina/util/CircularQueueTest.java
+++ b/core/src/test/java/org/apache/mina/util/CircularQueueTest.java
@@ -19,29 +19,37 @@
*/
package org.apache.mina.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.Iterator;
+import org.junit.Before;
+import org.junit.Test;
+
/**
* Tests {@link org.apache.mina.util.CircularQueue}
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class CircularQueueTest extends TestCase {
+public class CircularQueueTest {
private volatile int pushCount;
private volatile int popCount;
+ @Before
public void setUp() {
pushCount = 0;
popCount = 0;
}
+ @Test
public void testRotation() {
CircularQueue<Integer> q = new CircularQueue<Integer>(); // DEFAULT_CAPACITY = 4
testRotation0(q);
}
+ @Test
public void testExpandingRotation() {
CircularQueue<Integer> q = new CircularQueue<Integer>(); // DEFAULT_CAPACITY = 4
for (int i = 0; i < 10; i++) {
@@ -65,6 +73,7 @@
}
}
+ @Test
public void testRandomAddOnQueue() {
CircularQueue<Integer> q = new CircularQueue<Integer>();
// Create a queue with 5 elements and capacity 8;
@@ -96,6 +105,7 @@
}
}
+ @Test
public void testRandomAddOnRotatedQueue() {
CircularQueue<Integer> q = getRotatedQueue();
@@ -130,6 +140,7 @@
}
}
+ @Test
public void testRandomRemoveOnQueue() {
CircularQueue<Integer> q = new CircularQueue<Integer>();
@@ -156,6 +167,7 @@
}
}
+ @Test
public void testRandomRemoveOnRotatedQueue() {
CircularQueue<Integer> q = getRotatedQueue();
@@ -180,6 +192,7 @@
}
}
+ @Test
public void testExpandAndShrink() throws Exception {
CircularQueue<Integer> q = new CircularQueue<Integer>();
for (int i = 0; i < 1024; i ++) {
@@ -224,8 +237,4 @@
return q;
}
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(CircularQueueTest.class);
- }
}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/mina/util/ExpiringMapTest.java b/core/src/test/java/org/apache/mina/util/ExpiringMapTest.java
index 004ca34..867586f 100644
--- a/core/src/test/java/org/apache/mina/util/ExpiringMapTest.java
+++ b/core/src/test/java/org/apache/mina/util/ExpiringMapTest.java
@@ -21,9 +21,10 @@
package org.apache.mina.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertNull;
import org.junit.Before;
+import org.junit.Test;
/**
* Simple test that checks to see if the {@link ExpiringMap} can
@@ -31,7 +32,7 @@
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class ExpiringMapTest extends TestCase
+public class ExpiringMapTest
{
private ExpiringMap<String,String> theMap;
@@ -55,6 +56,7 @@
* Check to see if the map has been cleaned up.
*
*/
+ @Test
public void testGet(){
assertNull( theMap.get( "Apache" ) );
}
diff --git a/core/src/test/java/org/apache/mina/util/byteaccess/ByteAccessTest.java b/core/src/test/java/org/apache/mina/util/byteaccess/ByteAccessTest.java
index 755d0d2..2ab5b78 100644
--- a/core/src/test/java/org/apache/mina/util/byteaccess/ByteAccessTest.java
+++ b/core/src/test/java/org/apache/mina/util/byteaccess/ByteAccessTest.java
@@ -20,26 +20,26 @@
package org.apache.mina.util.byteaccess;
import static org.easymock.EasyMock.createStrictControl;
+import static org.junit.Assert.assertEquals;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.util.byteaccess.ByteArray.Cursor;
import org.apache.mina.util.byteaccess.CompositeByteArray.CursorListener;
import org.apache.mina.util.byteaccess.CompositeByteArrayRelativeWriter.ChunkedExpander;
import org.apache.mina.util.byteaccess.CompositeByteArrayRelativeWriter.Flusher;
import org.easymock.IMocksControl;
+import org.junit.Test;
/**
* Tests classes in the <code>byteaccess</code> package.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class ByteAccessTest extends TestCase {
+public class ByteAccessTest {
private List<String> operations = new ArrayList<String>();
@@ -55,6 +55,7 @@
operations.add(description);
}
+ @Test
public void testBufferByteArray() throws Exception {
ByteArray ba = getByteArrayFactory().create(1000);
testAbsoluteReaderAndWriter(0, 1000, ba, ba);
@@ -64,6 +65,7 @@
testRelativeReaderAndWriter(1000, readCursor, writeCursor);
}
+ @Test
public void testCompositeAddAndRemove() throws Exception {
CompositeByteArray cba = new CompositeByteArray();
assertEquals(0, cba.first());
@@ -120,6 +122,7 @@
return string;
}
+ @Test
public void testCompositeStringJoin() throws Exception {
ByteArray ba1 = wrapString("Hello");
ByteArray ba2 = wrapString("MINA");
@@ -133,6 +136,7 @@
assertEquals("HelloMINAWorld", toString(cba));
}
+ @Test
public void testCompositeCursor() throws Exception {
IMocksControl mc = createStrictControl();
@@ -206,6 +210,7 @@
mc.verify();
}
+ @Test
public void testCompositeByteArray() throws Exception {
CompositeByteArray ba = new CompositeByteArray();
for (int i = 0; i < 1000; i += 100) {
@@ -221,6 +226,7 @@
assertOperationCountEquals(0);
}
+ @Test
public void testCompositeByteArrayRelativeReaderAndWriter() throws Exception {
CompositeByteArray cba = new CompositeByteArray();
CompositeByteArrayRelativeReader cbarr = new CompositeByteArrayRelativeReader(cba, true);
@@ -242,6 +248,7 @@
assertOperationCountEquals(0); // Last free doesn't occur, since cursor only moves lazily.
}
+ @Test
public void testCompositeByteArrayRelativeReaderAndWriterWithFlush() throws Exception {
CompositeByteArray cba = new CompositeByteArray();
CompositeByteArrayRelativeReader cbarr = new CompositeByteArrayRelativeReader(cba, true);
@@ -263,6 +270,7 @@
assertOperationCountEquals(0); // Last free doesn't occur, since cursor only moves lazily.
}
+ @Test
public void testCompositeRemoveTo() throws Exception {
CompositeByteArray cba = new CompositeByteArray();
{
@@ -357,6 +365,7 @@
}
}
+ @Test
public void testCompositeByteArraySlicing() {
CompositeByteArray cba = new CompositeByteArray();
cba.addLast(getByteArrayFactory().create(10));
@@ -369,6 +378,7 @@
testByteArraySlicing(cba, 19, 2);
}
+ @Test
public void testBufferByteArraySlicing() {
ByteArray bba = getByteArrayFactory().create(30);
testByteArraySlicing(bba, 0, 30);
@@ -456,6 +466,7 @@
}
}
+ @Test
public void testByteArrayPrimitiveAccess() {
ByteArray bbaBig = getByteArrayFactory().create(1000);
bbaBig.order(ByteOrder.BIG_ENDIAN);
@@ -466,6 +477,7 @@
testPrimitiveAccess(bbaLittle.cursor(), bbaLittle.cursor());
}
+ @Test
public void testByteArrayBufferAccess() {
ByteArray ba = getByteArrayFactory().create(1);
ba.put(0, (byte) 99);
@@ -484,6 +496,7 @@
assertEquals(1, bb.remaining());
}
+ @Test
public void testCompositeByteArrayPrimitiveAccess() {
CompositeByteArray cbaBig = new CompositeByteArray();
cbaBig.order(ByteOrder.BIG_ENDIAN);
@@ -504,6 +517,7 @@
testPrimitiveAccess(cbaLittle.cursor(), cbaLittle.cursor());
}
+ @Test
public void testCompositeByteArrayWrapperPrimitiveAccess() {
CompositeByteArray cbaBig = new CompositeByteArray();
cbaBig.order(ByteOrder.BIG_ENDIAN);
@@ -543,11 +557,11 @@
float f = Float.intBitsToFloat(i);
write.putFloat(f);
- assertEquals(f, read.getFloat());
+ assertEquals(f, read.getFloat(), 0);
double d = Double.longBitsToDouble(l);
write.putDouble(d);
- assertEquals(d, read.getDouble());
+ assertEquals(d, read.getDouble(), 0);
char c = (char) 0x1234;
write.putChar(c);