1 16 17 package org.apache.commons.codec; 18 19 import junit.framework.TestCase; 20 21 25 public abstract class StringEncoderAbstractTest extends TestCase { 26 27 public StringEncoderAbstractTest(String name) { 28 super(name); 29 } 30 31 protected abstract StringEncoder makeEncoder(); 32 33 35 public void testEncodeEmpty() throws Exception { 36 Encoder encoder = makeEncoder(); 37 encoder.encode(""); 38 encoder.encode(" "); 39 encoder.encode("\t"); 40 } 41 42 public void testEncodeNull() throws Exception { 43 StringEncoder encoder = makeEncoder(); 44 45 try { 46 encoder.encode(null); 47 } catch( EncoderException ee ) { 48 } 50 } 51 52 public void testEncodeWithInvalidObject() throws Exception { 53 54 boolean exceptionThrown = false; 55 try { 56 StringEncoder encoder = makeEncoder(); 57 encoder.encode( new Float ( 3.4 ) ); 58 } catch( Exception 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 |