commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1154276 - /commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
Date Fri, 05 Aug 2011 15:48:13 GMT
Author: ggregory
Date: Fri Aug  5 15:48:13 2011
New Revision: 1154276

URL: http://svn.apache.org/viewvc?rev=1154276&view=rev
Log:
Bullet-proofing: Tests we do not blow up for any char input.

Modified:
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java?rev=1154276&r1=1154275&r2=1154276&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
Fri Aug  5 15:48:13 2011
@@ -38,16 +38,34 @@ public class BeiderMorseEncoderTest exte
         Assert.assertFalse(value, bmpm.encode(value).equals(""));
     }
 
+    private BeiderMorseEncoder createGenericApproxEncoder() {
+        BeiderMorseEncoder encoder = new BeiderMorseEncoder();
+        encoder.setNameType(NameType.GENERIC);
+        encoder.setRuleType(RuleType.APPROX);
+        return encoder;
+    }
+
     @Override
     protected StringEncoder createStringEncoder() {
         return new BeiderMorseEncoder();
     }
 
+    /**
+     * Tests we do not blow up.
+     * 
+     * @throws EncoderException
+     */
+    @Test
+    public void testAllChars() throws EncoderException {
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
+        for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
+            bmpm.encode("" + c);
+        }
+    }
+
     @Test
     public void testAsciiEncodeNotEmpty1Letter() throws EncoderException {
-        BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
-        bmpm.setNameType(NameType.GENERIC);
-        bmpm.setRuleType(RuleType.APPROX);
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
         for (char c = 'a'; c <= 'z'; c++) {
             final String value = "" + c;
             final String valueU = value.toUpperCase();
@@ -58,9 +76,7 @@ public class BeiderMorseEncoderTest exte
 
     @Test
     public void testAsciiEncodeNotEmpty2Letters() throws EncoderException {
-        BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
-        bmpm.setNameType(NameType.GENERIC);
-        bmpm.setRuleType(RuleType.APPROX);
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
         for (char c1 = 'a'; c1 <= 'z'; c1++) {
             for (char c2 = 'a'; c2 <= 'z'; c2++) {
                 final String value = new String(new char[] { c1, c2 });
@@ -73,9 +89,7 @@ public class BeiderMorseEncoderTest exte
 
     @Test
     public void testEncodeAtzNotEmpty() throws EncoderException {
-        BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
-        bmpm.setNameType(NameType.GENERIC);
-        bmpm.setRuleType(RuleType.APPROX);
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
         String[] names = { "ácz", "átz", "Ignácz", "Ignátz", "Ignác" };
         for (String name : names) {
             assertNotEmpty(bmpm, name);
@@ -90,9 +104,7 @@ public class BeiderMorseEncoderTest exte
      */
     @Test
     public void testEncodeGna() throws EncoderException {
-        BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
-        bmpm.setNameType(NameType.GENERIC);
-        bmpm.setRuleType(RuleType.APPROX);
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
         bmpm.encode("gna");
     }
 
@@ -113,9 +125,7 @@ public class BeiderMorseEncoderTest exte
 
     @Test(timeout = 10000L)
     public void testLongestEnglishSurname() throws EncoderException {
-        BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
-        bmpm.setNameType(NameType.GENERIC);
-        bmpm.setRuleType(RuleType.APPROX);
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
         bmpm.encode("MacGhilleseatheanaich");
     }
 
@@ -155,9 +165,7 @@ public class BeiderMorseEncoderTest exte
     @Test(timeout = 20000L)
     public void testSpeedCheck() throws EncoderException {
         char[] chars = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'o', 'u' };
-        BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
-        bmpm.setNameType(NameType.GENERIC);
-        bmpm.setRuleType(RuleType.APPROX);
+        BeiderMorseEncoder bmpm = createGenericApproxEncoder();
         StringBuffer stringBuffer = new StringBuffer();
         Random rand = new Random();
         stringBuffer.append(chars[rand.nextInt(chars.length)]);



Mime
View raw message