You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by ie...@apache.org on 2012/12/27 14:23:56 UTC
svn commit: r1426193 [2/7] - in /james/mime4j/trunk: ./
core/src/test/java/org/apache/james/mime4j/
core/src/test/java/org/apache/james/mime4j/codec/
core/src/test/java/org/apache/james/mime4j/io/
core/src/test/java/org/apache/james/mime4j/parser/ core...
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java Thu Dec 27 13:23:54 2012
@@ -19,56 +19,63 @@
package org.apache.james.mime4j.codec;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
-import junit.framework.TestCase;
-
-public class DecoderUtilTest extends TestCase {
+public class DecoderUtilTest {
+ @Test
public void testDecodeB() throws UnsupportedEncodingException {
String s = DecoderUtil.decodeB("VGhpcyBpcyB0aGUgcGxhaW4gd"
- + "GV4dCBtZXNzYWdlIQ==", "ISO8859-1", DecodeMonitor.STRICT);
- assertEquals("This is the plain text message!", s);
+ + "GV4dCBtZXNzYWdlIQ==", "ISO8859-1", DecodeMonitor.STRICT);
+ Assert.assertEquals("This is the plain text message!", s);
}
+ @Test
public void testDecodeQ() throws UnsupportedEncodingException {
String s = DecoderUtil.decodeQ("=e1_=e2=09=E3_=E4_", "ISO8859-1", DecodeMonitor.STRICT);
- assertEquals("\u00e1 \u00e2\t\u00e3 \u00e4 ", s);
+ Assert.assertEquals("\u00e1 \u00e2\t\u00e3 \u00e4 ", s);
}
+ @Test
public void testNonEncodedWordsAreIgnored() {
- assertEquals("", DecoderUtil.decodeEncodedWords(""));
- assertEquals("Yada yada", DecoderUtil.decodeEncodedWords("Yada yada"));
+ Assert.assertEquals("", DecoderUtil.decodeEncodedWords(""));
+ Assert.assertEquals("Yada yada", DecoderUtil.decodeEncodedWords("Yada yada"));
}
+ @Test
public void testDecodeSomeEncodedWords() {
- assertEquals(" \u00e1\u00e2\u00e3\t\u00e4",
+ Assert.assertEquals(" \u00e1\u00e2\u00e3\t\u00e4",
DecoderUtil.decodeEncodedWords("=?iso-8859-1?Q?_=20=e1=e2=E3=09=E4?="));
- assertEquals("Word 1 ' \u00e2\u00e3\t\u00e4'. Word 2 ' \u00e2\u00e3\t\u00e4'",
+ Assert.assertEquals("Word 1 ' \u00e2\u00e3\t\u00e4'. Word 2 ' \u00e2\u00e3\t\u00e4'",
DecoderUtil.decodeEncodedWords("Word 1 '=?iso-8859-1?Q?_=20=e2=E3=09=E4?="
+ "'. Word 2 '=?iso-8859-1?q?_=20=e2=E3=09=E4?='"));
- assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=",
+ Assert.assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=",
DecoderUtil.decodeEncodedWords("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?="));
- assertEquals("A short text",
+ Assert.assertEquals("A short text",
DecoderUtil.decodeEncodedWords("=?US-ASCII?B?QSBzaG9ydCB0ZXh0?="));
- assertEquals("A short text again!",
+ Assert.assertEquals("A short text again!",
DecoderUtil.decodeEncodedWords("=?US-ASCII?b?QSBzaG9ydCB0ZXh0IGFnYWluIQ==?="));
}
+ @Test
public void testDecodeJapaneseEncodedWords() {
String enc = "=?ISO-2022-JP?B?GyRCTCQbKEobJEI+NRsoShskQkJ6GyhKGyRCOS0bKEo=?= "
- + "=?ISO-2022-JP?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
- + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "
- + "=?ISO-2022-JP?B?GyRCJTkbKEobJEIkThsoShskQjdoGyhKGyRCRGobKEo=?= "
- + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";
+ + "=?ISO-2022-JP?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
+ + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "
+ + "=?ISO-2022-JP?B?GyRCJTkbKEobJEIkThsoShskQjdoGyhKGyRCRGobKEo=?= "
+ + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";
String dec = DecoderUtil.decodeEncodedWords(enc);
- assertEquals("\u672A\u627F\u8AFE\u5E83\u544A\u203B\u30B5\u30A4\u30C9\u30D3"
+ Assert.assertEquals("\u672A\u627F\u8AFE\u5E83\u544A\u203B\u30B5\u30A4\u30C9\u30D3"
+ "\u30B8\u30CD\u30B9\u306E\u6C7A\u5B9A\u7248\u3067\u3059\uFF01", dec);
}
- public void testDecodeJapaneseEncodedWordsWithFallback(){
+ @Test
+ public void testDecodeJapaneseEncodedWordsWithFallback() {
String enc = "=?random?B?GyRCTCQbKEobJEI+NRsoShskQkJ6GyhKGyRCOS0bKEo=?= "
+ "=?garbage?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
+ "=?charset?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "
@@ -76,67 +83,76 @@ public class DecoderUtilTest extends Tes
+ "=?trash?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";
String dec = DecoderUtil.decodeEncodedWords(enc, Charset.forName("ISO-2022-JP"));
- assertEquals("\u672A\u627F\u8AFE\u5E83\u544A\u203B\u30B5\u30A4\u30C9\u30D3"
+ Assert.assertEquals("\u672A\u627F\u8AFE\u5E83\u544A\u203B\u30B5\u30A4\u30C9\u30D3"
+ "\u30B8\u30CD\u30B9\u306E\u6C7A\u5B9A\u7248\u3067\u3059\uFF01", dec);
}
+ @Test
public void testInvalidEncodedWordsAreIgnored() {
- assertEquals("=?iso8859-1?Q?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?Q?="));
- assertEquals("=?iso8859-1?b?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?b?="));
- assertEquals("=?ISO-8859-1?Q?", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?"));
- assertEquals("=?ISO-8859-1?R?abc?=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?R?abc?="));
- assertEquals("test =?ISO-8859-1?R?abc?=", DecoderUtil.decodeEncodedWords("test =?ISO-8859-1?R?abc?="));
+ Assert.assertEquals("=?iso8859-1?Q?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?Q?="));
+ Assert.assertEquals("=?iso8859-1?b?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?b?="));
+ Assert.assertEquals("=?ISO-8859-1?Q?", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?"));
+ Assert.assertEquals("=?ISO-8859-1?R?abc?=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?R?abc?="));
+ Assert.assertEquals("test =?ISO-8859-1?R?abc?=", DecoderUtil.decodeEncodedWords("test =?ISO-8859-1?R?abc?="));
}
+ @Test
public void testEmptyEncodedTextIsIgnored() {
// encoded-text requires at least one character according to rfc 2047
- assertEquals("=?ISO-8859-1?Q??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q??="));
- assertEquals("=?ISO-8859-1?B??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?B??="));
+ Assert.assertEquals("=?ISO-8859-1?Q??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q??="));
+ Assert.assertEquals("=?ISO-8859-1?B??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?B??="));
}
// see MIME4J-104
+ @Test
public void testWhiteSpaceBetweenEncodedWordsGetsRemoved() {
- assertEquals("a", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?="));
- assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b"));
- assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
- assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
- assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=\r\n =?ISO-8859-1?Q?b?="));
- assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a_b?="));
- assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?="));
+ Assert.assertEquals("a", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?="));
+ Assert.assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b"));
+ Assert.assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
+ Assert.assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
+ Assert.assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=\r\n =?ISO-8859-1?Q?b?="));
+ Assert.assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a_b?="));
+ Assert.assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?="));
}
// see MIME4J-138
+ @Test
public void testEncodedTextMayStartWithAnEqualsSign() {
- assertEquals(" foo", DecoderUtil.decodeEncodedWords("=?utf-8?Q?=20foo?="));
- assertEquals("Re: How to place a view at the bottom with a 100% width",
- DecoderUtil.decodeEncodedWords("=?utf-8?Q?Re:=20How=20to=20place=20a=20view=20at=20the=20bottom?= "
- + "=?utf-8?Q?=20with=20a=20100%=20width?="));
- assertEquals("Test \u00fc and more",
- DecoderUtil.decodeEncodedWords("Test =?ISO-8859-1?Q?=FC_?= =?ISO-8859-1?Q?and_more?="));
+ Assert.assertEquals(" foo", DecoderUtil.decodeEncodedWords("=?utf-8?Q?=20foo?="));
+ Assert.assertEquals("Re: How to place a view at the bottom with a 100% width",
+ DecoderUtil.decodeEncodedWords("=?utf-8?Q?Re:=20How=20to=20place=20a=20view=20at=20the=20bottom?= "
+ + "=?utf-8?Q?=20with=20a=20100%=20width?="));
+ Assert.assertEquals("Test \u00fc and more",
+ DecoderUtil.decodeEncodedWords("Test =?ISO-8859-1?Q?=FC_?= =?ISO-8859-1?Q?and_more?="));
}
// see MIME4J-142
+ @Test
public void testEncodedTextMayContainDollarSign() {
- assertEquals("variable ${target.nl}", DecoderUtil.decodeEncodedWords("=?utf-8?Q?variable=20${target.nl}?="));
+ Assert.assertEquals("variable ${target.nl}", DecoderUtil.decodeEncodedWords("=?utf-8?Q?variable=20${target.nl}?="));
}
// see MIME4J-209
+ @Test
public void testEncodedTextMayContainQuestionMark() {
- assertEquals("?", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q???="));
+ Assert.assertEquals("?", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q???="));
}
-
+
+ @Test
public void testNonWhiteSpaceBetweenEncodedWordsIsRetained() {
- assertEquals("a b c", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?="));
- assertEquals("a\rb\nc", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=\rb\n=?ISO-8859-1?Q?c?="));
+ Assert.assertEquals("a b c", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?="));
+ Assert.assertEquals("a\rb\nc", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=\rb\n=?ISO-8859-1?Q?c?="));
}
+ @Test
public void testTextBeforeAndAfterEncodedWordIsRetained() {
- assertEquals(" a b c ", DecoderUtil.decodeEncodedWords(" =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= "));
- assertEquals("! a b c !", DecoderUtil.decodeEncodedWords("! =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= !"));
+ Assert.assertEquals(" a b c ", DecoderUtil.decodeEncodedWords(" =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= "));
+ Assert.assertEquals("! a b c !", DecoderUtil.decodeEncodedWords("! =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= !"));
}
+ @Test
public void testFunnyInputDoesNotRaiseOutOfMemoryError() {
// Bug detected on June 7, 2005. Decoding the following string caused OutOfMemoryError.
- assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!"));
+ Assert.assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!"));
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java Thu Dec 27 13:23:54 2012
@@ -19,151 +19,163 @@
package org.apache.james.mime4j.codec;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-
-import junit.framework.TestCase;
-
import org.apache.james.mime4j.codec.EncoderUtil.Encoding;
import org.apache.james.mime4j.codec.EncoderUtil.Usage;
import org.apache.james.mime4j.util.CharsetUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
-public class EncoderUtilTest extends TestCase {
+public class EncoderUtilTest {
+ @Test
public void testEncodeAddressDisplayName() throws Exception {
- assertEquals("\"\"", EncoderUtil.encodeAddressDisplayName(""));
- assertEquals("test", EncoderUtil.encodeAddressDisplayName("test"));
- assertEquals(" test ", EncoderUtil.encodeAddressDisplayName(" test "));
- assertEquals(" test\ttest ", EncoderUtil
+ Assert.assertEquals("\"\"", EncoderUtil.encodeAddressDisplayName(""));
+ Assert.assertEquals("test", EncoderUtil.encodeAddressDisplayName("test"));
+ Assert.assertEquals(" test ", EncoderUtil.encodeAddressDisplayName(" test "));
+ Assert.assertEquals(" test\ttest ", EncoderUtil
.encodeAddressDisplayName(" test\ttest "));
- assertEquals("\"test()\"", EncoderUtil
+ Assert.assertEquals("\"test()\"", EncoderUtil
.encodeAddressDisplayName("test()"));
- assertEquals("\"John Q. Public\"", EncoderUtil
+ Assert.assertEquals("\"John Q. Public\"", EncoderUtil
.encodeAddressDisplayName("John Q. Public"));
- assertEquals("\"Giant; \\\"Big\\\" Box\"", EncoderUtil
+ Assert.assertEquals("\"Giant; \\\"Big\\\" Box\"", EncoderUtil
.encodeAddressDisplayName("Giant; \"Big\" Box"));
- assertEquals("=?ISO-8859-1?Q?Semmelbr=F6sel?=", EncoderUtil
+ Assert.assertEquals("=?ISO-8859-1?Q?Semmelbr=F6sel?=", EncoderUtil
.encodeAddressDisplayName("Semmelbr\366sel"));
// dollar sign as to be encoded as =24 when used as a word in a phrase
- assertEquals("=?UTF-8?Q?Dollar_=24_Euro_=E2=82=AC?=", EncoderUtil
+ Assert.assertEquals("=?UTF-8?Q?Dollar_=24_Euro_=E2=82=AC?=", EncoderUtil
.encodeAddressDisplayName("Dollar $ Euro \u20ac"));
}
+ @Test
public void testEncodeAddressLocalPart() throws Exception {
- assertEquals("john.wayne", EncoderUtil
+ Assert.assertEquals("john.wayne", EncoderUtil
.encodeAddressLocalPart("john.wayne"));
- assertEquals("\"clint eastwood\"", EncoderUtil
+ Assert.assertEquals("\"clint eastwood\"", EncoderUtil
.encodeAddressLocalPart("clint eastwood"));
}
+ @Test
public void testEncodeHeaderParameter() throws Exception {
- assertEquals("p=test", EncoderUtil.encodeHeaderParameter("p", "test"));
- assertEquals("p=\"test test\"", EncoderUtil.encodeHeaderParameter("p",
+ Assert.assertEquals("p=test", EncoderUtil.encodeHeaderParameter("p", "test"));
+ Assert.assertEquals("p=\"test test\"", EncoderUtil.encodeHeaderParameter("p",
"test test"));
- assertEquals("p=\"=test\"", EncoderUtil.encodeHeaderParameter("p",
+ Assert.assertEquals("p=\"=test\"", EncoderUtil.encodeHeaderParameter("p",
"=test"));
- assertEquals("p=\"\\\\test\"", EncoderUtil.encodeHeaderParameter("p",
+ Assert.assertEquals("p=\"\\\\test\"", EncoderUtil.encodeHeaderParameter("p",
"\\test"));
- assertEquals("p=\"\\\"\\\\\\\"\"", EncoderUtil.encodeHeaderParameter(
+ Assert.assertEquals("p=\"\\\"\\\\\\\"\"", EncoderUtil.encodeHeaderParameter(
"p", "\"\\\""));
}
+ @Test
public void testHasToBeEncoded() throws Exception {
- assertFalse(EncoderUtil.hasToBeEncoded("", 0));
- assertFalse(EncoderUtil.hasToBeEncoded("only ascii characters", 0));
+ Assert.assertFalse(EncoderUtil.hasToBeEncoded("", 0));
+ Assert.assertFalse(EncoderUtil.hasToBeEncoded("only ascii characters", 0));
- assertTrue(EncoderUtil.hasToBeEncoded("non-printable ascii: \010", 0));
- assertTrue(EncoderUtil.hasToBeEncoded("non-ascii: \u20ac", 0));
+ Assert.assertTrue(EncoderUtil.hasToBeEncoded("non-printable ascii: \010", 0));
+ Assert.assertTrue(EncoderUtil.hasToBeEncoded("non-ascii: \u20ac", 0));
- assertFalse(EncoderUtil.hasToBeEncoded("123456789012345678901234567",
+ Assert.assertFalse(EncoderUtil.hasToBeEncoded("123456789012345678901234567",
50));
- assertTrue(EncoderUtil.hasToBeEncoded("1234567890123456789012345678",
+ Assert.assertTrue(EncoderUtil.hasToBeEncoded("1234567890123456789012345678",
50));
- assertFalse(EncoderUtil.hasToBeEncoded(
+ Assert.assertFalse(EncoderUtil.hasToBeEncoded(
"\t12345678901234567890123456789", 50));
}
+ @Test
public void testEncodeEncodedWordDetectCharset() throws Exception {
- assertTrue(EncoderUtil
+ Assert.assertTrue(EncoderUtil
.encodeEncodedWord("only ascii", Usage.TEXT_TOKEN).startsWith(
"=?US-ASCII?"));
- assertTrue(EncoderUtil.encodeEncodedWord("latin 1: \344",
+ Assert.assertTrue(EncoderUtil.encodeEncodedWord("latin 1: \344",
Usage.TEXT_TOKEN).startsWith("=?ISO-8859-1?"));
- assertTrue(EncoderUtil.encodeEncodedWord("unicode: \u20ac",
+ Assert.assertTrue(EncoderUtil.encodeEncodedWord("unicode: \u20ac",
Usage.TEXT_TOKEN).startsWith("=?UTF-8?"));
}
+ @Test
public void testEncodeEncodedWordForceCharset() throws Exception {
- assertTrue(EncoderUtil.encodeEncodedWord("only ascii",
+ Assert.assertTrue(EncoderUtil.encodeEncodedWord("only ascii",
Usage.TEXT_TOKEN, 0, CharsetUtil.UTF_8, null).startsWith(
"=?UTF-8?"));
}
+ @Test
public void testEncodeEncodedWordDetectEncoding() throws Exception {
- assertTrue(EncoderUtil
+ Assert.assertTrue(EncoderUtil
.encodeEncodedWord("only ascii", Usage.TEXT_TOKEN).startsWith(
"=?US-ASCII?Q?"));
- assertTrue(EncoderUtil.encodeEncodedWord("\344\344\344\344\344",
+ Assert.assertTrue(EncoderUtil.encodeEncodedWord("\344\344\344\344\344",
Usage.TEXT_TOKEN).startsWith("=?ISO-8859-1?B?"));
}
+ @Test
public void testEncodeEncodedWordForceEncoding() throws Exception {
- assertTrue(EncoderUtil.encodeEncodedWord("only ascii",
+ Assert.assertTrue(EncoderUtil.encodeEncodedWord("only ascii",
Usage.TEXT_TOKEN, 0, null, Encoding.B).startsWith(
"=?US-ASCII?B?"));
}
+ @Test
public void testEncodeEncodedWordSplit() throws Exception {
String sixty = "123456789012345678901234567890123456789012345678901234567890";
String expected = "=?US-ASCII?Q?" + sixty + "?=";
- assertEquals(expected, EncoderUtil.encodeEncodedWord(sixty,
+ Assert.assertEquals(expected, EncoderUtil.encodeEncodedWord(sixty,
Usage.TEXT_TOKEN, 0, null, Encoding.Q));
- assertEquals(75, expected.length());
+ Assert.assertEquals(75, expected.length());
String sixtyOne = sixty + "1";
String encodedSixtyOne = EncoderUtil.encodeEncodedWord(sixtyOne,
Usage.TEXT_TOKEN, 0, null, Encoding.Q);
- assertTrue(encodedSixtyOne.contains("?= =?US-ASCII?Q?"));
+ Assert.assertTrue(encodedSixtyOne.contains("?= =?US-ASCII?Q?"));
}
+ @Test
public void testEncodeEncodedWord() throws Exception {
- assertEquals("=?US-ASCII?Q??=", EncoderUtil.encodeEncodedWord("",
+ Assert.assertEquals("=?US-ASCII?Q??=", EncoderUtil.encodeEncodedWord("",
Usage.TEXT_TOKEN, 0, null, Encoding.Q));
- assertEquals("=?US-ASCII?Q?testing_123?=", EncoderUtil
+ Assert.assertEquals("=?US-ASCII?Q?testing_123?=", EncoderUtil
.encodeEncodedWord("testing 123", Usage.TEXT_TOKEN, 0, null,
Encoding.Q));
- assertEquals("=?US-ASCII?B?dGVzdGluZyAxMjM=?=", EncoderUtil
+ Assert.assertEquals("=?US-ASCII?B?dGVzdGluZyAxMjM=?=", EncoderUtil
.encodeEncodedWord("testing 123", Usage.TEXT_TOKEN, 0, null,
Encoding.B));
- assertEquals("=?windows-1252?Q?100_=80?=", EncoderUtil
+ Assert.assertEquals("=?windows-1252?Q?100_=80?=", EncoderUtil
.encodeEncodedWord("100 \u20ac", Usage.TEXT_TOKEN, 0, Charset
.forName("Cp1252"), Encoding.Q));
- assertEquals("=?windows-1252?B?MTAwIIA=?=", EncoderUtil
+ Assert.assertEquals("=?windows-1252?B?MTAwIIA=?=", EncoderUtil
.encodeEncodedWord("100 \u20ac", Usage.TEXT_TOKEN, 0, Charset
.forName("Cp1252"), Encoding.B));
}
+ @Test
public void testEncodeB() throws Exception {
- assertEquals("", encodeB(""));
- assertEquals("YQ==", encodeB("a"));
- assertEquals("YWI=", encodeB("ab"));
- assertEquals("YWJj", encodeB("abc"));
- assertEquals("YWJjZA==", encodeB("abcd"));
- assertEquals("YWJjZGU=", encodeB("abcde"));
- assertEquals("YWJjZGVm", encodeB("abcdef"));
- assertEquals("YWJjZGVmZw==", encodeB("abcdefg"));
- assertEquals("YWJjZGVmZ2g=", encodeB("abcdefgh"));
- assertEquals("YWJjZGVmZ2hp", encodeB("abcdefghi"));
- assertEquals("DQoMCQ==", encodeB("\r\n\f\t"));
- assertEquals("LT0/VGhhdCdzIGEgdGVzdD89LQ==",
+ Assert.assertEquals("", encodeB(""));
+ Assert.assertEquals("YQ==", encodeB("a"));
+ Assert.assertEquals("YWI=", encodeB("ab"));
+ Assert.assertEquals("YWJj", encodeB("abc"));
+ Assert.assertEquals("YWJjZA==", encodeB("abcd"));
+ Assert.assertEquals("YWJjZGU=", encodeB("abcde"));
+ Assert.assertEquals("YWJjZGVm", encodeB("abcdef"));
+ Assert.assertEquals("YWJjZGVmZw==", encodeB("abcdefg"));
+ Assert.assertEquals("YWJjZGVmZ2g=", encodeB("abcdefgh"));
+ Assert.assertEquals("YWJjZGVmZ2hp", encodeB("abcdefghi"));
+ Assert.assertEquals("DQoMCQ==", encodeB("\r\n\f\t"));
+ Assert.assertEquals("LT0/VGhhdCdzIGEgdGVzdD89LQ==",
encodeB("-=?That's a test?=-"));
}
+ @Test
public void testEncodeQRegular() throws Exception {
byte[] b = new byte[132];
for (int i = 0; i < 132; i++) {
@@ -174,9 +186,10 @@ public class EncoderUtilTest extends Tes
+ "=10=11=12=13=14=15=16=17=18=19=1A=1B=1C=1D=1E=1F_!\"#$%&"
+ "'()*+,-./0123456789:;<=3D>=3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "[\\]^=5F`abcdefghijklmnopqrstuvwxyz{|}~=7F=80=81=82=83";
- assertEquals(expected, EncoderUtil.encodeQ(b, Usage.TEXT_TOKEN));
+ Assert.assertEquals(expected, EncoderUtil.encodeQ(b, Usage.TEXT_TOKEN));
}
+ @Test
public void testEncodeQRestricted() throws Exception {
byte[] b = new byte[136];
for (int i = 0; i < 136; i++) {
@@ -188,7 +201,7 @@ public class EncoderUtilTest extends Tes
+ "=24=25=26=27=28=29*+=2C-=2E/0123456789=3A=3B=3C=3D=3E=3F"
+ "=40ABCDEFGHIJKLMNOPQRSTUVWXYZ=5B=5C=5D=5E=5F=60abcdefghi"
+ "jklmnopqrstuvwxyz=7B=7C=7D=7E=7F=80=81=82=83=84=85=86=87";
- assertEquals(expected, EncoderUtil.encodeQ(b, Usage.WORD_ENTITY));
+ Assert.assertEquals(expected, EncoderUtil.encodeQ(b, Usage.WORD_ENTITY));
}
private String encodeB(String s) {
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java Thu Dec 27 13:23:54 2012
@@ -19,41 +19,32 @@
package org.apache.james.mime4j.codec;
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.util.CharsetUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
-import junit.framework.TestCase;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mime4j.util.CharsetUtil;
-
-public class QuotedPrintableEncodeTest extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+public class QuotedPrintableEncodeTest {
+ @Test
public void testEscapedSoftBreak() throws Exception {
byte[] content = new byte[500];
- Arrays.fill(content, (byte)0x20);
+ Arrays.fill(content, (byte) 0x20);
byte[] expected = new byte[1557];
int index = 0;
- for (int l=0;l<20;l++) {
- for (int i=0;i<25;i++) {
+ for (int l = 0; l < 20; l++) {
+ for (int i = 0; i < 25; i++) {
expected[index++] = '=';
expected[index++] = '2';
expected[index++] = '0';
}
- if (l<19) {
+ if (l < 19) {
expected[index++] = '=';
expected[index++] = '\r';
expected[index++] = '\n';
@@ -62,11 +53,12 @@ public class QuotedPrintableEncodeTest e
check(content, expected);
}
+ @Test
public void testPlainAsciiSoftBreak() throws Exception {
byte[] content = new byte[500];
- Arrays.fill(content, (byte)0x29);
+ Arrays.fill(content, (byte) 0x29);
byte[] expected = new byte[518];
- Arrays.fill(expected, (byte)0x29);
+ Arrays.fill(expected, (byte) 0x29);
expected[75] = '=';
expected[76] = '\r';
expected[77] = '\n';
@@ -88,6 +80,7 @@ public class QuotedPrintableEncodeTest e
check(content, expected);
}
+ @Test
public void testPlainASCII() throws Exception {
checkRoundtrip("Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
@@ -95,12 +88,14 @@ public class QuotedPrintableEncodeTest e
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage.");
}
+ @Test
public void testEncodeSpace() throws Exception {
checkRoundtrip(" ");
}
+ @Test
public void testLetterEncoding() throws Exception {
- for (byte b=0;b<Byte.MAX_VALUE;b++) {
+ for (byte b = 0; b < Byte.MAX_VALUE; b++) {
byte[] content = {b};
checkRoundtrip(content);
}
@@ -133,9 +128,9 @@ public class QuotedPrintableEncodeTest e
}
private void assertEquals(byte[] expected, byte[] actual) {
- assertEquals(expected.length, actual.length);
+ Assert.assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i++) {
- assertEquals("Mismatch@" + i, expected[i], actual[i]);
+ Assert.assertEquals("Mismatch@" + i, expected[i], actual[i]);
}
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java Thu Dec 27 13:23:54 2012
@@ -19,80 +19,92 @@
package org.apache.james.mime4j.codec;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import junit.framework.TestCase;
-
-public class QuotedPrintableInputStreamTest extends TestCase {
+public class QuotedPrintableInputStreamTest {
+ @Test
public void testBasicDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("\u00e1\u00e2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("\u00e1\u00e2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeBufferWrapping() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream(
"=e1=e2=E3=E4\r\n=e1=e2=E3=E4\r\n=e1=e2=E3=E4\r\n=e1=e2=E3=E4\r\n=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("\u00e1\u00e2\u00e3\u00e4\r\n\u00e1\u00e2\u00e3\u00e4\r\n\u00e1\u00e2\u00e3" +
+ Assert.assertEquals("\u00e1\u00e2\u00e3\u00e4\r\n\u00e1\u00e2\u00e3\u00e4\r\n\u00e1\u00e2\u00e3" +
"\u00e4\r\n\u00e1\u00e2\u00e3\u00e4\r\n\u00e1\u00e2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testInvalidValueDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("=e1=g2=E3=E4\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("\u00e1=g2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("\u00e1=g2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeTrailingBlanks() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream(" =e1 =e2 =E3\t=E4 \t \t \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals(" \u00e1 \u00e2 \u00e3\t\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals(" \u00e1 \u00e2 \u00e3\t\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testCanonicalSoftBreakDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line =\r\nHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testInvalidCR() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Invalid=\rCR\rHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
// TODO is this what we really expect from decoding a stream including CR with no LF?
- assertEquals("Invalid=\rCR\rHard line\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("Invalid=\rCR\rHard line\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testSoftBreakLoneLFDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line =\nHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testSoftBreakTrailingBalnksDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line = \t \r\nHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testBrokenSoftBreakDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line =\rHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("Soft line =\rHard line\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("Soft line =\rHard line\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testEscapedEQDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("width==340 height=3d200\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("width=340 height=200\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("width=340 height=200\r\n", new String(read(decoder), "ISO8859-1"));
// TODO this could be even decoded as width=40 height=200.
}
+ @Test
public void testBrokenEscapedEQDecode() throws IOException, UnsupportedEncodingException {
/*
* This isn't valid qp (==) but it is known to occur in certain
@@ -100,65 +112,73 @@ public class QuotedPrintableInputStreamT
*/
ByteArrayInputStream bis = new ByteArrayInputStream("width==\r\n340 height=3d200\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("width=340 height=200\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("width=340 height=200\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testSpacesBeforeEOL() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("some \r\n spaced\t\r\ncontent \t \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
- assertEquals("some\r\n spaced\r\ncontent\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("some\r\n spaced\r\ncontent\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeEndOfStream1() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("01234567".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(6, bis, false);
- assertEquals("01234567", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("01234567", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeEndOfStream2() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("012345\r".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(6, bis, false);
- assertEquals("012345", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("012345", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeEndOfStream3() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("012345\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(6, bis, false);
- assertEquals("012345\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("012345\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeEndOfStream4() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("01234= ".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(6, bis, false);
- assertEquals("01234", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("01234", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeEndOfStream5() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("01234=\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(6, bis, false);
- assertEquals("01234", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("01234", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodeEndOfStream6() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("01234\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(6, bis, false);
- assertEquals("01234\r\n", new String(read(decoder), "ISO8859-1"));
+ Assert.assertEquals("01234\r\n", new String(read(decoder), "ISO8859-1"));
}
+ @Test
public void testDecodePrematureClose() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = null;
QuotedPrintableInputStream decoder = null;
bis = new ByteArrayInputStream("=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
decoder = new QuotedPrintableInputStream(bis);
- assertEquals('\u00e1', decoder.read());
- assertEquals('\u00e2', decoder.read());
+ Assert.assertEquals('\u00e1', decoder.read());
+ Assert.assertEquals('\u00e2', decoder.read());
decoder.close();
try {
decoder.read();
- fail();
+ Assert.fail();
} catch (IOException expected) {
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java Thu Dec 27 13:23:54 2012
@@ -19,14 +19,17 @@
package org.apache.james.mime4j.codec;
+import org.junit.Assert;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import junit.framework.TestCase;
-
-public class QuotedPrintableOutputStreamTest extends TestCase {
+public class QuotedPrintableOutputStreamTest {
+ @Test
public void testEncode() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
@@ -38,10 +41,11 @@ public class QuotedPrintableOutputStream
encoder = new QuotedPrintableOutputStream(bos, false);
encoder.write(fromString("This is the plain text message containing a few euros: 100 \u20ac!"));
encoder.close();
- assertEquals("This is the plain text message containing a few euros: 100 =E2=82=AC!",
+ Assert.assertEquals("This is the plain text message containing a few euros: 100 =E2=82=AC!",
toString(bos.toByteArray()));
}
+ @Test
public void testEncodeUnderlyingStreamStaysOpen() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
@@ -53,7 +57,7 @@ public class QuotedPrintableOutputStream
try {
encoder.write('b');
- fail();
+ Assert.fail();
} catch (IOException expected) {
}
@@ -61,10 +65,11 @@ public class QuotedPrintableOutputStream
bos.write('a');
bos.write('d');
bos.write('a');
- assertEquals("This is the plain text message containing a few euros: 100 =E2=82=AC!yada",
+ Assert.assertEquals("This is the plain text message containing a few euros: 100 =E2=82=AC!yada",
toString(bos.toByteArray()));
}
+ @Test
public void testEncodeSpecials() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
@@ -73,10 +78,11 @@ public class QuotedPrintableOutputStream
encoder = new QuotedPrintableOutputStream(bos, false);
encoder.write(fromString("Testing \u20ac special . chars = also at the end ="));
encoder.close();
- assertEquals("Testing =E2=82=AC special =2E chars =3D also at the end =3D",
+ Assert.assertEquals("Testing =E2=82=AC special =2E chars =3D also at the end =3D",
toString(bos.toByteArray()));
}
+ @Test
public void testEncodeWrapping() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
@@ -85,7 +91,7 @@ public class QuotedPrintableOutputStream
encoder = new QuotedPrintableOutputStream(bos, false);
encoder.write(fromString("This is a very very very very very very very very very very very very very very very long line"));
encoder.close();
- assertEquals("This is a very very very very very very very very very very very very very =\r\nvery very long line",
+ Assert.assertEquals("This is a very very very very very very very very very very very very very =\r\nvery very long line",
toString(bos.toByteArray()));
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java Thu Dec 27 13:23:54 2012
@@ -19,41 +19,32 @@
package org.apache.james.mime4j.codec;
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.util.CharsetUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
-import junit.framework.TestCase;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mime4j.util.CharsetUtil;
-
-public class QuotedPrintableTextEncodeTest extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+public class QuotedPrintableTextEncodeTest {
+ @Test
public void testEscapedSoftBreak() throws Exception {
byte[] content = new byte[500];
- Arrays.fill(content, (byte)0x18);
+ Arrays.fill(content, (byte) 0x18);
byte[] expected = new byte[1557];
int index = 0;
- for (int l=0;l<20;l++) {
- for (int i=0;i<25;i++) {
+ for (int l = 0; l < 20; l++) {
+ for (int i = 0; i < 25; i++) {
expected[index++] = '=';
expected[index++] = '1';
expected[index++] = '8';
}
- if (l<19) {
+ if (l < 19) {
expected[index++] = '=';
expected[index++] = '\r';
expected[index++] = '\n';
@@ -62,11 +53,12 @@ public class QuotedPrintableTextEncodeTe
check(content, expected);
}
+ @Test
public void testPlainAsciiSoftBreak() throws Exception {
byte[] content = new byte[500];
- Arrays.fill(content, (byte)0x29);
+ Arrays.fill(content, (byte) 0x29);
byte[] expected = new byte[518];
- Arrays.fill(expected, (byte)0x29);
+ Arrays.fill(expected, (byte) 0x29);
expected[75] = '=';
expected[76] = '\r';
expected[77] = '\n';
@@ -88,6 +80,7 @@ public class QuotedPrintableTextEncodeTe
check(content, expected);
}
+ @Test
public void testPlainASCII() throws Exception {
checkRoundtrip("Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
@@ -95,12 +88,14 @@ public class QuotedPrintableTextEncodeTe
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage.");
}
+ @Test
public void testEncodeSpace() throws Exception {
checkRoundtrip(" A");
}
+ @Test
public void testLetterEncoding() throws Exception {
- for (byte b=0;b<Byte.MAX_VALUE;b++) {
+ for (byte b = 0; b < Byte.MAX_VALUE; b++) {
byte[] content = {b};
// White space is only escaped when followed by CRLF
if (b != 10 && b != 13 && b != 32 && b != 9) {
@@ -109,35 +104,42 @@ public class QuotedPrintableTextEncodeTe
}
}
+ @Test
public void testCRLFShouldResetLineCount() throws Exception {
StringBuilder buffer = new StringBuilder(4096);
- for (int i=0;i<1000;i++) {
+ for (int i = 0; i < 1000; i++) {
buffer.append("Hugo\r\n");
}
String longLine = buffer.toString();
check(longLine, longLine);
}
+ @Test
public void testDontEscapeLF() throws Exception {
check("Ready\nFor\n", "Ready\nFor\n");
}
+ @Test
public void testDontEscapeCR() throws Exception {
check("Ready\rFor\r", "Ready\rFor\r");
}
+ @Test
public void testEscapeSpaceAtLineEnd() throws Exception {
check(" \r\n", " =20\r\n");
}
+ @Test
public void testDontEscapeSpaceBeforeLineEnd() throws Exception {
check(" ", " ");
}
+ @Test
public void testDontEscapeTabsBeforeLineEnd() throws Exception {
check("\t\t\t\t", "\t\t\t\t");
}
+ @Test
public void testDontWhiteSpaceBeforeLineEnd() throws Exception {
check(" \t\t \t", " \t\t \t");
}
@@ -175,9 +177,9 @@ public class QuotedPrintableTextEncodeTe
}
private void assertEquals(byte[] expected, byte[] actual) {
- assertEquals(expected.length, actual.length);
+ Assert.assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i++) {
- assertEquals("Mismatch@" + i, expected[i], actual[i]);
+ Assert.assertEquals("Mismatch@" + i, expected[i], actual[i]);
}
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java Thu Dec 27 13:23:54 2012
@@ -19,14 +19,14 @@
package org.apache.james.mime4j.io;
-import org.apache.james.mime4j.io.BufferedLineReaderInputStream;
+import org.junit.Assert;
+import org.junit.Test;
import java.io.ByteArrayInputStream;
-import junit.framework.TestCase;
-
-public class BufferedLineReaderInputStreamBufferTest extends TestCase {
+public class BufferedLineReaderInputStreamBufferTest {
+ @Test
public void testInvalidInput() throws Exception {
String text = "blah blah yada yada";
byte[] b1 = text.getBytes("US-ASCII");
@@ -35,99 +35,101 @@ public class BufferedLineReaderInputStre
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
- assertEquals('b', inbuffer.read());
- assertEquals('l', inbuffer.read());
+ Assert.assertEquals('b', inbuffer.read());
+ Assert.assertEquals('l', inbuffer.read());
try {
inbuffer.byteAt(1);
- fail("IndexOutOfBoundsException should have been thrown");
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.byteAt(20);
- fail("IndexOutOfBoundsException should have been thrown");
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, -1, 3);
- fail("IndexOutOfBoundsException should have been thrown");
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, 1, 3);
- fail("IndexOutOfBoundsException should have been thrown");
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, 2, -1);
- fail("IndexOutOfBoundsException should have been thrown");
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, 2, 18);
- fail("IndexOutOfBoundsException should have been thrown");
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
- assertEquals(5, inbuffer.indexOf(b2, 2, 17));
+ Assert.assertEquals(5, inbuffer.indexOf(b2, 2, 17));
try {
- inbuffer.indexOf((byte)' ', -1, 3);
- fail("IndexOutOfBoundsException should have been thrown");
+ inbuffer.indexOf((byte) ' ', -1, 3);
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
- inbuffer.indexOf((byte)' ', 1, 3);
- fail("IndexOutOfBoundsException should have been thrown");
+ inbuffer.indexOf((byte) ' ', 1, 3);
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
- inbuffer.indexOf((byte)' ', 2, -1);
- fail("IndexOutOfBoundsException should have been thrown");
+ inbuffer.indexOf((byte) ' ', 2, -1);
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
- inbuffer.indexOf((byte)' ', 2, 18);
- fail("IndexOutOfBoundsException should have been thrown");
+ inbuffer.indexOf((byte) ' ', 2, 18);
+ Assert.fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
- assertEquals(10, inbuffer.indexOf((byte)'y', 2, 17));
+ Assert.assertEquals(10, inbuffer.indexOf((byte) 'y', 2, 17));
}
+ @Test
public void testBasicOperations() throws Exception {
String text = "bla bla yada yada haha haha";
byte[] b1 = text.getBytes("US-ASCII");
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
- assertEquals(0, inbuffer.pos());
- assertEquals(27, inbuffer.limit());
- assertEquals(27, inbuffer.length());
+ Assert.assertEquals(0, inbuffer.pos());
+ Assert.assertEquals(27, inbuffer.limit());
+ Assert.assertEquals(27, inbuffer.length());
inbuffer.read();
inbuffer.read();
- assertEquals(2, inbuffer.pos());
- assertEquals(27, inbuffer.limit());
- assertEquals(25, inbuffer.length());
+ Assert.assertEquals(2, inbuffer.pos());
+ Assert.assertEquals(27, inbuffer.limit());
+ Assert.assertEquals(25, inbuffer.length());
byte[] tmp1 = new byte[3];
- assertEquals(3, inbuffer.read(tmp1));
+ Assert.assertEquals(3, inbuffer.read(tmp1));
- assertEquals(5, inbuffer.pos());
- assertEquals(27, inbuffer.limit());
- assertEquals(22, inbuffer.length());
+ Assert.assertEquals(5, inbuffer.pos());
+ Assert.assertEquals(27, inbuffer.limit());
+ Assert.assertEquals(22, inbuffer.length());
byte[] tmp2 = new byte[22];
- assertEquals(22, inbuffer.read(tmp2));
+ Assert.assertEquals(22, inbuffer.read(tmp2));
+
+ Assert.assertEquals(27, inbuffer.pos());
+ Assert.assertEquals(27, inbuffer.limit());
+ Assert.assertEquals(0, inbuffer.length());
- assertEquals(27, inbuffer.pos());
- assertEquals(27, inbuffer.limit());
- assertEquals(0, inbuffer.length());
-
- assertEquals(-1, inbuffer.read(tmp1));
- assertEquals(-1, inbuffer.read(tmp1));
- assertEquals(-1, inbuffer.read());
- assertEquals(-1, inbuffer.read());
+ Assert.assertEquals(-1, inbuffer.read(tmp1));
+ Assert.assertEquals(-1, inbuffer.read(tmp1));
+ Assert.assertEquals(-1, inbuffer.read());
+ Assert.assertEquals(-1, inbuffer.read());
}
+ @Test
public void testPatternMatching1() throws Exception {
String text = "blabla d is the word";
String pattern = "d";
@@ -136,9 +138,10 @@ public class BufferedLineReaderInputStre
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
int i = inbuffer.indexOf(b2);
- assertEquals(7, i);
+ Assert.assertEquals(7, i);
}
+ @Test
public void testPatternMatching2() throws Exception {
String text = "disddisdissdsidsidsiid";
String pattern = "siid";
@@ -147,9 +150,10 @@ public class BufferedLineReaderInputStre
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
int i = inbuffer.indexOf(b2);
- assertEquals(18, i);
+ Assert.assertEquals(18, i);
}
+ @Test
public void testPatternMatching3() throws Exception {
String text = "bla bla yada yada haha haha";
String pattern = "blah";
@@ -158,9 +162,10 @@ public class BufferedLineReaderInputStre
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
int i = inbuffer.indexOf(b2);
- assertEquals(-1, i);
+ Assert.assertEquals(-1, i);
}
+ @Test
public void testPatternMatching4() throws Exception {
String text = "bla bla yada yada haha haha";
String pattern = "bla";
@@ -169,9 +174,10 @@ public class BufferedLineReaderInputStre
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
int i = inbuffer.indexOf(b2);
- assertEquals(0, i);
+ Assert.assertEquals(0, i);
}
+ @Test
public void testPatternOutOfBound() throws Exception {
String text = "bla bla yada yada haha haha";
String pattern1 = "bla bla";
@@ -182,11 +188,12 @@ public class BufferedLineReaderInputStre
byte[] tmp = new byte[3];
inbuffer.read(tmp);
int i = inbuffer.indexOf(b2, inbuffer.pos(), inbuffer.length());
- assertEquals(-1, i);
+ Assert.assertEquals(-1, i);
i = inbuffer.indexOf(b2, inbuffer.pos(), inbuffer.length() - 1);
- assertEquals(-1, i);
+ Assert.assertEquals(-1, i);
}
+ @Test
public void testCharOutOfBound() throws Exception {
String text = "zzz blah blah blah ggg";
byte[] b1 = text.getBytes("US-ASCII");
@@ -194,18 +201,19 @@ public class BufferedLineReaderInputStre
inbuffer.fillBuffer();
byte[] tmp = new byte[3];
inbuffer.read(tmp);
- int i = inbuffer.indexOf((byte)'z', inbuffer.pos(), inbuffer.length());
- assertEquals(-1, i);
- i = inbuffer.indexOf((byte)'g', inbuffer.pos(), inbuffer.length() - 3);
- assertEquals(-1, i);
+ int i = inbuffer.indexOf((byte) 'z', inbuffer.pos(), inbuffer.length());
+ Assert.assertEquals(-1, i);
+ i = inbuffer.indexOf((byte) 'g', inbuffer.pos(), inbuffer.length() - 3);
+ Assert.assertEquals(-1, i);
}
+ @Test
public void test0xFFInBinaryStream() throws Exception {
- byte[] b1 = new byte[] {1, 2, 3, (byte) 0xff, 10, 1, 2, 3};
- byte[] b2 = new byte[] {10};
+ byte[] b1 = new byte[]{1, 2, 3, (byte) 0xff, 10, 1, 2, 3};
+ byte[] b2 = new byte[]{10};
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
int i = inbuffer.indexOf(b2);
- assertEquals(4, i);
+ Assert.assertEquals(4, i);
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java Thu Dec 27 13:23:54 2012
@@ -19,37 +19,36 @@
package org.apache.james.mime4j.io;
-import org.apache.james.mime4j.io.BufferedLineReaderInputStream;
-import org.apache.james.mime4j.io.LineReaderInputStream;
-import org.apache.james.mime4j.io.MaxLineLimitException;
import org.apache.james.mime4j.util.ByteArrayBuffer;
+import org.junit.Assert;
+import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
-
-public class BufferedLineReaderInputStreamTest extends TestCase {
+public class BufferedLineReaderInputStreamTest {
+ @Test
public void testBasicOperations() throws Exception {
String text = "ah blahblah";
byte[] b1 = text.getBytes("US-ASCII");
BufferedLineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
- assertEquals((byte)'a', instream.read());
- assertEquals((byte)'h', instream.read());
- assertEquals((byte)' ', instream.read());
+ Assert.assertEquals((byte) 'a', instream.read());
+ Assert.assertEquals((byte) 'h', instream.read());
+ Assert.assertEquals((byte) ' ', instream.read());
byte[] tmp1 = new byte[4];
- assertEquals(4, instream.read(tmp1));
- assertEquals(4, instream.read(tmp1));
+ Assert.assertEquals(4, instream.read(tmp1));
+ Assert.assertEquals(4, instream.read(tmp1));
- assertEquals(-1, instream.read(tmp1));
- assertEquals(-1, instream.read(tmp1));
- assertEquals(-1, instream.read());
- assertEquals(-1, instream.read());
+ Assert.assertEquals(-1, instream.read(tmp1));
+ Assert.assertEquals(-1, instream.read(tmp1));
+ Assert.assertEquals(-1, instream.read());
+ Assert.assertEquals(-1, instream.read());
}
+ @Test
public void testBasicReadLine() throws Exception {
String[] teststrs = new String[5];
@@ -79,12 +78,13 @@ public class BufferedLineReaderInputStre
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals(teststr, s);
+ Assert.assertEquals(teststr, s);
}
- assertEquals(-1, instream.readLine(linebuf));
- assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
}
+ @Test
public void testReadEmptyLine() throws Exception {
String teststr = "\n\n\r\n\r\r\n\n\n\n\n\n";
@@ -96,52 +96,53 @@ public class BufferedLineReaderInputStre
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\r\n", s);
+ Assert.assertEquals("\r\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\r\r\n", s);
+ Assert.assertEquals("\r\r\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
- assertEquals(-1, instream.readLine(linebuf));
- assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
}
+ @Test
public void testReadEmptyLineMaxLimit() throws Exception {
String teststr = "1234567890\r\n";
@@ -158,7 +159,7 @@ public class BufferedLineReaderInputStre
linebuf.clear();
try {
instream2.readLine(linebuf);
- fail("MaxLineLimitException should have been thrown");
+ Assert.fail("MaxLineLimitException should have been thrown");
} catch (MaxLineLimitException ex) {
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java Thu Dec 27 13:23:54 2012
@@ -19,17 +19,17 @@
package org.apache.james.mime4j.io;
+import org.junit.Assert;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import org.apache.james.mime4j.io.EOLConvertingInputStream;
-
-
-import junit.framework.TestCase;
-
-public class EOLConvertingInputStreamTest extends TestCase {
+public class EOLConvertingInputStreamTest {
+ @Test
public void testRead() throws IOException {
testConvertBoth("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n");
testConvertCR("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n");
@@ -69,10 +69,10 @@ public class EOLConvertingInputStreamTes
ByteArrayInputStream bais = new ByteArrayInputStream(fromString(s1));
EOLConvertingInputStream in =
- new EOLConvertingInputStream(bais,
+ new EOLConvertingInputStream(bais,
EOLConvertingInputStream.CONVERT_BOTH);
int n = in.read(bytes);
- assertEquals(s2, toString(bytes, n));
+ Assert.assertEquals(s2, toString(bytes, n));
}
private void testConvertCR(String s1, String s2) throws IOException {
@@ -80,10 +80,10 @@ public class EOLConvertingInputStreamTes
ByteArrayInputStream bais = new ByteArrayInputStream(fromString(s1));
EOLConvertingInputStream in =
- new EOLConvertingInputStream(bais,
+ new EOLConvertingInputStream(bais,
EOLConvertingInputStream.CONVERT_CR);
int n = in.read(bytes);
- assertEquals(s2, toString(bytes, n));
+ Assert.assertEquals(s2, toString(bytes, n));
}
private void testConvertLF(String s1, String s2) throws IOException {
@@ -91,10 +91,10 @@ public class EOLConvertingInputStreamTes
ByteArrayInputStream bais = new ByteArrayInputStream(fromString(s1));
EOLConvertingInputStream in =
- new EOLConvertingInputStream(bais,
+ new EOLConvertingInputStream(bais,
EOLConvertingInputStream.CONVERT_LF);
int n = in.read(bytes);
- assertEquals(s2, toString(bytes, n));
+ Assert.assertEquals(s2, toString(bytes, n));
}
private String toString(byte[] b, int len) {
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java Thu Dec 27 13:23:54 2012
@@ -19,36 +19,38 @@
package org.apache.james.mime4j.io;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import junit.framework.TestCase;
-
-public class LimitedInputStreamTest extends TestCase {
+public class LimitedInputStreamTest {
+ @Test
public void testUpToLimitRead() throws IOException {
- byte[] data = new byte[] {'0', '1', '2', '3', '4', '5', '6'};
+ byte[] data = new byte[]{'0', '1', '2', '3', '4', '5', '6'};
ByteArrayInputStream instream = new ByteArrayInputStream(data);
LimitedInputStream limitedStream = new LimitedInputStream(instream, 3);
- assertEquals(0, limitedStream.getPosition());
- assertTrue(limitedStream.read() != -1);
- assertEquals(1, limitedStream.getPosition());
+ Assert.assertEquals(0, limitedStream.getPosition());
+ Assert.assertTrue(limitedStream.read() != -1);
+ Assert.assertEquals(1, limitedStream.getPosition());
byte[] tmp = new byte[3];
- assertEquals(2, limitedStream.read(tmp));
- assertEquals(3, limitedStream.getPosition());
+ Assert.assertEquals(2, limitedStream.read(tmp));
+ Assert.assertEquals(3, limitedStream.getPosition());
try {
limitedStream.read();
- fail("IOException should have been thrown");
+ Assert.fail("IOException should have been thrown");
} catch (IOException ex) {
}
try {
limitedStream.read(tmp);
- fail("IOException should have been thrown");
+ Assert.fail("IOException should have been thrown");
} catch (IOException ex) {
}
try {
limitedStream.skip(2);
- fail("IOException should have been thrown");
+ Assert.fail("IOException should have been thrown");
} catch (IOException ex) {
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineNumberInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineNumberInputStreamTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineNumberInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineNumberInputStreamTest.java Thu Dec 27 13:23:54 2012
@@ -19,63 +19,64 @@
package org.apache.james.mime4j.io;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import org.apache.james.mime4j.io.LineNumberInputStream;
-
-import junit.framework.TestCase;
-
-public class LineNumberInputStreamTest extends TestCase {
+public class LineNumberInputStreamTest {
/**
* Tests that reading single bytes updates the line number appropriately.
*/
+ @Test
public void testReadSingleByte() throws IOException {
String s = "Yada\r\nyada\r\nyada\r\n";
LineNumberInputStream is = new LineNumberInputStream(
new ByteArrayInputStream(s.getBytes()));
for (int i = 0; i < 6; i++) {
- assertEquals(1, is.getLineNumber());
+ Assert.assertEquals(1, is.getLineNumber());
is.read();
}
for (int i = 6; i < 12; i++) {
- assertEquals(2, is.getLineNumber());
+ Assert.assertEquals(2, is.getLineNumber());
is.read();
}
for (int i = 12; i < 18; i++) {
- assertEquals(3, is.getLineNumber());
+ Assert.assertEquals(3, is.getLineNumber());
is.read();
}
- assertEquals(4, is.getLineNumber());
- assertEquals(-1, is.read());
+ Assert.assertEquals(4, is.getLineNumber());
+ Assert.assertEquals(-1, is.read());
}
/**
* Tests that reading multiple bytes at once updates the line number
* appropriately.
*/
+ @Test
public void testReadManyBytes() throws IOException {
String s = "Yada\r\nyada\r\nyada\r\n";
LineNumberInputStream is = new LineNumberInputStream(
new ByteArrayInputStream(s.getBytes()));
byte[] buf = new byte[4];
- assertEquals(1, is.getLineNumber());
+ Assert.assertEquals(1, is.getLineNumber());
is.read(buf);
- assertEquals(1, is.getLineNumber());
+ Assert.assertEquals(1, is.getLineNumber());
is.read(buf);
- assertEquals(2, is.getLineNumber());
+ Assert.assertEquals(2, is.getLineNumber());
is.read(buf);
- assertEquals(3, is.getLineNumber());
+ Assert.assertEquals(3, is.getLineNumber());
is.read(buf);
- assertEquals(3, is.getLineNumber());
+ Assert.assertEquals(3, is.getLineNumber());
is.read(buf);
- assertEquals(4, is.getLineNumber());
+ Assert.assertEquals(4, is.getLineNumber());
- assertEquals(-1, is.read());
+ Assert.assertEquals(-1, is.read());
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java?rev=1426193&r1=1426192&r2=1426193&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java Thu Dec 27 13:23:54 2012
@@ -19,17 +19,16 @@
package org.apache.james.mime4j.io;
-import org.apache.james.mime4j.io.LineReaderInputStreamAdaptor;
-import org.apache.james.mime4j.io.MaxLineLimitException;
import org.apache.james.mime4j.util.ByteArrayBuffer;
+import org.junit.Assert;
+import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
-
-public class LineReaderInputStreamAdaptorTest extends TestCase {
+public class LineReaderInputStreamAdaptorTest {
+ @Test
public void testBasicOperations() throws Exception {
String text = "ah blahblah";
byte[] b1 = text.getBytes("US-ASCII");
@@ -37,20 +36,21 @@ public class LineReaderInputStreamAdapto
LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
new ByteArrayInputStream(b1));
- assertEquals((byte)'a', instream.read());
- assertEquals((byte)'h', instream.read());
- assertEquals((byte)' ', instream.read());
+ Assert.assertEquals((byte) 'a', instream.read());
+ Assert.assertEquals((byte) 'h', instream.read());
+ Assert.assertEquals((byte) ' ', instream.read());
byte[] tmp1 = new byte[4];
- assertEquals(4, instream.read(tmp1));
- assertEquals(4, instream.read(tmp1));
+ Assert.assertEquals(4, instream.read(tmp1));
+ Assert.assertEquals(4, instream.read(tmp1));
- assertEquals(-1, instream.read(tmp1));
- assertEquals(-1, instream.read(tmp1));
- assertEquals(-1, instream.read());
- assertEquals(-1, instream.read());
+ Assert.assertEquals(-1, instream.read(tmp1));
+ Assert.assertEquals(-1, instream.read(tmp1));
+ Assert.assertEquals(-1, instream.read());
+ Assert.assertEquals(-1, instream.read());
}
+ @Test
public void testBasicReadLine() throws Exception {
String[] teststrs = new String[5];
@@ -81,12 +81,13 @@ public class LineReaderInputStreamAdapto
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals(teststr, s);
+ Assert.assertEquals(teststr, s);
}
- assertEquals(-1, instream.readLine(linebuf));
- assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
}
+ @Test
public void testReadEmptyLine() throws Exception {
String teststr = "\n\n\r\n\r\r\n\n\n\n\n\n";
@@ -99,52 +100,53 @@ public class LineReaderInputStreamAdapto
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\r\n", s);
+ Assert.assertEquals("\r\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\r\r\n", s);
+ Assert.assertEquals("\r\r\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
- assertEquals("\n", s);
+ Assert.assertEquals("\n", s);
- assertEquals(-1, instream.readLine(linebuf));
- assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
+ Assert.assertEquals(-1, instream.readLine(linebuf));
}
+ @Test
public void testReadEmptyLineMaxLimit() throws Exception {
String teststr = "1234567890\r\n";
@@ -161,7 +163,7 @@ public class LineReaderInputStreamAdapto
linebuf.clear();
try {
instream2.readLine(linebuf);
- fail("MaxLineLimitException should have been thrown");
+ Assert.fail("MaxLineLimitException should have been thrown");
} catch (MaxLineLimitException ex) {
}
}