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 ShortArrayMorpherTest 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( ShortArrayMorpherTest.class );
38 suite.setName( "ShortArrayMorpher Tests" );
39 return suite;
40 }
41
42 private ShortArrayMorpher anotherMorpher;
43 private ShortArrayMorpher anotherMorpherWithDefaultValue;
44 private ShortArrayMorpher morpher;
45 private ShortArrayMorpher morpherWithDefaultValue;
46
47 public ShortArrayMorpherTest( 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_null()
66 {
67 assertNull( morpher.morph( null ) );
68 }
69
70 public void testMorph_shortArray()
71 {
72 short[] expected = { 1, 2, 3 };
73 short[] actual = (short[]) morpher.morph( expected );
74 ArrayAssertions.assertEquals( expected, actual );
75 }
76
77 public void testMorph_shortArray_threedims()
78 {
79 short[][][] expected = { { { 1 }, { 2 } }, { { 3 }, { 4 } } };
80 short[][][] actual = (short[][][]) morpher.morph( expected );
81 ArrayAssertions.assertEquals( expected, actual );
82 }
83
84 public void testMorph_shortArray_twodims()
85 {
86 short[][] expected = { { 1, 2, 3 }, { 4, 5, 6 } };
87 short[][] actual = (short[][]) morpher.morph( expected );
88 ArrayAssertions.assertEquals( expected, actual );
89 }
90
91 public void testMorph_strings()
92 {
93 String[] expected = { "1", "2", "3.3" };
94 short[] actual = (short[]) morpher.morph( expected );
95 ArrayAssertions.assertEquals( new short[] { 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 short[][] actual = (short[][]) morpher.morph( expected );
102 ArrayAssertions.assertEquals( new short[][] { { 1, 2, 3 }, { 4, 5, 6 } }, actual );
103 }
104
105 public void testMorph_throwException()
106 {
107 try{
108 new ShortArrayMorpher().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 short[].class;
139 }
140
141 protected void setUp() throws Exception
142 {
143 morpher = new ShortArrayMorpher();
144 morpherWithDefaultValue = new ShortArrayMorpher( (short) 0 );
145 anotherMorpher = new ShortArrayMorpher();
146 anotherMorpherWithDefaultValue = new ShortArrayMorpher( (short) 1 );
147 }
148 }