1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ezmorph.primitive;
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21 import junit.textui.TestRunner;
22 import net.sf.ezmorph.MorphException;
23 import net.sf.ezmorph.Morpher;
24
25
26
27
28 public class CharMorpherTest extends AbstractMorpherTestCase
29 {
30 public static void main( String[] args )
31 {
32 TestRunner.run( suite() );
33 }
34
35 public static Test suite()
36 {
37 TestSuite suite = new TestSuite( CharMorpherTest.class );
38 suite.setName( "CharMorpher Tests" );
39 return suite;
40 }
41
42 private Morpher anotherMorpher;
43 private Morpher anotherMorpherWithDefaultValue;
44 private Morpher morpher;
45 private Morpher morpherWithDefaultValue;
46
47 public CharMorpherTest( String name )
48 {
49 super( name );
50 }
51
52
53
54 public void testCharMorph()
55 {
56 String expected = String.valueOf( "A" );
57 char actual = ((CharMorpher) getMorpher()).morph( expected );
58 assertEquals( 'A', actual );
59 }
60
61 public void testCharMorph_throwException_emptyString()
62 {
63 try{
64 ((CharMorpher) getMorpher()).morph( "" );
65 fail( "Should have thrown an Exception" );
66 }
67 catch( MorphException expected ){
68
69 }
70 }
71
72 public void testCharMorph_throwException_null()
73 {
74 try{
75 ((CharMorpher) getMorpher()).morph( null );
76 fail( "Should have thrown an Exception" );
77 }
78 catch( MorphException expected ){
79
80 }
81 }
82
83 public void testCharMorph_useDefault()
84 {
85 String expected = String.valueOf( "" );
86 char actual = new CharMorpher( 'A' ).morph( expected );
87 assertEquals( 'A', actual );
88 }
89
90 public void testCharMorph_useDefault_null()
91 {
92 char actual = new CharMorpher( 'A' ).morph( null );
93 assertEquals( 'A', actual );
94 }
95
96 protected Morpher getMorpher()
97 {
98 return morpher;
99 }
100
101 protected Morpher getMorpherWithDefaultValue()
102 {
103 return morpherWithDefaultValue;
104 }
105
106 protected Class getMorphsToClass()
107 {
108 return Character.TYPE;
109 }
110
111 protected Morpher getAnotherMorpher()
112 {
113 return anotherMorpher;
114 }
115
116 protected Morpher getAnotherMorpherWithDefaultValue()
117 {
118 return anotherMorpherWithDefaultValue;
119 }
120
121 protected void setUp() throws Exception
122 {
123 morpher = new CharMorpher();
124 morpherWithDefaultValue = new CharMorpher( 'A' );
125 anotherMorpher = new CharMorpher();
126 anotherMorpherWithDefaultValue = new CharMorpher( 'B' );
127 }
128 }