KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > codec > StringEncoderAbstractTest


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.codec;
18
19 import junit.framework.TestCase;
20
21 /**
22  * @version $Id: StringEncoderAbstractTest.java,v 1.9 2004/04/19 01:14:29 ggregory Exp $
23  * @author Apache Software Foundation
24  */

25 public abstract class StringEncoderAbstractTest extends TestCase {
26
27     public StringEncoderAbstractTest(String JavaDoc name) {
28         super(name);
29     }
30
31     protected abstract StringEncoder makeEncoder();
32
33     // ------------------------------------------------------------------------
34

35     public void testEncodeEmpty() throws Exception JavaDoc {
36         Encoder encoder = makeEncoder();
37         encoder.encode("");
38         encoder.encode(" ");
39         encoder.encode("\t");
40     }
41
42     public void testEncodeNull() throws Exception JavaDoc {
43         StringEncoder encoder = makeEncoder();
44     
45     try {
46         encoder.encode(null);
47     } catch( EncoderException ee ) {
48         // An exception should be thrown
49
}
50     }
51
52     public void testEncodeWithInvalidObject() throws Exception JavaDoc {
53
54         boolean exceptionThrown = false;
55         try {
56             StringEncoder encoder = makeEncoder();
57             encoder.encode( new Float JavaDoc( 3.4 ) );
58         } catch( Exception JavaDoc e ) {
59             exceptionThrown = true;
60         }
61
62         assertTrue( "An exception was not thrown when we tried to encode " +
63                     "a Float object", exceptionThrown );
64     }
65 }
66
Popular Tags