1 16 17 package org.apache.commons.codec; 18 19 import java.util.Arrays ; 20 import java.util.Collections ; 21 import java.util.List ; 22 23 import junit.framework.TestCase; 24 import org.apache.commons.codec.language.DoubleMetaphone; 25 import org.apache.commons.codec.language.Soundex; 26 27 33 public class StringEncoderComparatorTest extends TestCase { 34 35 public StringEncoderComparatorTest(String name) { 36 super(name); 37 } 38 39 public void testComparatorNoArgCon() throws Exception { 40 new StringEncoderComparator(); 41 } 42 43 public void testComparatorWithSoundex() throws Exception { 44 StringEncoderComparator sCompare = 45 new StringEncoderComparator( new Soundex() ); 46 47 assertTrue( "O'Brien and O'Brian didn't come out with " + 48 "the same Soundex, something must be wrong here", 49 0 == sCompare.compare( "O'Brien", "O'Brian" ) ); 50 } 51 52 public void testComparatorWithDoubleMetaphone() throws Exception { 53 StringEncoderComparator sCompare = 54 new StringEncoderComparator( new DoubleMetaphone() ); 55 56 String [] testArray = { "Jordan", "Sosa", "Prior", "Pryor" }; 57 List testList = Arrays.asList( testArray ); 58 59 String [] controlArray = { "Jordan", "Prior", "Pryor", "Sosa" }; 60 61 Collections.sort( testList, sCompare); 62 63 String [] resultArray = (String []) testList.toArray(new String [0]); 64 65 for( int i = 0; i < resultArray.length; i++) { 66 assertEquals( "Result Array not Equal to Control Array at index: " + i, controlArray[i], resultArray[i] ); 67 } 68 } 69 70 public void testComparatorWithDoubleMetaphoneAndInvalidInput() throws Exception { 71 StringEncoderComparator sCompare = 72 new StringEncoderComparator( new DoubleMetaphone() ); 73 74 int compare = sCompare.compare(new Double (3.0), new Long (3)); 75 assertEquals( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code", 76 0, compare); 77 78 } 79 } 80 | Popular Tags |