2828 */
2929public abstract class StringEncoderAbstractTest extends TestCase {
3030
31- protected StringEncoder stringEncoder = createEncoder ();
31+ protected StringEncoder stringEncoder = this . createStringEncoder ();
3232
3333 public StringEncoderAbstractTest (String name ) {
3434 super (name );
3535 }
3636
37- protected abstract StringEncoder createEncoder ();
37+ public void checkEncoding (String expected , String source ) throws EncoderException {
38+ Assert .assertEquals ("Source: " + source , expected , this .getStringEncoder ().encode (source ));
39+ }
3840
39- // ------------------------------------------------------------------------
41+ protected void checkEncodings (String [][] data ) throws EncoderException {
42+ for (int i = 0 ; i < data .length ; i ++) {
43+ this .checkEncoding (data [i ][1 ], data [i ][0 ]);
44+ }
45+ }
46+
47+ protected void checkEncodingVariations (String expected , String data []) throws EncoderException {
48+ for (int i = 0 ; i < data .length ; i ++) {
49+ this .checkEncoding (expected , data [i ]);
50+ }
51+ }
52+
53+ protected abstract StringEncoder createStringEncoder ();
54+
55+ public StringEncoder getStringEncoder () {
56+ return this .stringEncoder ;
57+ }
4058
4159 public void testEncodeEmpty () throws Exception {
42- Encoder encoder = createEncoder ();
60+ Encoder encoder = this . getStringEncoder ();
4361 encoder .encode ("" );
4462 encoder .encode (" " );
4563 encoder .encode ("\t " );
46- }
64+ }
4765
4866 public void testEncodeNull () throws Exception {
49- StringEncoder encoder = createEncoder ();
50-
67+ StringEncoder encoder = this .getStringEncoder ();
5168 try {
5269 encoder .encode (null );
5370 } catch (EncoderException ee ) {
5471 // An exception should be thrown
5572 }
56- }
73+ }
5774
5875 public void testEncodeWithInvalidObject () throws Exception {
5976
6077 boolean exceptionThrown = false ;
6178 try {
62- StringEncoder encoder = createEncoder ();
63- encoder .encode ( new Float ( 3.4 ) );
79+ StringEncoder encoder = this . getStringEncoder ();
80+ encoder .encode (new Float (3.4 ) );
6481 } catch (Exception e ) {
6582 exceptionThrown = true ;
6683 }
6784
68- assertTrue ( "An exception was not thrown when we tried to encode " +
69- "a Float object" , exceptionThrown );
85+ Assert .assertTrue ("An exception was not thrown when we tried to encode " + "a Float object" , exceptionThrown );
7086 }
7187
7288 public void testLocaleIndependence () throws Exception {
73- StringEncoder encoder = createEncoder ();
89+ StringEncoder encoder = this . getStringEncoder ();
7490
75- String [] data = { "I" , "i" , };
91+ String [] data = {"I" , "i" ,};
7692
7793 Locale orig = Locale .getDefault ();
78- Locale [] locales = { Locale .ENGLISH , new Locale ("tr" ), Locale .getDefault () };
94+ Locale [] locales = {Locale .ENGLISH , new Locale ("tr" ), Locale .getDefault ()};
7995
8096 try {
8197 for (int i = 0 ; i < data .length ; i ++) {
@@ -89,9 +105,9 @@ public void testLocaleIndependence() throws Exception {
89105 try {
90106 cur = encoder .encode (data [i ]);
91107 } catch (Exception e ) {
92- fail (Locale .getDefault ().toString () + ": " + e .getMessage ());
108+ Assert . fail (Locale .getDefault ().toString () + ": " + e .getMessage ());
93109 }
94- assertEquals (Locale .getDefault ().toString () + ": " , ref , cur );
110+ Assert . assertEquals (Locale .getDefault ().toString () + ": " , ref , cur );
95111 }
96112 }
97113 }
@@ -100,20 +116,4 @@ public void testLocaleIndependence() throws Exception {
100116 }
101117 }
102118
103- protected void checkEncodings (String [][] data ) throws EncoderException {
104- for (int i = 0 ; i < data .length ; i ++) {
105- this .checkEncoding (data [i ][1 ], data [i ][0 ]);
106- }
107- }
108-
109- protected void checkEncodingVariations (String expected , String data []) throws EncoderException {
110- for (int i = 0 ; i < data .length ; i ++) {
111- this .checkEncoding (expected , data [i ]);
112- }
113- }
114-
115- public void checkEncoding (String expected , String source ) throws EncoderException {
116- Assert .assertEquals ("Source: " + source , expected , this .stringEncoder .encode (source ));
117- }
118-
119119}
0 commit comments