1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */ 
17  
18  package org.apache.commons.codec;
19  
20  import junit.framework.TestCase;
21  
22  /**
23   * @author Apache Software Foundation
24   * @version $Id: StringEncoderAbstractTest.java 618557 2008-02-05 06:00:44Z bayard $
25   */
26  public abstract class StringEncoderAbstractTest extends TestCase {
27  
28      public StringEncoderAbstractTest(String name) {
29          super(name);
30      }
31  
32      protected abstract StringEncoder makeEncoder();
33  
34      // ------------------------------------------------------------------------
35  
36      public void testEncodeEmpty() throws Exception {
37          Encoder encoder = makeEncoder();
38          encoder.encode("");
39          encoder.encode(" ");
40          encoder.encode("\t");
41      }        
42  
43      public void testEncodeNull() throws Exception {
44          StringEncoder encoder = makeEncoder();
45          
46          try {
47              encoder.encode(null);
48          } catch( EncoderException ee ) {
49              // An exception should be thrown
50          }
51      }        
52  
53      public void testEncodeWithInvalidObject() throws Exception {
54  
55          boolean exceptionThrown = false;
56          try {
57              StringEncoder encoder = makeEncoder();
58              encoder.encode( new Float( 3.4 ) );
59          } catch( Exception e ) {
60              exceptionThrown = true;
61          }
62  
63          assertTrue( "An exception was not thrown when we tried to encode " +
64                      "a Float object", exceptionThrown );
65      }
66  }