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 BooleanArrayMorpherTest 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( BooleanArrayMorpherTest.class );
38 suite.setName( "BooleanArrayMorpher Tests" );
39 return suite;
40 }
41
42 private BooleanArrayMorpher anotherMorpher;
43 private BooleanArrayMorpher anotherMorpherWithDefaultValue;
44 private BooleanArrayMorpher morpher;
45 private BooleanArrayMorpher morpherWithDefaultValue;
46
47 public BooleanArrayMorpherTest( String name )
48 {
49 super( name );
50 }
51
52
53
54 public void testMorph_booleanArray()
55 {
56 boolean[] expected = { true, false };
57 boolean[] actual = (boolean[]) morpher.morph( expected );
58 ArrayAssertions.assertEquals( expected, actual );
59 }
60
61 public void testMorph_booleanArray_threedims()
62 {
63 boolean[][][] expected = { { { true }, { false } }, { { true }, { false } } };
64 boolean[][][] actual = (boolean[][][]) morpher.morph( expected );
65 ArrayAssertions.assertEquals( expected, actual );
66 }
67
68 public void testMorph_booleanArray_twodims()
69 {
70 boolean[][] expected = { { true, false }, { true, false } };
71 boolean[][] actual = (boolean[][]) 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 = { "true", "yes", "on", "false", "no", "off" };
94 boolean[] actual = (boolean[]) morpher.morph( expected );
95 ArrayAssertions.assertEquals( new boolean[] { true, true, true, false, false, false }, actual );
96 }
97
98 public void testMorph_strings_twodims()
99 {
100 String[][] expected = { { "true", "yes", "on" }, { "false", "no", "off" } };
101 boolean[][] actual = (boolean[][]) morpher.morph( expected );
102 ArrayAssertions.assertEquals(
103 new boolean[][] { { true, true, true }, { false, false, false } }, actual );
104 }
105
106 public void testMorph_throwException()
107 {
108 try{
109 new BooleanArrayMorpher().morph( new String[] { null } );
110 fail( "Should have thrown an Exception" );
111 }
112 catch( MorphException expected ){
113
114 }
115 }
116
117 protected AbstractArrayMorpher getAnotherMorpher()
118 {
119 return anotherMorpher;
120 }
121
122 protected AbstractArrayMorpher getAnotherMorpherWithDefaultValue()
123 {
124 return anotherMorpherWithDefaultValue;
125 }
126
127 protected AbstractArrayMorpher getMorpher()
128 {
129 return morpher;
130 }
131
132 protected AbstractArrayMorpher getMorpherWithDefaultValue()
133 {
134 return morpherWithDefaultValue;
135 }
136
137 protected Class getMorphsToClass()
138 {
139 return boolean[].class;
140 }
141
142 protected void setUp() throws Exception
143 {
144 morpher = new BooleanArrayMorpher();
145 morpherWithDefaultValue = new BooleanArrayMorpher( true );
146 anotherMorpher = new BooleanArrayMorpher();
147 anotherMorpherWithDefaultValue = new BooleanArrayMorpher( false );
148 }
149 }