1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.ezmorph.test;
18  
19  import junit.framework.AssertionFailedError;
20  import junit.framework.Test;
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  import junit.textui.TestRunner;
24  
25  /**
26   * @author Andres Almiray <aalmiray@users.sourceforge.net>
27   */
28  public class ShortArrayAssertionsTest extends TestCase
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( ShortArrayAssertionsTest.class );
38        suite.setName( "ShortArrayAssertions Tests" );
39        return suite;
40     }
41  
42     public ShortArrayAssertionsTest( String name )
43     {
44        super( name );
45     }
46  
47     // -----------------------------------------------------------------------
48  
49     public void testAssertEquals_multi_short_short()
50     {
51        short[][] expecteds = new short[][] { { 1, 2 }, { 1, 2 } };
52        short[][] actuals = new short[][] { { 1, 2 }, { 1, 2 } };
53        ArrayAssertions.assertEquals( expecteds, actuals );
54     }
55  
56     public void testAssertEquals_multi_short_Short()
57     {
58        short[][] expecteds = new short[][] { { 1, 2 }, { 1, 2 } };
59        Short[][] actuals = new Short[][] { { new Short( (short) 1 ), new Short( (short) 2 ) },
60              { new Short( (short) 1 ), new Short( (short) 2 ) } };
61        ArrayAssertions.assertEquals( expecteds, actuals );
62     }
63  
64     public void testAssertEquals_multi_Short_short()
65     {
66        Short[][] expecteds = new Short[][] { { new Short( (short) 1 ), new Short( (short) 2 ) },
67              { new Short( (short) 1 ), new Short( (short) 2 ) } };
68        short[][] actuals = new short[][] { { 1, 2 }, { 1, 2 } };
69        ArrayAssertions.assertEquals( expecteds, actuals );
70     }
71  
72     public void testAssertEquals_multi_Short_Short()
73     {
74        Short[][] expecteds = new Short[][] { { new Short( (short) 1 ), new Short( (short) 2 ) },
75              { new Short( (short) 1 ), new Short( (short) 2 ) } };
76        Short[][] actuals = new Short[][] { { new Short( (short) 1 ), new Short( (short) 2 ) },
77              { new Short( (short) 1 ), new Short( (short) 2 ) } };
78        ArrayAssertions.assertEquals( expecteds, actuals );
79     }
80  
81     public void testAssertEquals_OO_Object_array_Object_array()
82     {
83        Object expecteds = new Object[] { new Short( (short) 1 ), new Short( (short) 2 ) };
84        Object actuals = new Object[] { new Short( (short) 1 ), new Short( (short) 2 ) };
85        ArrayAssertions.assertEquals( expecteds, actuals );
86     }
87  
88     public void testAssertEquals_OO_Object_array_short()
89     {
90        Object expecteds = new Object[] { new Short( (short) 1 ), new Short( (short) 2 ) };
91        Object actuals = new short[] { 1, 2 };
92        ArrayAssertions.assertEquals( expecteds, actuals );
93     }
94  
95     public void testAssertEquals_OO_short_double()
96     {
97        boolean errorThrown = false;
98        Object expecteds = new short[] { 1, 2 };
99        Object actuals = new double[] { 1, 2 };
100       try{
101          ArrayAssertions.assertEquals( expecteds, actuals );
102       }
103       catch( AssertionFailedError expected ){
104          errorThrown = true;
105       }
106       assertTrue( "Expected a failure", errorThrown );
107    }
108 
109    public void testAssertEquals_OO_short_Object_array()
110    {
111       Object expecteds = new short[] { 1, 2 };
112       Object actuals = new Object[] { new Short( (short) 1 ), new Short( (short) 2 ) };
113       ArrayAssertions.assertEquals( expecteds, actuals );
114    }
115 
116    public void testAssertEquals_OO_short_short()
117    {
118       Object expecteds = new short[] { 1, 2 };
119       Object actuals = new short[] { 1, 2 };
120       ArrayAssertions.assertEquals( expecteds, actuals );
121    }
122 
123    public void testAssertEquals_OO_short_Short()
124    {
125       Object expecteds = new short[] { 1, 2 };
126       Object actuals = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
127       ArrayAssertions.assertEquals( expecteds, actuals );
128    }
129 
130    public void testAssertEquals_OO_Short_short()
131    {
132       Object expecteds = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
133       Object actuals = new short[] { 1, 2 };
134       ArrayAssertions.assertEquals( expecteds, actuals );
135    }
136 
137    public void testAssertEquals_short_short()
138    {
139       short[] expecteds = new short[] { 1, 2 };
140       short[] actuals = new short[] { 1, 2 };
141       ArrayAssertions.assertEquals( expecteds, actuals );
142    }
143 
144    public void testAssertEquals_short_Short()
145    {
146       short[] expecteds = new short[] { 1, 2 };
147       Short[] actuals = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
148       ArrayAssertions.assertEquals( expecteds, actuals );
149    }
150 
151    public void testAssertEquals_Short_short()
152    {
153       Short[] expecteds = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
154       short[] actuals = new short[] { 1, 2 };
155       ArrayAssertions.assertEquals( expecteds, actuals );
156    }
157 
158    public void testAssertEquals_Short_Short()
159    {
160       Short[] expecteds = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
161       Short[] actuals = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
162       ArrayAssertions.assertEquals( expecteds, actuals );
163    }
164 
165    public void testAssertEquals_short_short_actuals_is_null()
166    {
167       boolean errorThrown = false;
168       short[] expecteds = new short[] { 1, 2 };
169       try{
170          ArrayAssertions.assertEquals( expecteds, (short[]) null );
171       }
172       catch( AssertionFailedError expected ){
173          errorThrown = true;
174       }
175       assertTrue( "Expected a failure", errorThrown );
176    }
177 
178    public void testAssertEquals_short_Short_actuals_is_null()
179    {
180       boolean errorThrown = false;
181       short[] expecteds = new short[] { 1, 2 };
182       try{
183          ArrayAssertions.assertEquals( expecteds, (Short[]) null );
184       }
185       catch( AssertionFailedError expected ){
186          errorThrown = true;
187       }
188       assertTrue( "Expected a failure", errorThrown );
189    }
190 
191    public void testAssertEquals_Short_short_actuals_is_null()
192    {
193       boolean errorThrown = false;
194       Short[] expecteds = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
195       try{
196          ArrayAssertions.assertEquals( expecteds, (short[]) null );
197       }
198       catch( AssertionFailedError expected ){
199          errorThrown = true;
200       }
201       assertTrue( "Expected a failure", errorThrown );
202    }
203 
204    public void testAssertEquals_short_short_different_length()
205    {
206       short[] expecteds = new short[] { 1 };
207       short[] actuals = new short[] { 1, 2 };
208       boolean errorThrown = false;
209       try{
210          ArrayAssertions.assertEquals( expecteds, actuals );
211       }
212       catch( AssertionFailedError expected ){
213          errorThrown = true;
214       }
215       assertTrue( "Expected a failure", errorThrown );
216    }
217 
218    public void testAssertEquals_short_Short_different_length()
219    {
220       short[] expecteds = new short[] { 1 };
221       Short[] actuals = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
222       boolean errorThrown = false;
223       try{
224          ArrayAssertions.assertEquals( expecteds, actuals );
225       }
226       catch( AssertionFailedError expected ){
227          errorThrown = true;
228       }
229       assertTrue( "Expected a failure", errorThrown );
230    }
231 
232    public void testAssertEquals_Short_short_different_length()
233    {
234       Short[] expecteds = new Short[] { new Short( (short) 1 ) };
235       short[] actuals = new short[] { 1, 2 };
236       boolean errorThrown = false;
237       try{
238          ArrayAssertions.assertEquals( expecteds, actuals );
239       }
240       catch( AssertionFailedError expected ){
241          errorThrown = true;
242       }
243       assertTrue( "Expected a failure", errorThrown );
244    }
245 
246    public void testAssertEquals_short_short_expecteds_is_null()
247    {
248       boolean errorThrown = false;
249       short[] actuals = new short[] { 1, 2 };
250       try{
251          ArrayAssertions.assertEquals( (short[]) null, actuals );
252       }
253       catch( AssertionFailedError expected ){
254          errorThrown = true;
255       }
256       assertTrue( "Expected a failure", errorThrown );
257    }
258 
259    public void testAssertEquals_short_Short_expecteds_is_null()
260    {
261       boolean errorThrown = false;
262       Short[] actuals = new Short[] { new Short( (short) 1 ), new Short( (short) 2 ) };
263       try{
264          ArrayAssertions.assertEquals( (short[]) null, actuals );
265       }
266       catch( AssertionFailedError expected ){
267          errorThrown = true;
268       }
269       assertTrue( "Expected a failure", errorThrown );
270    }
271    public void testAssertEquals_Short_short_expecteds_is_null()
272    {
273       boolean errorThrown = false;
274       short[] actuals = new short[] { 1, 2 };
275       try{
276          ArrayAssertions.assertEquals( (Short[]) null, actuals );
277       }
278       catch( AssertionFailedError expected ){
279          errorThrown = true;
280       }
281       assertTrue( "Expected a failure", errorThrown );
282    }
283 }