5757
5858package org .apache .commons .codec ;
5959
60+ import java .util .Arrays ;
61+ import java .util .Collections ;
62+ import java .util .List ;
63+
6064import junit .framework .TestCase ;
6165
66+ import org .apache .commons .codec .language .DoubleMetaphone ;
6267import org .apache .commons .codec .language .Soundex ;
6368
6469/**
65- * @version $Revision: 1.5 $ $Date: 2003/10/05 21:45:49 $
70+ * Test cases for the StingEncoderComparator.
71+ *
72+ * @version $Revision: 1.6 $ $Date: 2003/10/12 01:35:17 $
6673 * @author Tim O'Brien
6774 */
6875public class StringEncoderComparatorTest extends TestCase {
@@ -82,7 +89,33 @@ public void testComparatorWithSoundex() throws Exception {
8289 assertTrue ( "O'Brien and O'Brian didn't come out with " +
8390 "the same Soundex, something must be wrong here" ,
8491 0 == sCompare .compare ( "O'Brien" , "O'Brian" ) );
92+ }
93+
94+ public void testComparatorWithDoubleMetaphone () throws Exception {
95+ StringEncoderComparator sCompare =
96+ new StringEncoderComparator ( new DoubleMetaphone () );
97+
98+ String [] testArray = { "Jordan" , "Sosa" , "Prior" , "Pryor" };
99+ List testList = Arrays .asList ( testArray );
100+
101+ String [] controlArray = { "Jordan" , "Prior" , "Pryor" , "Sosa" };
85102
103+ Collections .sort ( testList , sCompare );
104+
105+ String [] resultArray = (String []) testList .toArray (new String [0 ]);
106+
107+ for ( int i = 0 ; i < resultArray .length ; i ++) {
108+ assertEquals ( "Result Array not Equal to Control Array at index: " + i , controlArray [i ], resultArray [i ] );
109+ }
86110 }
87111
112+ public void testComparatorWithDoubleMetaphoneAndInvalidInput () throws Exception {
113+ StringEncoderComparator sCompare =
114+ new StringEncoderComparator ( new DoubleMetaphone () );
115+
116+ int compare = sCompare .compare (new Double (3.0 ), new Long (3 ));
117+ assertEquals ( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code" ,
118+ 0 , compare );
119+
120+ }
88121}
0 commit comments