2424import java .util .HashSet ;
2525import java .util .Locale ;
2626import java .util .Set ;
27+ import java .util .stream .Stream ;
2728
2829import org .apache .commons .codec .AbstractStringEncoderTest ;
2930import org .apache .commons .codec .EncoderException ;
3031import org .junit .jupiter .api .AfterAll ;
3132import org .junit .jupiter .api .Test ;
33+ import org .junit .jupiter .params .ParameterizedTest ;
34+ import org .junit .jupiter .params .provider .Arguments ;
35+ import org .junit .jupiter .params .provider .MethodSource ;
3236import org .opentest4j .AssertionFailedError ;
3337
3438/**
@@ -99,6 +103,110 @@ public static void main(final String[] args) {
99103 }
100104 }
101105
106+ static Stream <Arguments > testBasicEncoding () {
107+ // @formatter:off
108+ return Stream .of (
109+ Arguments .arguments ("01" , "Aabjoe" ),
110+ Arguments .arguments ("0856" , "Aaclan" ),
111+ Arguments .arguments ("04567" , "Aychlmajr" ) // CODEC-122
112+ );
113+ // @formatter:on
114+ }
115+
116+ static Stream <Arguments > testEdgeCases () {
117+ // @formatter:off
118+ return Stream .of (
119+ Arguments .arguments ("a" , "0" ),
120+ Arguments .arguments ("e" , "0" ),
121+ Arguments .arguments ("i" , "0" ),
122+ Arguments .arguments ("o" , "0" ),
123+ Arguments .arguments ("u" , "0" ),
124+ Arguments .arguments ("\u00E4 " , "0" ), // a-umlaut
125+ Arguments .arguments ("\u00F6 " , "0" ), // o-umlaut
126+ Arguments .arguments ("\u00FC " , "0" ), // u-umlaut
127+ Arguments .arguments ("\u00DF " , "8" ), // small sharp s
128+ Arguments .arguments ("aa" , "0" ),
129+ Arguments .arguments ("ha" , "0" ),
130+ Arguments .arguments ("h" , "" ),
131+ Arguments .arguments ("aha" , "0" ),
132+ Arguments .arguments ("b" , "1" ),
133+ Arguments .arguments ("p" , "1" ),
134+ Arguments .arguments ("ph" , "3" ),
135+ Arguments .arguments ("f" , "3" ),
136+ Arguments .arguments ("v" , "3" ),
137+ Arguments .arguments ("w" , "3" ),
138+ Arguments .arguments ("g" , "4" ),
139+ Arguments .arguments ("k" , "4" ),
140+ Arguments .arguments ("q" , "4" ),
141+ Arguments .arguments ("x" , "48" ),
142+ Arguments .arguments ("ax" , "048" ),
143+ Arguments .arguments ("cx" , "48" ),
144+ Arguments .arguments ("l" , "5" ),
145+ Arguments .arguments ("cl" , "45" ),
146+ Arguments .arguments ("acl" , "085" ),
147+ Arguments .arguments ("mn" , "6" ),
148+ Arguments .arguments ("{mn}" , "6" ), // test chars above Z
149+ Arguments .arguments ("r" , "7" )
150+ );
151+ // @formatter:on
152+ }
153+
154+ static Stream <Arguments > testExamples () {
155+ // @formatter:off
156+ return Stream .of (
157+ Arguments .arguments ("m\u00DC ller" , "657" ), // mÜller - why upper case U-umlaut?
158+ Arguments .arguments ("m\u00FC ller" , "657" ), // müller - add equivalent lower-case
159+ Arguments .arguments ("schmidt" , "862" ),
160+ Arguments .arguments ("schneider" , "8627" ),
161+ Arguments .arguments ("fischer" , "387" ),
162+ Arguments .arguments ("weber" , "317" ),
163+ Arguments .arguments ("wagner" , "3467" ),
164+ Arguments .arguments ("becker" , "147" ),
165+ Arguments .arguments ("hoffmann" , "0366" ),
166+ Arguments .arguments ("sch\u00C4 fer" , "837" ), // schÄfer - why upper case A-umlaut ?
167+ Arguments .arguments ("sch\u00e4 fer" , "837" ), // schäfer - add equivalent lower-case
168+ Arguments .arguments ("Breschnew" , "17863" ),
169+ Arguments .arguments ("Wikipedia" , "3412" ),
170+ Arguments .arguments ("peter" , "127" ),
171+ Arguments .arguments ("pharma" , "376" ),
172+ Arguments .arguments ("m\u00f6 nchengladbach" , "664645214" ), // mönchengladbach
173+ Arguments .arguments ("deutsch" , "28" ),
174+ Arguments .arguments ("deutz" , "28" ),
175+ Arguments .arguments ("hamburg" , "06174" ),
176+ Arguments .arguments ("hannover" , "0637" ),
177+ Arguments .arguments ("christstollen" , "478256" ),
178+ Arguments .arguments ("Xanthippe" , "48621" ),
179+ Arguments .arguments ("Zacharias" , "8478" ),
180+ Arguments .arguments ("Holzbau" , "0581" ),
181+ Arguments .arguments ("matsch" , "68" ),
182+ Arguments .arguments ("matz" , "68" ),
183+ Arguments .arguments ("Arbeitsamt" , "071862" ),
184+ Arguments .arguments ("Eberhard" , "01772" ),
185+ Arguments .arguments ("Eberhardt" , "01772" ),
186+ Arguments .arguments ("Celsius" , "8588" ),
187+ Arguments .arguments ("Ace" , "08" ),
188+ Arguments .arguments ("shch" , "84" ), // CODEC-254
189+ Arguments .arguments ("xch" , "484" ), // CODEC-255
190+ Arguments .arguments ("heithabu" , "021" )
191+ );
192+ // @formatter:on
193+ }
194+
195+ static Stream <Arguments > testIsEncodeEquals () {
196+ // @formatter:off
197+ return Stream .of (
198+ Arguments .arguments ("Muller" , "M\u00fc ller" ), // Müller
199+ Arguments .arguments ("Meyer" , "Mayr" ),
200+ Arguments .arguments ("house" , "house" ),
201+ Arguments .arguments ("House" , "house" ),
202+ Arguments .arguments ("Haus" , "house" ),
203+ Arguments .arguments ("ganz" , "Gans" ),
204+ Arguments .arguments ("ganz" , "G\u00e4 nse" ), // Gänse
205+ Arguments .arguments ("Miyagi" , "Miyako" )
206+ );
207+ // @formatter:on
208+ }
209+
102210 @ Override
103211 // Capture test strings for later checking
104212 public void checkEncoding (final String expected , final String source ) throws EncoderException {
@@ -112,24 +220,10 @@ protected ColognePhonetic createStringEncoder() {
112220 return new ColognePhonetic ();
113221 }
114222
115- @ Test
116- void testAabjoe () throws EncoderException {
117- checkEncoding ("01" , "Aabjoe" );
118- }
119-
120- @ Test
121- void testAaclan () throws EncoderException {
122- checkEncoding ("0856" , "Aaclan" );
123- }
124-
125- /**
126- * Tests [CODEC-122]
127- *
128- * @throws EncoderException for some failure scenarios
129- */
130- @ Test
131- void testAychlmajrCodec122 () throws EncoderException {
132- checkEncoding ("04567" , "Aychlmajr" );
223+ @ ParameterizedTest
224+ @ MethodSource
225+ void testBasicEncoding (final String expected , final String source ) throws EncoderException {
226+ checkEncoding (expected , source );
133227 }
134228
135229 @ Test
@@ -138,87 +232,16 @@ void testCanFail() {
138232 assertThrows (AssertionFailedError .class , () -> checkEncoding ("/" , "Fehler" ));
139233 }
140234
141- @ Test
142- void testEdgeCases () throws EncoderException {
143- // @formatter:off
144- final String [][] data = {
145- { "a" , "0" },
146- { "e" , "0" },
147- { "i" , "0" },
148- { "o" , "0" },
149- { "u" , "0" },
150- { "\u00E4 " , "0" }, // a-umlaut
151- { "\u00F6 " , "0" }, // o-umlaut
152- { "\u00FC " , "0" }, // u-umlaut
153- { "\u00DF " , "8" }, // small sharp s
154- { "aa" , "0" },
155- { "ha" , "0" },
156- { "h" , "" },
157- { "aha" , "0" },
158- { "b" , "1" },
159- { "p" , "1" },
160- { "ph" , "3" },
161- { "f" , "3" },
162- { "v" , "3" },
163- { "w" , "3" },
164- { "g" , "4" },
165- { "k" , "4" },
166- { "q" , "4" },
167- { "x" , "48" },
168- { "ax" , "048" },
169- { "cx" , "48" },
170- { "l" , "5" },
171- { "cl" , "45" },
172- { "acl" , "085" },
173- { "mn" , "6" },
174- { "{mn}" , "6" }, // test chars above Z
175- { "r" , "7" }
176- };
177- // @formatter:on
178- checkEncodings (data );
235+ @ ParameterizedTest
236+ @ MethodSource
237+ void testEdgeCases (final String source , final String expected ) throws EncoderException {
238+ checkEncoding (expected , source );
179239 }
180240
181- @ Test
182- void testExamples () throws EncoderException {
183- // @formatter:off
184- final String [][] data = {
185- { "m\u00DC ller" , "657" }, // mÜller - why upper case U-umlaut?
186- { "m\u00FC ller" , "657" }, // müller - add equivalent lower-case
187- { "schmidt" , "862" },
188- { "schneider" , "8627" },
189- { "fischer" , "387" },
190- { "weber" , "317" },
191- { "wagner" , "3467" },
192- { "becker" , "147" },
193- { "hoffmann" , "0366" },
194- { "sch\u00C4 fer" , "837" }, // schÄfer - why upper case A-umlaut ?
195- { "sch\u00e4 fer" , "837" }, // schäfer - add equivalent lower-case
196- { "Breschnew" , "17863" },
197- { "Wikipedia" , "3412" },
198- { "peter" , "127" },
199- { "pharma" , "376" },
200- { "m\u00f6 nchengladbach" , "664645214" }, // mönchengladbach
201- { "deutsch" , "28" },
202- { "deutz" , "28" },
203- { "hamburg" , "06174" },
204- { "hannover" , "0637" },
205- { "christstollen" , "478256" },
206- { "Xanthippe" , "48621" },
207- { "Zacharias" , "8478" },
208- { "Holzbau" , "0581" },
209- { "matsch" , "68" },
210- { "matz" , "68" },
211- { "Arbeitsamt" , "071862" },
212- { "Eberhard" , "01772" },
213- { "Eberhardt" , "01772" },
214- { "Celsius" , "8588" },
215- { "Ace" , "08" },
216- { "shch" , "84" }, // CODEC-254
217- { "xch" , "484" }, // CODEC-255
218- { "heithabu" , "021" }
219- };
220- // @formatter:on
221- checkEncodings (data );
241+ @ ParameterizedTest
242+ @ MethodSource
243+ void testExamples (final String source , final String expected ) throws EncoderException {
244+ checkEncoding (expected , source );
222245 }
223246
224247 @ Test
@@ -227,24 +250,11 @@ void testHyphen() throws EncoderException {
227250 checkEncodings (data );
228251 }
229252
230- @ Test
231- void testIsEncodeEquals () {
232- //@formatter:off
233- final String [][] data = {
234- { "Muller" , "M\u00fc ller" }, // Müller
235- { "Meyer" , "Mayr" },
236- { "house" , "house" },
237- { "House" , "house" },
238- { "Haus" , "house" },
239- { "ganz" , "Gans" },
240- { "ganz" , "G\u00e4 nse" }, // Gänse
241- { "Miyagi" , "Miyako" }
242- };
243- //@formatter:on
244- for (final String [] element : data ) {
245- final boolean encodeEqual = getStringEncoder ().isEncodeEqual (element [1 ], element [0 ]);
246- assertTrue (encodeEqual , element [1 ] + " != " + element [0 ]);
247- }
253+ @ ParameterizedTest
254+ @ MethodSource
255+ void testIsEncodeEquals (final String source , final String expected ) {
256+ final boolean encodeEqual = getStringEncoder ().isEncodeEqual (expected , source );
257+ assertTrue (encodeEqual , () -> expected + " != " + source );
248258 }
249259
250260 @ Test
0 commit comments