Skip to content

Commit 00e0305

Browse files
committed
Remove unnecessary code. Changed test from:
if ((to == -1) || (to == termnator)) { to: if (to == termnator) { since we are guaranteed to find the separator because we have tested for its presence at the beginning of the method. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@798427 13f79535-47bb-0310-9956-ffa450edef68
1 parent 81b6c11 commit 00e0305

2 files changed

Lines changed: 21 additions & 42 deletions

File tree

src/java/org/apache/commons/codec/net/RFC1522Codec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected String decodeText(final String text)
130130
}
131131
from = to + 1;
132132
to = text.indexOf(SEP, from);
133-
if ((to == -1) || (to == termnator)) {
133+
if (to == termnator) {
134134
throw new DecoderException("RFC 1522 violation: encoding token not found");
135135
}
136136
String encoding = text.substring(from, to);

src/test/org/apache/commons/codec/net/RFC1522CodecTest.java

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
* @version $Id$
3030
*/
3131
public class RFC1522CodecTest extends TestCase {
32-
32+
3333
public RFC1522CodecTest(String name) {
3434
super(name);
3535
}
3636

37-
static class RFC1522TestCodec extends RFC1522Codec {
37+
static class RFC1522TestCodec extends RFC1522Codec {
3838

3939
protected byte[] doDecoding(byte[] bytes) {
4040
return bytes;
@@ -56,50 +56,29 @@ public void testNullInput() throws Exception {
5656
assertNull(testcodec.encodeText(null, CharEncoding.UTF_8));
5757
}
5858

59-
public void testDecodeInvalid() throws Exception {
59+
private void assertExpectedDecoderException(String s) throws Exception {
6060
RFC1522TestCodec testcodec = new RFC1522TestCodec();
6161
try {
62-
testcodec.decodeText("whatever");
63-
fail("DecoderException should have been thrown");
64-
} catch (DecoderException e) {
65-
// Expected. Move on
66-
}
67-
try {
68-
testcodec.decodeText("=?stuff?=");
62+
testcodec.decodeText(s);
6963
fail("DecoderException should have been thrown");
7064
} catch (DecoderException e) {
71-
// Expected. Move on
72-
}
73-
try {
74-
testcodec.decodeText("=?UTF-8?stuff?=");
75-
fail("DecoderException should have been thrown");
76-
} catch (DecoderException e) {
77-
// Expected. Move on
78-
}
79-
try {
80-
testcodec.decodeText("=?UTF-8?T?stuff");
81-
fail("DecoderException should have been thrown");
82-
} catch (DecoderException e) {
83-
// Expected. Move on
84-
}
85-
try {
86-
testcodec.decodeText("=??T?stuff?=");
87-
fail("DecoderException should have been thrown");
88-
} catch (DecoderException e) {
89-
// Expected. Move on
90-
}
91-
try {
92-
testcodec.decodeText("=?UTF-8??stuff?=");
93-
fail("DecoderException should have been thrown");
94-
} catch (DecoderException e) {
95-
// Expected. Move on
96-
}
97-
try {
98-
testcodec.decodeText("=?UTF-8?W?stuff?=");
99-
fail("DecoderException should have been thrown");
100-
} catch (DecoderException e) {
101-
// Expected. Move on
65+
// Expected.
10266
}
10367
}
10468

69+
public void testDecodeInvalid() throws Exception {
70+
assertExpectedDecoderException("whatever");
71+
assertExpectedDecoderException("=?");
72+
assertExpectedDecoderException("?=");
73+
assertExpectedDecoderException("==");
74+
assertExpectedDecoderException("=??=");
75+
assertExpectedDecoderException("=?stuff?=");
76+
assertExpectedDecoderException("=?UTF-8??=");
77+
assertExpectedDecoderException("=?UTF-8?stuff?=");
78+
assertExpectedDecoderException("=?UTF-8?T?stuff");
79+
assertExpectedDecoderException("=??T?stuff?=");
80+
assertExpectedDecoderException("=?UTF-8??stuff?=");
81+
assertExpectedDecoderException("=?UTF-8?W?stuff?=");
82+
}
83+
10584
}

0 commit comments

Comments
 (0)