1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ezmorph.array;
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.test.ArrayAssertions;
24
25
26
27
28 public class CharArrayMorpherTest extends AbstractArrayMorpherTestCase
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( CharArrayMorpherTest.class );
38 suite.setName( "CharArrayMorpher Tests" );
39 return suite;
40 }
41
42 private CharArrayMorpher anotherMorpher;
43 private CharArrayMorpher anotherMorpherWithDefaultValue;
44 private CharArrayMorpher morpher;
45 private CharArrayMorpher morpherWithDefaultValue;
46
47 public CharArrayMorpherTest( String name )
48 {
49 super( name );
50 }
51
52
53
54 public void testMorph_charArray()
55 {
56 char[] expected = { '1', '2', '3' };
57 char[] actual = (char[]) morpher.morph( expected );
58 ArrayAssertions.assertEquals( expected, actual );
59 }
60
61 public void testMorph_charArray_threedims()
62 {
63 char[][][] expected = { { { '1' }, { '2' } }, { { '3' }, { '4' } } };
64 char[][][] actual = (char[][][]) morpher.morph( expected );
65 ArrayAssertions.assertEquals( expected, actual );
66 }
67
68 public void testMorph_charArray_twodims()
69 {
70 char[][] expected = { { '1', '2', '3' }, { '4', '5', '6' } };
71 char[][] actual = (char[][]) morpher.morph( expected );
72 ArrayAssertions.assertEquals( expected, actual );
73 }
74
75 public void testMorph_illegalArgument()
76 {
77 try{
78
79 morpher.morph( "" );
80 }
81 catch( MorphException expected ){
82
83 }
84 }
85
86 public void testMorph_null()
87 {
88 assertNull( morpher.morph( null ) );
89 }
90
91 public void testMorph_strings()
92 {
93 String[] expected = { "1", "2", "3.3" };
94 char[] actual = (char[]) morpher.morph( expected );
95 ArrayAssertions.assertEquals( new char[] { '1', '2', '3' }, actual );
96 }
97
98 public void testMorph_strings_twodims()
99 {
100 String[][] expected = { { "1", "2", "3.3" }, { "4", "5", "6.6" } };
101 char[][] actual = (char[][]) morpher.morph( expected );
102 ArrayAssertions.assertEquals( new char[][] { { '1', '2', '3' }, { '4', '5', '6' } }, actual );
103 }
104
105 public void testMorph_throwException()
106 {
107 try{
108 new CharArrayMorpher().morph( new String[] { null } );
109 fail( "Should have thrown an Exception" );
110 }
111 catch( MorphException expected ){
112
113 }
114 }
115
116 protected AbstractArrayMorpher getAnotherMorpher()
117 {
118 return anotherMorpher;
119 }
120
121 protected AbstractArrayMorpher getAnotherMorpherWithDefaultValue()
122 {
123 return anotherMorpherWithDefaultValue;
124 }
125
126 protected AbstractArrayMorpher getMorpher()
127 {
128 return morpher;
129 }
130
131 protected AbstractArrayMorpher getMorpherWithDefaultValue()
132 {
133 return morpherWithDefaultValue;
134 }
135
136 protected Class getMorphsToClass()
137 {
138 return char[].class;
139 }
140
141 protected void setUp() throws Exception
142 {
143 morpher = new CharArrayMorpher();
144 morpherWithDefaultValue = new CharArrayMorpher( 'A' );
145 anotherMorpher = new CharArrayMorpher();
146 anotherMorpherWithDefaultValue = new CharArrayMorpher( 'B' );
147 }
148 }