KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > util > junit > ArrayUtilitiesTests


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * --------------------
28  * ArrayUtilsTests.java
29  * --------------------
30  * (C) Copyright 2004, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: ArrayUtilitiesTests.java,v 1.3 2005/10/18 13:25:14 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 24-Aug-2004 : Version 1 (DG);
40  * 04-Oct-2004 : Renamed ArrayUtilsTests --> ArrayUtilitiesTests (DG);
41  *
42  */

43
44 package org.jfree.util.junit;
45
46 import junit.framework.Test;
47 import junit.framework.TestCase;
48 import junit.framework.TestSuite;
49
50 import org.jfree.util.ArrayUtilities;
51
52 /**
53  * Tests for the {@link ArrayUtilities} class.
54  */

55 public class ArrayUtilitiesTests extends TestCase {
56
57     /**
58      * Returns the tests as a test suite.
59      *
60      * @return The test suite.
61      */

62     public static Test suite() {
63         return new TestSuite(ArrayUtilitiesTests.class);
64     }
65
66     /**
67      * Constructs a new set of tests.
68      *
69      * @param name the name of the tests.
70      */

71     public ArrayUtilitiesTests(String JavaDoc name) {
72         super(name);
73     }
74
75     /**
76      * Some tests for the hasDuplicateItems() method.
77      */

78     public void testHasDuplicateItems() {
79         Object JavaDoc[] a1 = new Object JavaDoc[] {"1", "2", "3"};
80         Object JavaDoc[] a2 = new Object JavaDoc[] {"1", "1", "3"};
81         Object JavaDoc[] a3 = new Object JavaDoc[] {null, "2", null};
82         assertFalse(ArrayUtilities.hasDuplicateItems(a1));
83         assertTrue(ArrayUtilities.hasDuplicateItems(a2));
84         assertFalse(ArrayUtilities.hasDuplicateItems(a3));
85     }
86     
87     /**
88      * Some checks for the equalReferencesInArrays() method.
89      */

90     public void testEqualReferencesInArrays() {
91         Object JavaDoc[] a1 = new Object JavaDoc[] {};
92         Object JavaDoc[] a2 = new Object JavaDoc[] {};
93         Object JavaDoc[] a3 = new Object JavaDoc[] {null};
94         Object JavaDoc[] a4 = new Object JavaDoc[] {null};
95         Object JavaDoc[] a5 = new Object JavaDoc[] {"A"};
96         Object JavaDoc[] a6 = new Object JavaDoc[] {"A"};
97         Object JavaDoc[] a7 = new Object JavaDoc[] {"A", "B"};
98         Object JavaDoc[] a8 = new Object JavaDoc[] {"A", "B"};
99         Object JavaDoc[] a9 = new Object JavaDoc[] {"A", null};
100         Object JavaDoc[] a10 = new Object JavaDoc[] {"A", null};
101         
102         assertTrue(ArrayUtilities.equalReferencesInArrays(a1, a2));
103         assertFalse(ArrayUtilities.equalReferencesInArrays(a1, a3));
104         assertTrue(ArrayUtilities.equalReferencesInArrays(a3, a4));
105         assertFalse(ArrayUtilities.equalReferencesInArrays(a3, a5));
106         assertTrue(ArrayUtilities.equalReferencesInArrays(a5, a6));
107         assertFalse(ArrayUtilities.equalReferencesInArrays(a5, a7));
108         assertTrue(ArrayUtilities.equalReferencesInArrays(a7, a8));
109         assertFalse(ArrayUtilities.equalReferencesInArrays(a7, a9));
110         assertTrue(ArrayUtilities.equalReferencesInArrays(a9, a10));
111     }
112 }
113
Popular Tags