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 IntArrayMorpherTest 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( IntArrayMorpherTest.class );
38 suite.setName( "IntArrayMorpher Tests" );
39 return suite;
40 }
41
42 private IntArrayMorpher anotherMorpher;
43 private IntArrayMorpher anotherMorpherWithDefaultValue;
44 private IntArrayMorpher morpher;
45 private IntArrayMorpher morpherWithDefaultValue;
46
47 public IntArrayMorpherTest( String name )
48 {
49 super( name );
50 }
51
52
53
54 public void testMorph_illegalArgument()
55 {
56 try{
57
58 morpher.morph( "" );
59 }
60 catch( MorphException expected ){
61
62 }
63 }
64
65 public void testMorph_intArray()
66 {
67 int[] expected = { 1, 2, 3 };
68 int[] actual = (int[]) morpher.morph( expected );
69 ArrayAssertions.assertEquals( expected, actual );
70 }
71
72 public void testMorph_intArray_threedims()
73 {
74 int[][][] expected = { { { 1 }, { 2 } }, { { 3 }, { 4 } } };
75 int[][][] actual = (int[][][]) morpher.morph( expected );
76 ArrayAssertions.assertEquals( expected, actual );
77 }
78
79 public void testMorph_intArray_twodims()
80 {
81 int[][] expected = { { 1, 2, 3 }, { 4, 5, 6 } };
82 int[][] actual = (int[][]) morpher.morph( expected );
83 ArrayAssertions.assertEquals( expected, actual );
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 int[] actual = (int[]) morpher.morph( expected );
95 ArrayAssertions.assertEquals( new int[] { 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 int[][] actual = (int[][]) morpher.morph( expected );
102 ArrayAssertions.assertEquals( new int[][] { { 1, 2, 3 }, { 4, 5, 6 } }, actual );
103 }
104
105 public void testMorph_throwException()
106 {
107 try{
108 new IntArrayMorpher().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 int[].class;
139 }
140
141 protected void setUp() throws Exception
142 {
143 morpher = new IntArrayMorpher();
144 morpherWithDefaultValue = new IntArrayMorpher( 0 );
145 anotherMorpher = new IntArrayMorpher();
146 anotherMorpherWithDefaultValue = new IntArrayMorpher( 1 );
147 }
148 }