Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java (original) +++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java Thu Dec 27 13:23:54 2012 @@ -19,12 +19,6 @@ package org.apache.james.mime4j.message; -import java.io.ByteArrayInputStream; -import java.text.SimpleDateFormat; -import java.util.TimeZone; - -import junit.framework.TestCase; - import org.apache.james.mime4j.ExampleMail; import org.apache.james.mime4j.stream.BodyDescriptor; import org.apache.james.mime4j.stream.BodyDescriptorBuilder; @@ -32,19 +26,29 @@ import org.apache.james.mime4j.stream.En import org.apache.james.mime4j.stream.MimeConfig; import org.apache.james.mime4j.stream.MimeTokenStream; import org.apache.james.mime4j.stream.RawField; +import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.text.SimpleDateFormat; +import java.util.TimeZone; -public class MaximalBodyDescriptorTest extends TestCase { +public class MaximalBodyDescriptorTest { MimeTokenStream parser; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { MimeConfig config = new MimeConfig(); config.setStrictParsing(true); parser = new MimeTokenStream(config, new DefaultBodyDescriptorBuilder(null)); } + @Test public void testAddField() throws Exception { /* * Make sure that only the first Content-Type header added is used. @@ -52,34 +56,35 @@ public class MaximalBodyDescriptorTest e BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder(); builder.addField(new RawField("Content-Type ", "text/plain; charset=ISO-8859-1")); BodyDescriptor bd = builder.build(); - assertEquals("text/plain", bd.getMimeType()); - assertEquals("ISO-8859-1", bd.getCharset()); + Assert.assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("ISO-8859-1", bd.getCharset()); builder.addField(new RawField("Content-Type ", "text/html; charset=us-ascii")); bd = builder.build(); - assertEquals("text/plain", bd.getMimeType()); - assertEquals("ISO-8859-1", bd.getCharset()); + Assert.assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("ISO-8859-1", bd.getCharset()); } + @Test public void testGetMimeType() throws Exception { BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder(); builder.addField(new RawField("Content-Type ", "text/PLAIN")); BodyDescriptor bd = builder.build(); - assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("text/plain", bd.getMimeType()); builder.reset(); builder.addField(new RawField("content-type", " TeXt / html ")); bd = builder.build(); - assertEquals("text/html", bd.getMimeType()); + Assert.assertEquals("text/html", bd.getMimeType()); builder.reset(); builder.addField(new RawField("CONTENT-TYPE", " x-app/yada ; param = yada")); bd = builder.build(); - assertEquals("x-app/yada", bd.getMimeType()); + Assert.assertEquals("x-app/yada", bd.getMimeType()); builder.reset(); builder.addField(new RawField("CONTENT-TYPE", " yada")); bd = builder.build(); - assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("text/plain", bd.getMimeType()); /* * Make sure that only the first Content-Type header added is used. @@ -87,10 +92,10 @@ public class MaximalBodyDescriptorTest e builder.reset(); builder.addField(new RawField("Content-Type ", "text/plain")); bd = builder.build(); - assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("text/plain", bd.getMimeType()); builder.addField(new RawField("Content-Type ", "text/html")); bd = builder.build(); - assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("text/plain", bd.getMimeType()); /* * Implicit mime types. @@ -99,40 +104,41 @@ public class MaximalBodyDescriptorTest e parent.addField(new RawField("Content-Type", "mutlipart/alternative; boundary=foo")); BodyDescriptorBuilder child = parent.newChild(); bd = child.build(); - assertEquals("text/plain", bd.getMimeType()); + Assert.assertEquals("text/plain", bd.getMimeType()); child.addField(new RawField("Content-Type", " child/type")); bd = child.build(); - assertEquals("child/type", bd.getMimeType()); + Assert.assertEquals("child/type", bd.getMimeType()); parent.reset(); parent.addField(new RawField("Content-Type", "multipart/digest; boundary=foo")); child = parent.newChild(); bd = child.build(); - assertEquals("message/rfc822", bd.getMimeType()); + Assert.assertEquals("message/rfc822", bd.getMimeType()); child.addField(new RawField("Content-Type", " child/type")); bd = child.build(); - assertEquals("child/type", bd.getMimeType()); + Assert.assertEquals("child/type", bd.getMimeType()); } + @Test public void testParameters() throws Exception { BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder(); /* * Test charset. */ BodyDescriptor bd = builder.build(); - assertEquals("us-ascii", bd.getCharset()); + Assert.assertEquals("us-ascii", bd.getCharset()); builder.addField(new RawField("Content-Type ", "text/type; charset=ISO-8859-1")); bd = builder.build(); - assertEquals("ISO-8859-1", bd.getCharset()); + Assert.assertEquals("ISO-8859-1", bd.getCharset()); builder.reset(); bd = builder.build(); - assertEquals("us-ascii", bd.getCharset()); + Assert.assertEquals("us-ascii", bd.getCharset()); builder.addField(new RawField("Content-Type ", "text/type")); bd = builder.build(); - assertEquals("us-ascii", bd.getCharset()); + Assert.assertEquals("us-ascii", bd.getCharset()); /* * Test boundary. @@ -140,160 +146,178 @@ public class MaximalBodyDescriptorTest e builder.reset(); builder.addField(new RawField("Content-Type", "text/html; boundary=yada yada")); bd = builder.build(); - assertNull(bd.getBoundary()); + Assert.assertNull(bd.getBoundary()); builder.reset(); builder.addField(new RawField("Content-Type", "multipart/yada; boundary=yada")); bd = builder.build(); - assertEquals("yada", bd.getBoundary()); + Assert.assertEquals("yada", bd.getBoundary()); builder.reset(); builder.addField(new RawField("Content-Type", "multipart/yada; boUNdarY= \"ya \\\"\\\"\tda \\\"\"; " - + "\tcharset\t = \"\\\"hepp\\\" =us\t-ascii\"")); + + "\tcharset\t = \"\\\"hepp\\\" =us\t-ascii\"")); bd = builder.build(); - assertEquals("ya \"\"\tda \"", bd.getBoundary()); - assertEquals("\"hepp\" =us\t-ascii", bd.getCharset()); + Assert.assertEquals("ya \"\"\tda \"", bd.getBoundary()); + Assert.assertEquals("\"hepp\" =us\t-ascii", bd.getCharset()); } + @Test public void testGetContentLength() throws Exception { BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder(); BodyDescriptor bd = builder.build(); - assertEquals(-1, bd.getContentLength()); + Assert.assertEquals(-1, bd.getContentLength()); builder.addField(new RawField("Content-Length", "9901")); bd = builder.build(); - assertEquals(9901, bd.getContentLength()); + Assert.assertEquals(9901, bd.getContentLength()); // only the first content-length counts builder.addField(new RawField("Content-Length", "1239901")); bd = builder.build(); - assertEquals(9901, bd.getContentLength()); + Assert.assertEquals(9901, bd.getContentLength()); } + @Test public void testDoDefaultToUsAsciiWhenUntyped() throws Exception { BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder(); builder.addField(new RawField("To", "[email protected]")); BodyDescriptor bd = builder.build(); - assertEquals("us-ascii", bd.getCharset()); + Assert.assertEquals("us-ascii", bd.getCharset()); } + @Test public void testDoNotDefaultToUsAsciiForNonTextTypes() throws Exception { BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder(); builder.addField(new RawField("Content-Type", "image/png; name=blob.png")); BodyDescriptor bd = builder.build(); - assertNull(bd.getCharset()); + Assert.assertNull(bd.getCharset()); } + @Test public void testMimeVersionDefault() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.RFC822_SIMPLE_BYTES); - assertEquals(1, descriptor.getMimeMajorVersion()); - assertEquals(0, descriptor.getMimeMinorVersion()); + Assert.assertEquals(1, descriptor.getMimeMajorVersion()); + Assert.assertEquals(0, descriptor.getMimeMinorVersion()); } + @Test public void testMimeVersion() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_ASCII_COMMENT_IN_MIME_VERSION_BYTES); - assertEquals(2, descriptor.getMimeMajorVersion()); - assertEquals(4, descriptor.getMimeMinorVersion()); + Assert.assertEquals(2, descriptor.getMimeMajorVersion()); + Assert.assertEquals(4, descriptor.getMimeMinorVersion()); } + @Test public void testContentId() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_8859_BYTES); - assertEquals(1, descriptor.getMimeMajorVersion()); - assertEquals(0, descriptor.getMimeMinorVersion()); - assertEquals(ExampleMail.CONTENT_ID, descriptor.getContentId()); + Assert.assertEquals(1, descriptor.getMimeMajorVersion()); + Assert.assertEquals(0, descriptor.getMimeMinorVersion()); + Assert.assertEquals(ExampleMail.CONTENT_ID, descriptor.getContentId()); } + @Test public void testContentDescription() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_8859_BYTES); - assertEquals(1, descriptor.getMimeMajorVersion()); - assertEquals(0, descriptor.getMimeMinorVersion()); - assertEquals(ExampleMail.CONTENT_DESCRIPTION, descriptor.getContentDescription()); + Assert.assertEquals(1, descriptor.getMimeMajorVersion()); + Assert.assertEquals(0, descriptor.getMimeMinorVersion()); + Assert.assertEquals(ExampleMail.CONTENT_DESCRIPTION, descriptor.getContentDescription()); } + @Test public void testMimeVersionHeaderBreak() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES_BYTES); - assertEquals(4, descriptor.getMimeMajorVersion()); - assertEquals(1, descriptor.getMimeMinorVersion()); + Assert.assertEquals(4, descriptor.getMimeMajorVersion()); + Assert.assertEquals(1, descriptor.getMimeMinorVersion()); } + @Test public void testContentDispositionType() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_BASE64_LATIN1_BYTES); - assertEquals("inline", descriptor.getContentDispositionType()); + Assert.assertEquals("inline", descriptor.getContentDispositionType()); } + @Test public void testContentDispositionTypeCaseConversion() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_BASE64_LATIN1_BYTES); - assertEquals("Should be converted to lower case", "inline", descriptor.getContentDispositionType()); - assertNotNull(descriptor.getContentDispositionParameters()); - assertEquals(0, descriptor.getContentDispositionParameters().size()); + Assert.assertEquals("Should be converted to lower case", "inline", descriptor.getContentDispositionType()); + Assert.assertNotNull(descriptor.getContentDispositionParameters()); + Assert.assertEquals(0, descriptor.getContentDispositionParameters().size()); } + @Test public void testContentDispositionParameters() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS_BYTES); - assertEquals("inline", descriptor.getContentDispositionType()); - assertNotNull(descriptor.getContentDispositionParameters()); - assertEquals(3, descriptor.getContentDispositionParameters().size()); - assertEquals("value", descriptor.getContentDispositionParameters().get("param")); - assertEquals("1", descriptor.getContentDispositionParameters().get("one")); - assertEquals("bar", descriptor.getContentDispositionParameters().get("foo")); + Assert.assertEquals("inline", descriptor.getContentDispositionType()); + Assert.assertNotNull(descriptor.getContentDispositionParameters()); + Assert.assertEquals(3, descriptor.getContentDispositionParameters().size()); + Assert.assertEquals("value", descriptor.getContentDispositionParameters().get("param")); + Assert.assertEquals("1", descriptor.getContentDispositionParameters().get("one")); + Assert.assertEquals("bar", descriptor.getContentDispositionParameters().get("foo")); } + @Test public void testContentDispositionStandardParameters() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, 1); - assertEquals("attachment", descriptor.getContentDispositionType()); - assertNotNull(descriptor.getContentDispositionParameters()); - assertEquals(5, descriptor.getContentDispositionParameters().size()); - assertEquals("blob.png", descriptor.getContentDispositionFilename()); + Assert.assertEquals("attachment", descriptor.getContentDispositionType()); + Assert.assertNotNull(descriptor.getContentDispositionParameters()); + Assert.assertEquals(5, descriptor.getContentDispositionParameters().size()); + Assert.assertEquals("blob.png", descriptor.getContentDispositionFilename()); SimpleDateFormat dateparser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateparser.setTimeZone(TimeZone.getTimeZone("GMT")); - assertEquals(dateparser.parse("2008-06-21 15:32:18"), descriptor.getContentDispositionModificationDate()); - assertEquals(dateparser.parse("2008-06-20 10:15:09"), descriptor.getContentDispositionCreationDate()); - assertEquals(dateparser.parse("2008-06-22 12:08:56"), descriptor.getContentDispositionReadDate()); - assertEquals(10234, descriptor.getContentDispositionSize()); + Assert.assertEquals(dateparser.parse("2008-06-21 15:32:18"), descriptor.getContentDispositionModificationDate()); + Assert.assertEquals(dateparser.parse("2008-06-20 10:15:09"), descriptor.getContentDispositionCreationDate()); + Assert.assertEquals(dateparser.parse("2008-06-22 12:08:56"), descriptor.getContentDispositionReadDate()); + Assert.assertEquals(10234, descriptor.getContentDispositionSize()); } + @Test public void testLanguageParameters() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, 3); - assertNotNull(descriptor.getContentLanguage()); - assertEquals(3, descriptor.getContentLanguage().size()); - assertEquals("en", descriptor.getContentLanguage().get(0)); - assertEquals("en-US", descriptor.getContentLanguage().get(1)); - assertEquals("en-CA", descriptor.getContentLanguage().get(2)); + Assert.assertNotNull(descriptor.getContentLanguage()); + Assert.assertEquals(3, descriptor.getContentLanguage().size()); + Assert.assertEquals("en", descriptor.getContentLanguage().get(0)); + Assert.assertEquals("en-US", descriptor.getContentLanguage().get(1)); + Assert.assertEquals("en-CA", descriptor.getContentLanguage().get(2)); } + @Test public void testContentLocationRelativeUrl() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 0); - assertEquals("relative/url", descriptor.getContentLocation()); + Assert.assertEquals("relative/url", descriptor.getContentLocation()); } + @Test public void testContentLocationAbsoluteUrl() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 1); - assertEquals("http://www.example.org/absolute/rhubard.txt", descriptor.getContentLocation()); + Assert.assertEquals("http://www.example.org/absolute/rhubard.txt", descriptor.getContentLocation()); } + @Test public void testContentLocationWithComment() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 3); - assertEquals("http://www.example.org/absolute/comments/rhubard.txt", descriptor.getContentLocation()); + Assert.assertEquals("http://www.example.org/absolute/comments/rhubard.txt", descriptor.getContentLocation()); } + @Test public void testContentLocationFoldedUrl() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 4); - assertEquals("http://www.example.org/this/is/a/very/long/url/split/over/two/lines/", descriptor.getContentLocation()); + Assert.assertEquals("http://www.example.org/this/is/a/very/long/url/split/over/two/lines/", descriptor.getContentLocation()); } + @Test public void testContentMD5Url() throws Exception { MaximalBodyDescriptor descriptor = describe(ExampleMail.ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS_BYTES); - assertEquals(ExampleMail.MD5_CONTENT, descriptor.getContentMD5Raw()); + Assert.assertEquals(ExampleMail.MD5_CONTENT, descriptor.getContentMD5Raw()); } private MaximalBodyDescriptor describe(byte[] mail, int zeroBasedPart) throws Exception { ByteArrayInputStream bias = new ByteArrayInputStream(mail); parser.parse(bias); EntityState state = parser.next(); - while (state != EntityState.T_END_OF_STREAM && zeroBasedPart>=0) { + while (state != EntityState.T_END_OF_STREAM && zeroBasedPart >= 0) { state = parser.next(); if (state == EntityState.T_BODY) { --zeroBasedPart; @@ -310,8 +334,7 @@ public class MaximalBodyDescriptorTest e ByteArrayInputStream bias = new ByteArrayInputStream(mail); parser.parse(bias); EntityState state = parser.next(); - while (state != EntityState.T_BODY && state != EntityState.T_END_OF_STREAM) - { + while (state != EntityState.T_BODY && state != EntityState.T_END_OF_STREAM) { state = parser.next(); } assertEquals(EntityState.T_BODY, state);
Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java (original) +++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java Thu Dec 27 13:23:54 2012 @@ -19,24 +19,26 @@ package org.apache.james.mime4j.message; +import org.apache.james.mime4j.util.CharsetUtil; +import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + import java.io.IOException; import java.io.InputStream; import java.security.SecureRandom; -import org.apache.james.mime4j.util.CharsetUtil; - -import junit.framework.TestCase; - -public class StringInputStreamTest extends TestCase { +public class StringInputStreamTest { private static final String SWISS_GERMAN_HELLO = "Gr\374ezi_z\344m\344"; private static final String RUSSIAN_HELLO = "\u0412\u0441\u0435\u043C_\u043F\u0440\u0438\u0432\u0435\u0442"; - private static final String TEST_STRING = "Hello and stuff " + SWISS_GERMAN_HELLO + " " + RUSSIAN_HELLO; + private static final String TEST_STRING = "Hello and stuff " + SWISS_GERMAN_HELLO + " " + RUSSIAN_HELLO; private static final String LARGE_TEST_STRING; static { StringBuilder buffer = new StringBuilder(); - for (int i=0; i<100; i++) { + for (int i = 0; i < 100; i++) { buffer.append(TEST_STRING); } LARGE_TEST_STRING = buffer.toString(); @@ -49,7 +51,7 @@ public class StringInputStreamTest exten int read = in.read(); assertTrue(read >= 0); assertTrue(read <= 255); - assertEquals(b, (byte)read); + assertEquals(b, (byte) read); } assertEquals(-1, in.read()); } @@ -80,48 +82,55 @@ public class StringInputStreamTest exten } } + @Test public void testSingleByteRead() throws IOException { singleByteReadTest(TEST_STRING); } + @Test public void testLargeSingleByteRead() throws IOException { singleByteReadTest(LARGE_TEST_STRING); } + @Test public void testBufferedRead() throws IOException { bufferedReadTest(TEST_STRING); } + @Test public void testLargeBufferedRead() throws IOException { bufferedReadTest(LARGE_TEST_STRING); } + @Test public void testReadZero() throws Exception { InputStream r = new StringInputStream("test", CharsetUtil.UTF_8); byte[] bytes = new byte[30]; - assertEquals(0, r.read(bytes, 0, 0)); + Assert.assertEquals(0, r.read(bytes, 0, 0)); } + @Test public void testSkip() throws Exception { InputStream r = new StringInputStream("test", CharsetUtil.UTF_8); r.skip(1); r.skip(2); - assertEquals('t', r.read()); + Assert.assertEquals('t', r.read()); r.skip(100); - assertEquals(-1, r.read()); + Assert.assertEquals(-1, r.read()); } + @Test public void testMarkReset() throws Exception { InputStream r = new StringInputStream("test", CharsetUtil.UTF_8); r.skip(2); r.mark(0); - assertEquals('s', r.read()); - assertEquals('t', r.read()); - assertEquals(-1, r.read()); + Assert.assertEquals('s', r.read()); + Assert.assertEquals('t', r.read()); + Assert.assertEquals(-1, r.read()); r.reset(); - assertEquals('s', r.read()); - assertEquals('t', r.read()); - assertEquals(-1, r.read()); + Assert.assertEquals('s', r.read()); + Assert.assertEquals('t', r.read()); + Assert.assertEquals(-1, r.read()); r.reset(); r.reset(); } Modified: james/mime4j/trunk/pom.xml URL: http://svn.apache.org/viewvc/james/mime4j/trunk/pom.xml?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/pom.xml (original) +++ james/mime4j/trunk/pom.xml Thu Dec 27 13:23:54 2012 @@ -130,6 +130,7 @@ <exclude>**/test/resources/testmsgs/*</exclude> <exclude>**/test/resources/mimetools-testmsgs/*</exclude> <exclude>**/test/resources/test-1/*</exclude> + <exclude>**/test/resources/*.msg</exclude> <!-- Generated by Maven --> <exclude>release.properties</exclude> <exclude>dist/**/*</exclude> Modified: james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/DefaultStorageProviderTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/DefaultStorageProviderTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/DefaultStorageProviderTest.java (original) +++ james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/DefaultStorageProviderTest.java Thu Dec 27 13:23:54 2012 @@ -19,26 +19,30 @@ package org.apache.james.mime4j.storage; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; -public class DefaultStorageProviderTest extends TestCase { +public class DefaultStorageProviderTest { - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { System.getProperties().remove( DefaultStorageProvider.DEFAULT_STORAGE_PROVIDER_PROPERTY); DefaultStorageProvider.reset(); } + @Test public void testDefaultInstance() throws Exception { System.getProperties().remove( DefaultStorageProvider.DEFAULT_STORAGE_PROVIDER_PROPERTY); DefaultStorageProvider.reset(); StorageProvider instance = DefaultStorageProvider.getInstance(); - assertTrue(instance instanceof ThresholdStorageProvider); + Assert.assertTrue(instance instanceof ThresholdStorageProvider); } + @Test public void testSetDefaultProperty() throws Exception { System.setProperty( DefaultStorageProvider.DEFAULT_STORAGE_PROVIDER_PROPERTY, @@ -46,14 +50,15 @@ public class DefaultStorageProviderTest DefaultStorageProvider.reset(); StorageProvider instance = DefaultStorageProvider.getInstance(); - assertTrue(instance instanceof MemoryStorageProvider); + Assert.assertTrue(instance instanceof MemoryStorageProvider); } + @Test public void testSetter() throws Exception { StorageProvider instance = new MemoryStorageProvider(); DefaultStorageProvider.setInstance(instance); - assertSame(instance, DefaultStorageProvider.getInstance()); + Assert.assertSame(instance, DefaultStorageProvider.getInstance()); } } Modified: james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/MultiReferenceStorageTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/MultiReferenceStorageTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/MultiReferenceStorageTest.java (original) +++ james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/MultiReferenceStorageTest.java Thu Dec 27 13:23:54 2012 @@ -19,34 +19,38 @@ package org.apache.james.mime4j.storage; +import org.junit.Assert; +import org.junit.Test; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import junit.framework.TestCase; - -public class MultiReferenceStorageTest extends TestCase { +public class MultiReferenceStorageTest { + @Test public void testForwardsGetInputStream() throws Exception { DummyStorage storage = new DummyStorage(); MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage( storage); - assertEquals(ByteArrayInputStream.class, multiReferenceStorage + Assert.assertEquals(ByteArrayInputStream.class, multiReferenceStorage .getInputStream().getClass()); } + @Test public void testSingleReference() throws Exception { DummyStorage storage = new DummyStorage(); MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage( storage); - assertFalse(storage.deleted); + Assert.assertFalse(storage.deleted); multiReferenceStorage.delete(); - assertTrue(storage.deleted); + Assert.assertTrue(storage.deleted); } + @Test public void testMultiReference() throws Exception { DummyStorage storage = new DummyStorage(); MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage( @@ -55,12 +59,13 @@ public class MultiReferenceStorageTest e multiReferenceStorage.addReference(); multiReferenceStorage.delete(); - assertFalse(storage.deleted); + Assert.assertFalse(storage.deleted); multiReferenceStorage.delete(); - assertTrue(storage.deleted); + Assert.assertTrue(storage.deleted); } + @Test public void testGetInputStreamOnDeleted() throws Exception { DummyStorage storage = new DummyStorage(); MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage( @@ -70,11 +75,12 @@ public class MultiReferenceStorageTest e try { multiReferenceStorage.getInputStream(); - fail(); + Assert.fail(); } catch (IllegalStateException expected) { } } + @Test public void testAddReferenceOnDeleted() throws Exception { DummyStorage storage = new DummyStorage(); MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage( @@ -84,7 +90,7 @@ public class MultiReferenceStorageTest e try { multiReferenceStorage.addReference(); - fail(); + Assert.fail(); } catch (IllegalStateException expected) { } } Modified: james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java (original) +++ james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java Thu Dec 27 13:23:54 2012 @@ -19,17 +19,18 @@ package org.apache.james.mime4j.storage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -import junit.framework.TestCase; - import org.apache.james.mime4j.dom.SingleBody; import org.apache.james.mime4j.message.MessageImpl; import org.apache.james.mime4j.util.CharsetUtil; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; -public class SingleBodyCopyTest extends TestCase { +public class SingleBodyCopyTest { + @Test public void testCopyStorageBinaryBody() throws Exception { Storage storage = new MemoryStorageProvider() .store(new ByteArrayInputStream("test".getBytes())); @@ -39,6 +40,7 @@ public class SingleBodyCopyTest extends copyTest(body); } + @Test public void testCopyStorageTextBody() throws Exception { Storage storage = new MemoryStorageProvider() .store(new ByteArrayInputStream("test".getBytes())); @@ -49,11 +51,13 @@ public class SingleBodyCopyTest extends copyTest(body); } + @Test public void testCopyStringTextBody() throws Exception { SingleBody body = new StringTextBody("test", CharsetUtil.US_ASCII); copyTest(body); } + @Test public void testDisposeStorageBinaryBody() throws Exception { Storage storage = new MemoryStorageProvider() .store(new ByteArrayInputStream("test".getBytes())); @@ -63,6 +67,7 @@ public class SingleBodyCopyTest extends disposeTest(body, storage); } + @Test public void testDisposeStorageTextBody() throws Exception { Storage storage = new MemoryStorageProvider() .store(new ByteArrayInputStream("test".getBytes())); @@ -78,11 +83,11 @@ public class SingleBodyCopyTest extends parent.setBody(body); SingleBody copy = body.copy(); - assertNotNull(copy); - assertNotSame(body, copy); + Assert.assertNotNull(copy); + Assert.assertNotSame(body, copy); - assertSame(parent, body.getParent()); - assertNull(copy.getParent()); + Assert.assertSame(parent, body.getParent()); + Assert.assertNull(copy.getParent()); sameContentTest(body, copy); } @@ -97,23 +102,23 @@ public class SingleBodyCopyTest extends actualBody.writeTo(actBaos); byte[] actual = actBaos.toByteArray(); - assertEquals(expected.length, actual.length); + Assert.assertEquals(expected.length, actual.length); for (int i = 0; i < expected.length; i++) { - assertEquals(expected[i], actual[i]); + Assert.assertEquals(expected[i], actual[i]); } } private void disposeTest(SingleBody body, Storage storage) throws Exception { - assertTrue(storageIsReadable(storage)); + Assert.assertTrue(storageIsReadable(storage)); SingleBody copy = body.copy(); - assertTrue(storageIsReadable(storage)); + Assert.assertTrue(storageIsReadable(storage)); body.dispose(); - assertTrue(storageIsReadable(storage)); + Assert.assertTrue(storageIsReadable(storage)); copy.dispose(); - assertFalse(storageIsReadable(storage)); + Assert.assertFalse(storageIsReadable(storage)); } private boolean storageIsReadable(Storage storage) throws Exception { Modified: james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff ============================================================================== --- james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java (original) +++ james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java Thu Dec 27 13:23:54 2012 @@ -19,16 +19,17 @@ package org.apache.james.mime4j.storage; +import org.apache.james.mime4j.codec.CodecUtil; +import org.junit.Assert; +import org.junit.Test; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import org.apache.james.mime4j.codec.CodecUtil; - -import junit.framework.TestCase; - -public class StorageProviderTest extends TestCase { +public class StorageProviderTest { + @Test public void testMemoryStorageProvider() throws Exception { StorageProvider provider = new MemoryStorageProvider(); @@ -40,6 +41,7 @@ public class StorageProviderTest extends testDelete(provider); } + @Test public void testTempFileStorageProvider() throws Exception { StorageProvider provider = new TempFileStorageProvider(); @@ -51,6 +53,7 @@ public class StorageProviderTest extends testDelete(provider); } + @Test public void testThresholdStorageProvider() throws Exception { final int threshold = 5000; StorageProvider backend = new TempFileStorageProvider(); @@ -68,6 +71,7 @@ public class StorageProviderTest extends testDelete(provider); } + @Test public void testCipherStorageProvider() throws Exception { StorageProvider backend = new TempFileStorageProvider(); StorageProvider provider = new CipherStorageProvider(backend); @@ -89,7 +93,7 @@ public class StorageProviderTest extends private void testStore(StorageProvider provider, int size) throws IOException { byte[] data = createData(size); - assertEquals(size, data.length); + Assert.assertEquals(size, data.length); Storage storage = provider.store(new ByteArrayInputStream(data)); @@ -99,9 +103,9 @@ public class StorageProviderTest extends } private void testCreateStorageOutputStream(StorageProvider provider, - int size) throws IOException { + int size) throws IOException { byte[] data = createData(size); - assertEquals(size, data.length); + Assert.assertEquals(size, data.length); StorageOutputStream out = provider.createStorageOutputStream(); CodecUtil.copy(new ByteArrayInputStream(data), out); @@ -113,9 +117,9 @@ public class StorageProviderTest extends } private void verifyData(byte[] expected, byte[] actual) { - assertEquals(expected.length, actual.length); + Assert.assertEquals(expected.length, actual.length); for (int i = 0; i < expected.length; i++) { - assertEquals(expected[i], actual[i]); + Assert.assertEquals(expected[i], actual[i]); } } @@ -136,7 +140,7 @@ public class StorageProviderTest extends // getInputStream has to throw an IllegalStateException try { storage.getInputStream(); - fail(); + Assert.fail(); } catch (IllegalStateException expected) { }
