commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1075410 - in /commons/proper/codec/trunk/src/test/org/apache/commons/codec: StringEncoderAbstractTest.java language/CaverphoneTest.java language/ColognePhoneticTest.java
Date Mon, 28 Feb 2011 16:27:12 GMT
Author: ggregory
Date: Mon Feb 28 16:27:12 2011
New Revision: 1075410

URL: http://svn.apache.org/viewvc?rev=1075410&view=rev
Log:
Refactor encoding tests.

Modified:
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/CaverphoneTest.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/ColognePhoneticTest.java

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java?rev=1075410&r1=1075409&r2=1075410&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
Mon Feb 28 16:27:12 2011
@@ -19,6 +19,7 @@ package org.apache.commons.codec;
 
 import java.util.Locale;
 
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 /**
@@ -27,6 +28,8 @@ import junit.framework.TestCase;
  */
 public abstract class StringEncoderAbstractTest extends TestCase {
 
+    protected StringEncoder stringEncoder = createEncoder();
+
     public StringEncoderAbstractTest(String name) {
         super(name);
     }
@@ -97,4 +100,20 @@ public abstract class StringEncoderAbstr
         }
     }
 
+    protected void checkEncodings(String[][] data) throws EncoderException {
+        for (int i = 0; i < data.length; i++) {
+            this.checkEncoding(data[i][1], data[i][0]);
+        }
+    }
+
+    protected void checkEncodingVariations(String expected, String data[]) throws EncoderException
{
+        for (int i = 0; i < data.length; i++) {
+            this.checkEncoding(expected, data[i]);
+        }
+    }
+
+    public void checkEncoding(String expected, String source) throws EncoderException {
+        Assert.assertEquals("Source: " + source, expected, this.stringEncoder.encode(source));
+    }
+
 }

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/CaverphoneTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/CaverphoneTest.java?rev=1075410&r1=1075409&r2=1075410&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/CaverphoneTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/CaverphoneTest.java
Mon Feb 28 16:27:12 2011
@@ -17,6 +17,7 @@
 
 package org.apache.commons.codec.language;
 
+import org.apache.commons.codec.EncoderException;
 import org.apache.commons.codec.StringEncoder;
 import org.apache.commons.codec.StringEncoderAbstractTest;
 
@@ -34,24 +35,19 @@ public class CaverphoneTest extends Stri
         return new Caverphone();
     }
 
-    public void testSpecificationExamples() {
-        Caverphone caverphone = new Caverphone();
+    public void testSpecificationExamples() throws EncoderException {
         String[][] data = {
-            {"Stevenson", "STFNSN1111"},
-            {"Peter",     "PTA1111111"},
-            {"ready",     "RTA1111111"},
-            {"social",    "SSA1111111"},
-            {"able",      "APA1111111"},
-            {"Tedder",    "TTA1111111"},
-            {"Karleen",   "KLN1111111"},
-            {"Dyun",      "TN11111111"},
-        };
-
-        for(int i=0; i<data.length; i++) {
-            assertEquals( data[i][1], caverphone.caverphone(data[i][0]) );
-        }
+            {"Peter", "PTA1111111"},
+            {"ready", "RTA1111111"},
+            {"social", "SSA1111111"},
+            {"able", "APA1111111"},
+            {"Tedder", "TTA1111111"},
+            {"Karleen", "KLN1111111"},
+            {"Dyun", "TN11111111"},};
+        this.checkEncodings(data);
     }
 
+    // Caverphone Revisited
     public void testIsCaverphoneEquals() {
         Caverphone caverphone = new Caverphone();
         assertFalse("Caverphone encodings should not be equal", caverphone.isCaverphoneEqual("Peter",
"Stevenson"));

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/ColognePhoneticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/ColognePhoneticTest.java?rev=1075410&r1=1075409&r2=1075410&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/ColognePhoneticTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/ColognePhoneticTest.java
Mon Feb 28 16:27:12 2011
@@ -17,48 +17,30 @@
 
 package org.apache.commons.codec.language;
 
-import junit.framework.Assert;
 
+import org.apache.commons.codec.EncoderException;
 import org.apache.commons.codec.StringEncoder;
 import org.apache.commons.codec.StringEncoderAbstractTest;
 
 public class ColognePhoneticTest extends StringEncoderAbstractTest {
 
-    private ColognePhonetic colognePhonetic = new ColognePhonetic();
-
     public ColognePhoneticTest(String name) {
         super(name);
     }
 
-    public void checkEncoding(String expected, String source) {
-        Assert.assertEquals("Source: " + source, expected, this.colognePhonetic.encode(source));
-    }
-
-    private void checkEncodings(String[][] data) {
-        for (int i = 0; i < data.length; i++) {
-            this.checkEncoding(data[i][1], data[i][0]);
-        }
-    }
-
-    private void checkEncodingVariations(String expected, String data[]) {
-        for (int i = 0; i < data.length; i++) {
-            this.checkEncoding(expected, data[i]);
-        }
-    }
-
     protected StringEncoder createEncoder() {
         return new ColognePhonetic();
     }
 
-    public void testAabjoe() {
+    public void testAabjoe() throws EncoderException {
         this.checkEncoding("01", "Aabjoe");
     }
 
-    public void testAaclan() {
+    public void testAaclan() throws EncoderException {
         this.checkEncoding("0856", "Aaclan");
     }
 
-    public void testEdgeCases() {
+    public void testEdgeCases() throws EncoderException {
         String[][] data = {
             {"a", "0"},
             {"e", "0"},
@@ -92,7 +74,7 @@ public class ColognePhoneticTest extends
         this.checkEncodings(data);
     }
 
-    public void testExamples() {
+    public void testExamples() throws EncoderException {
         String[][] data = {
             {"m\u00DCller", "657"},
             {"schmidt", "862"},
@@ -125,7 +107,7 @@ public class ColognePhoneticTest extends
         this.checkEncodings(data);
     }
 
-    public void testHyphen() {
+    public void testHyphen() throws EncoderException {
         String[][] data = {{"bergisch-gladbach", "174845214"}, {"Müller-Lüdenscheidt",
"65752682"},
             // From the Javadoc example:
             {"Müller-Lüdenscheidt", "65752682"}};
@@ -143,17 +125,17 @@ public class ColognePhoneticTest extends
             {"ganz", "Gänse"},
             {"Miyagi", "Miyako"}};
         for (int i = 0; i < data.length; i++) {
-            this.colognePhonetic.isEncodeEqual(data[i][1], data[i][0]);
+            ((ColognePhonetic) this.stringEncoder).isEncodeEqual(data[i][1], data[i][0]);
         }
     }
 
-    public void testVariationsMeyer() {
-        String data[] = {"Meier", "Maier", "Mair", "Meyer", "Meyr", "Mejer", "Major"};
-        this.checkEncodingVariations("67", data);
-    }
-
-    public void testVariationsMella() {
+    public void testVariationsMella() throws EncoderException {
         String data[] = {"mella", "milah", "moulla", "mellah", "muehle", "mule"};
         this.checkEncodingVariations("65", data);
     }
+
+    public void testVariationsMeyer() throws EncoderException {
+        String data[] = {"Meier", "Maier", "Mair", "Meyer", "Meyr", "Mejer", "Major"};
+        this.checkEncodingVariations("67", data);
+    }
 }



Mime
View raw message