1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ezmorph.object;
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 CharacterObjectMorpherTest extends AbstractObjectMorpherTestCase
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( CharacterObjectMorpherTest.class );
38 suite.setName( "CharacterObjectMorpher Tests" );
39 return suite;
40 }
41
42 private CharacterObjectMorpher anotherMorpher;
43 private CharacterObjectMorpher anotherMorpherWithDefaultValue;
44 private CharacterObjectMorpher morpher;
45 private CharacterObjectMorpher morpherWithDefaultValue;
46
47 public CharacterObjectMorpherTest( String name )
48 {
49 super( name );
50 }
51
52
53
54 public void testCharMorph()
55 {
56 String expected = String.valueOf( "A" );
57 Character actual = (Character) new CharacterObjectMorpher().morph( expected );
58 assertEquals( new Character( 'A' ), actual );
59 }
60
61 public void testCharMorph_noConversion()
62 {
63 Character expected = new Character( 'A' );
64 Character actual = (Character) new CharacterObjectMorpher().morph( expected );
65 assertEquals( expected, actual );
66 assertSame( expected, actual );
67 }
68
69 public void testCharMorph_throwException_emptyString()
70 {
71 try{
72 new CharacterObjectMorpher().morph( "" );
73 fail( "Should have thrown an Exception" );
74 }
75 catch( MorphException expected ){
76
77 }
78 }
79
80 public void testCharMorph_throwException_null()
81 {
82 try{
83 new CharacterObjectMorpher().morph( null );
84 fail( "Should have thrown an Exception" );
85 }
86 catch( MorphException expected ){
87
88 }
89 }
90
91 public void testCharMorph_useDefault()
92 {
93 String expected = String.valueOf( "" );
94 Character actual = (Character) new CharacterObjectMorpher( new Character( 'A' ) ).morph( expected );
95 assertEquals( new Character( 'A' ), actual );
96 }
97
98 public void testCharMorph_useDefault_null()
99 {
100 Character actual = (Character) new CharacterObjectMorpher( new Character( 'A' ) ).morph( null );
101 assertEquals( new Character( 'A' ), actual );
102 }
103
104 protected Morpher getAnotherMorpher()
105 {
106 return anotherMorpher;
107 }
108
109 protected Morpher getAnotherMorpherWithDefaultValue()
110 {
111 return anotherMorpherWithDefaultValue;
112 }
113
114 protected Morpher getMorpher()
115 {
116 return morpher;
117 }
118
119 protected Morpher getMorpherWithDefaultValue()
120 {
121 return morpherWithDefaultValue;
122 }
123
124 protected void setUp() throws Exception
125 {
126 morpher = new CharacterObjectMorpher();
127 morpherWithDefaultValue = new CharacterObjectMorpher( new Character( 'A' ) );
128 anotherMorpher = new CharacterObjectMorpher();
129 anotherMorpherWithDefaultValue = new CharacterObjectMorpher( new Character( 'B' ) );
130 }
131 }