JAMES-2543 convert junit 3 tests to junit 4
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e4a2289f Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e4a2289f Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e4a2289f Branch: refs/heads/master Commit: e4a2289f9f57a966ced762cfb926a18f5f420d71 Parents: a8d9795 Author: Matthieu Baechler <[email protected]> Authored: Thu Sep 6 17:52:59 2018 +0200 Committer: Matthieu Baechler <[email protected]> Committed: Mon Sep 10 21:25:25 2018 +0200 ---------------------------------------------------------------------- .../org/apache/james/mpt/ant/TestAddUser.java | 21 ++++++------- .../apache/james/mpt/ant/TestRunScripts.java | 31 +++++++++++--------- .../apache/james/mpt/TestDiscardProtocol.java | 31 ++++++++++++-------- .../apache/james/mpt/TestScriptedUserAdder.java | 21 ++++++------- .../pop3/core/AbstractInputStreamTest.java | 9 +++--- .../core/CRLFTerminatedInputStreamTest.java | 5 ++++ .../pop3/core/ExtraDotInputStreamTest.java | 15 ++++++---- 7 files changed, 75 insertions(+), 58 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java ---------------------------------------------------------------------- diff --git a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java index aabc2e1..dd54b3b 100644 --- a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java +++ b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java @@ -22,10 +22,12 @@ package org.apache.james.mpt.ant; import org.apache.james.mpt.DiscardProtocol; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.resources.Union; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestAddUser extends TestCase { +public class TestAddUser { DiscardProtocol fakeServer; @@ -33,9 +35,8 @@ public class TestAddUser extends TestCase { MailProtocolTestTask subject; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fakeServer = new DiscardProtocol(); fakeServer.start(); record = fakeServer.recordNext(); @@ -47,12 +48,12 @@ public class TestAddUser extends TestCase { subject.setProject(new Project()); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { fakeServer.stop(); } + @Test public void testShouldExecuteScriptAgainstPort() throws Exception { MailProtocolTestTask.AddUser user = subject.createAddUser(); user.setPort(fakeServer.getPort().getValue()); @@ -61,6 +62,6 @@ public class TestAddUser extends TestCase { final String script = "This script adds a user"; user.addText("C: " + script); subject.execute(); - assertEquals(script + "\r\n", record.complete()); + Assert.assertEquals(script + "\r\n", record.complete()); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java ---------------------------------------------------------------------- diff --git a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java index 9472f1d..c589c42 100644 --- a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java +++ b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java @@ -28,10 +28,12 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.resources.StringResource; import org.apache.tools.ant.types.resources.Union; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestRunScripts extends TestCase { +public class TestRunScripts { private static final String SCRIPT = "A script"; @@ -43,9 +45,8 @@ public class TestRunScripts extends TestCase { MailProtocolTestTask subject; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fakeServer = new DiscardProtocol(); fakeServer.start(); record = fakeServer.recordNext(); @@ -60,12 +61,12 @@ public class TestRunScripts extends TestCase { subject.setProject(new Project()); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { fakeServer.stop(); } + @Test public void testIgnoreUnsupportedResource() throws Exception { final Resource unsupportedResource = new StringResource() { @Override @@ -76,15 +77,17 @@ public class TestRunScripts extends TestCase { stubResourceCollection.add(unsupportedResource); subject.add(stubResourceCollection); subject.execute(); - assertEquals(SCRIPT + "\r\n", record.complete()); + Assert.assertEquals(SCRIPT + "\r\n", record.complete()); } - + + @Test public void testRunOneScriptFromCollection() throws Exception { subject.add(stubResourceCollection); subject.execute(); - assertEquals(SCRIPT + "\r\n", record.complete()); + Assert.assertEquals(SCRIPT + "\r\n", record.complete()); } - + + @Test public void testRunOneScriptFromAttribute() throws Exception { final File file = File.createTempFile("Test", "mpt"); file.deleteOnExit(); @@ -93,6 +96,6 @@ public class TestRunScripts extends TestCase { writer.close(); subject.setScript(file); subject.execute(); - assertEquals(SCRIPT + "\r\n", record.complete()); + Assert.assertEquals(SCRIPT + "\r\n", record.complete()); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java ---------------------------------------------------------------------- diff --git a/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java b/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java index bc30917..9c18f36 100644 --- a/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java +++ b/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java @@ -19,6 +19,8 @@ package org.apache.james.mpt; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; @@ -26,9 +28,12 @@ import java.net.Socket; import javax.net.SocketFactory; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; -public class TestDiscardProtocol extends TestCase { +public class TestDiscardProtocol { private final class InputLater implements Runnable { private Exception e; @@ -58,26 +63,25 @@ public class TestDiscardProtocol extends TestCase { private DiscardProtocol.Record record; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { protocol = new DiscardProtocol(); protocol.start(); socket = SocketFactory.getDefault().createSocket("127.0.0.1", protocol.getPort().getValue()); record = protocol.recordNext(); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { protocol.stop(); - super.tearDown(); } - + + @Test public void testRecord() throws Exception { - assertTrue(socket.isConnected()); + assertThat(socket.isConnected()).isTrue(); input(); String output = record.complete(); - assertEquals(INPUT, output); + Assert.assertEquals(INPUT, output); } private void input() throws IOException { @@ -86,13 +90,14 @@ public class TestDiscardProtocol extends TestCase { out.close(); socket.close(); } - + + @Test public void testComplete() throws Exception { InputLater inputLater = new InputLater(); Thread thread = new Thread(inputLater); thread.start(); String output = record.complete(); - assertEquals(INPUT, output); + Assert.assertEquals(INPUT, output); inputLater.assertExecutedSuccessfully(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java ---------------------------------------------------------------------- diff --git a/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java b/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java index b3d461d..596322f 100644 --- a/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java +++ b/mpt/core/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java @@ -20,32 +20,33 @@ package org.apache.james.mpt; import org.apache.james.mpt.user.ScriptedUserAdder; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestScriptedUserAdder extends TestCase { +public class TestScriptedUserAdder { private DiscardProtocol protocol; private DiscardProtocol.Record record; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { protocol = new DiscardProtocol(); protocol.start(); record = protocol.recordNext(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { protocol.stop(); } + @Test public void testShouldExecuteScriptAgainstPort() throws Exception { ScriptedUserAdder adder = new ScriptedUserAdder("localhost", protocol.getPort(), "C: USER='${user}' password='${password}'"); adder.addUser("A User", "Some Password"); - assertEquals("USER='A User' password='Some Password'\r\n", record.complete()); + Assert.assertEquals("USER='A User' password='Some Password'\r\n", record.complete()); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java ---------------------------------------------------------------------- diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java index 38bd76b..bc3153d 100644 --- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java +++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java @@ -22,10 +22,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import junit.framework.TestCase; +import org.junit.Assert; - -public abstract class AbstractInputStreamTest extends TestCase { +public abstract class AbstractInputStreamTest { protected void checkRead(InputStream in, String expected) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -35,7 +34,7 @@ public abstract class AbstractInputStreamTest extends TestCase { } in.close(); out.close(); - assertEquals(expected, new String(out.toByteArray())); + Assert.assertEquals(expected, new String(out.toByteArray())); @@ -53,7 +52,7 @@ public abstract class AbstractInputStreamTest extends TestCase { in.close(); out.close(); - assertEquals(expected, new String(out.toByteArray())); + Assert.assertEquals(expected, new String(out.toByteArray())); } http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java ---------------------------------------------------------------------- diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java index e39bcea..b0ed18f 100644 --- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java +++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java @@ -22,8 +22,11 @@ package org.apache.james.protocols.pop3.core; import java.io.ByteArrayInputStream; import java.io.IOException; +import org.junit.Test; + public class CRLFTerminatedInputStreamTest extends AbstractInputStreamTest { + @Test public void testCRLFPresent() throws IOException { String data = "Subject: test\r\n\r\ndata\r\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data); @@ -31,6 +34,7 @@ public class CRLFTerminatedInputStreamTest extends AbstractInputStreamTest { } + @Test public void testCRPresent() throws IOException { String data = "Subject: test\r\n\r\ndata\r"; String expected = data + "\n"; @@ -38,6 +42,7 @@ public class CRLFTerminatedInputStreamTest extends AbstractInputStreamTest { checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); } + @Test public void testNonPresent() throws IOException { String data = "Subject: test\r\n\r\ndata"; String expected = data + "\r\n"; http://git-wip-us.apache.org/repos/asf/james-project/blob/e4a2289f/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java ---------------------------------------------------------------------- diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java index 9cf428a..199ce24 100644 --- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java +++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java @@ -22,8 +22,11 @@ package org.apache.james.protocols.pop3.core; import java.io.ByteArrayInputStream; import java.io.IOException; +import org.junit.Test; + public class ExtraDotInputStreamTest extends AbstractInputStreamTest { + @Test public void testExtraDot() throws IOException { String data = "This\r\n.\r\nThis.\r\n"; String expectedOutput = "This\r\n..\r\nThis.\r\n"; @@ -33,6 +36,7 @@ public class ExtraDotInputStreamTest extends AbstractInputStreamTest { } + @Test public void testExtraDotOnDoubleDot() throws IOException { String data = "This\r\n..\r\nThis.\r\n"; String expectedOutput = "This\r\n...\r\nThis.\r\n"; @@ -41,8 +45,8 @@ public class ExtraDotInputStreamTest extends AbstractInputStreamTest { checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expectedOutput); } - + @Test public void testExtraDotOnDotWithText() throws IOException { String data = "This\r\n.TestText\r\nThis.\r\n"; String expected = "This\r\n..TestText\r\nThis.\r\n"; @@ -51,13 +55,15 @@ public class ExtraDotInputStreamTest extends AbstractInputStreamTest { checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expected); } - + + @Test public void testNoDotCLRF() throws IOException { String data = "ABCD\r\n"; checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data); checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data); } + @Test public void testNoDot() throws IOException { String data = "ABCD"; checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data); @@ -65,14 +71,11 @@ public class ExtraDotInputStreamTest extends AbstractInputStreamTest { } // Proof of BUG JAMES-1152 + @Test public void testNoDotHeaderBody() throws IOException { String data = "Subject: test\r\n\r\nABCD\r\n"; checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data); checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data); - } - - - } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
