commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r798427 - in /commons/proper/codec/trunk/src: java/org/apache/commons/codec/net/RFC1522Codec.java test/org/apache/commons/codec/net/RFC1522CodecTest.java
Date Tue, 28 Jul 2009 07:32:09 GMT
Author: ggregory
Date: Tue Jul 28 07:32:09 2009
New Revision: 798427

URL: http://svn.apache.org/viewvc?rev=798427&view=rev
Log:
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.

Modified:
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/RFC1522CodecTest.java

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java?rev=798427&r1=798426&r2=798427&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java Tue
Jul 28 07:32:09 2009
@@ -130,7 +130,7 @@
         }
         from = to + 1;
         to = text.indexOf(SEP, from);
-        if ((to == -1) || (to == termnator)) {
+        if (to == termnator) {
             throw new DecoderException("RFC 1522 violation: encoding token not found");
         }
         String encoding = text.substring(from, to);

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/RFC1522CodecTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/RFC1522CodecTest.java?rev=798427&r1=798426&r2=798427&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/RFC1522CodecTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/RFC1522CodecTest.java
Tue Jul 28 07:32:09 2009
@@ -29,12 +29,12 @@
  * @version $Id$
  */
 public class RFC1522CodecTest extends TestCase {
-    
+
     public RFC1522CodecTest(String name) {
         super(name);
     }
 
-    static class RFC1522TestCodec extends RFC1522Codec { 
+    static class RFC1522TestCodec extends RFC1522Codec {
 
         protected byte[] doDecoding(byte[] bytes) {
             return bytes;
@@ -56,50 +56,29 @@
         assertNull(testcodec.encodeText(null, CharEncoding.UTF_8));
     }
 
-    public void testDecodeInvalid() throws Exception {
+    private void assertExpectedDecoderException(String s) throws Exception {
         RFC1522TestCodec testcodec = new RFC1522TestCodec();
         try {
-            testcodec.decodeText("whatever");
-            fail("DecoderException should have been thrown");
-        } catch (DecoderException e) {
-            // Expected. Move on
-        }
-        try {
-            testcodec.decodeText("=?stuff?=");
+            testcodec.decodeText(s);
             fail("DecoderException should have been thrown");
         } catch (DecoderException e) {
-            // Expected. Move on
-        }
-        try {
-            testcodec.decodeText("=?UTF-8?stuff?=");
-            fail("DecoderException should have been thrown");
-        } catch (DecoderException e) {
-            // Expected. Move on
-        }
-        try {
-            testcodec.decodeText("=?UTF-8?T?stuff");
-            fail("DecoderException should have been thrown");
-        } catch (DecoderException e) {
-            // Expected. Move on
-        }
-        try {
-            testcodec.decodeText("=??T?stuff?=");
-            fail("DecoderException should have been thrown");
-        } catch (DecoderException e) {
-            // Expected. Move on
-        }
-        try {
-            testcodec.decodeText("=?UTF-8??stuff?=");
-            fail("DecoderException should have been thrown");
-        } catch (DecoderException e) {
-            // Expected. Move on
-        }
-        try {
-            testcodec.decodeText("=?UTF-8?W?stuff?=");
-            fail("DecoderException should have been thrown");
-        } catch (DecoderException e) {
-            // Expected. Move on
+            // Expected.
         }
     }
 
+    public void testDecodeInvalid() throws Exception {
+        assertExpectedDecoderException("whatever");
+        assertExpectedDecoderException("=?");
+        assertExpectedDecoderException("?=");
+        assertExpectedDecoderException("==");
+        assertExpectedDecoderException("=??=");
+        assertExpectedDecoderException("=?stuff?=");
+        assertExpectedDecoderException("=?UTF-8??=");
+        assertExpectedDecoderException("=?UTF-8?stuff?=");
+        assertExpectedDecoderException("=?UTF-8?T?stuff");
+        assertExpectedDecoderException("=??T?stuff?=");
+        assertExpectedDecoderException("=?UTF-8??stuff?=");
+        assertExpectedDecoderException("=?UTF-8?W?stuff?=");
+    }
+
 }



Mime
View raw message