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 ArrayAssertionsTest 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( ArrayAssertionsTest.class );
38        suite.setName( "ArrayAssertions Tests" );
39        return suite;
40     }
41  
42     public ArrayAssertionsTest( String name )
43     {
44        super( name );
45     }
46  
47     // -----------------------------------------------------------------------
48  
49     public void testAssertEquals_null_null()
50     {
51        // assert that original contract is not borken
52        ArrayAssertions.assertEquals( (Object) null, (Object) null );
53     }
54  
55     public void testAssertEquals_actuals_is_null()
56     {
57        boolean errorThrown = false;
58        Object[] expecteds = new Object[] { new Object(), new Object() };
59        try{
60           ArrayAssertions.assertEquals( expecteds, (Object[]) null );
61        }
62        catch( AssertionFailedError expected ){
63           errorThrown = true;
64        }
65        assertTrue( "Expected a failure", errorThrown );
66     }
67  
68     public void testAssertEquals_different_length()
69     {
70        boolean errorThrown = false;
71        Object[] expecteds = new Object[] { new Object(), new Object() };
72        Object[] actuals = new Object[] { new Object() };
73        try{
74           ArrayAssertions.assertEquals( expecteds, actuals );
75        }
76        catch( AssertionFailedError expected ){
77           errorThrown = true;
78        }
79        assertTrue( "Expected a failure", errorThrown );
80     }
81  
82     public void testAssertEquals_expecteds_is_null()
83     {
84        boolean errorThrown = false;
85        Object[] actuals = new Object[] { new Object(), new Object() };
86        try{
87           ArrayAssertions.assertEquals( (Object[]) null, actuals );
88        }
89        catch( AssertionFailedError expected ){
90           errorThrown = true;
91        }
92        assertTrue( "Expected a failure", errorThrown );
93     }
94  
95     public void testAssertEquals_multi_Object_Object_nulls()
96     {
97        Object[][] expecteds = new Object[][] { { null }, { null } };
98        Object[][] actuals = new Object[][] { { null }, { null } };
99        ArrayAssertions.assertEquals( expecteds, actuals );
100    }
101 
102    public void testAssertEquals_null_elements()
103    {
104       boolean errorThrown = false;
105       Object[] expecteds = new Object[] { null };
106       Object[] actuals = new Object[] { new Object() };
107       try{
108          ArrayAssertions.assertEquals( expecteds, actuals );
109       }
110       catch( AssertionFailedError expected ){
111          errorThrown = true;
112       }
113       assertTrue( "Expected a failure", errorThrown );
114    }
115 
116    public void testAssertEquals_null_elements_2()
117    {
118       boolean errorThrown = false;
119       Object[] expecteds = new Object[] { new Object() };
120       Object[] actuals = new Object[] { null };
121       try{
122          ArrayAssertions.assertEquals( expecteds, actuals );
123       }
124       catch( AssertionFailedError expected ){
125          errorThrown = true;
126       }
127       assertTrue( "Expected a failure", errorThrown );
128    }
129 
130    public void testAssertEquals_Object_Object_nulls()
131    {
132       Object[] expecteds = new Object[] { null };
133       Object[] actuals = new Object[] { null };
134       ArrayAssertions.assertEquals( expecteds, actuals );
135    }
136 }