root/trunk/test/java/org/jcoderz/commons/util/ArraysUtilTest.java

Revision 1561, 4.4 kB (checked in by amandel, 3 years ago)

New unit test

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 *
4 * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *    * Redistributions of source code must retain the above copyright
11 *      notice, this list of conditions and the following disclaimer.
12 *    * Redistributions in binary form must reproduce the above
13 *      copyright notice, this list of conditions and the following
14 *      disclaimer in the documentation and/or other materials
15 *      provided with the distribution.
16 *    * Neither the name of the jCoderZ.org Project nor the names of
17 *      its contributors may be used to endorse or promote products
18 *      derived from this software without specific prior written
19 *      permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33package org.jcoderz.commons.util;
34
35
36import junit.framework.TestCase;
37
38
39/**
40 * JUnit tests for class {@link org.jcoderz.commons.util.ArraysUtil}.
41 *
42 * @author Michael Griffel.
43 */
44public class ArraysUtilTest
45      extends TestCase
46{
47   private static final String NULL_STRING = "null";
48   private static final String EMPTY_ARRAY_STRING = "[]";
49
50   /**
51    * Tests the method {@link ArraysUtil#toString(Object[])}.
52    */
53   public final void testToStringObjectArray ()
54   {
55      final Object[] nullInput = null;
56      final String nullInputResult = ArraysUtil.toString(nullInput);
57      assertEquals("Expected a 'null' string for an array that is 'null'.",
58            NULL_STRING, nullInputResult);
59
60      final Object[] emptyArray = {};
61      final String emptyArrayResult = ArraysUtil.toString(emptyArray);
62      assertEquals("Expected a '" + EMPTY_ARRAY_STRING
63            + "' string for an empty array.",
64            EMPTY_ARRAY_STRING, emptyArrayResult);
65
66      final Object[] inputArray = {null, "", "a string"};
67      final String output = ArraysUtil.toString(inputArray);
68      assertEquals("Unexpected string representation of array received.",
69            "[null, , a string]", output);
70   }
71
72   /**
73    * Tests the method {@link ArraysUtil#toString(Object)}.
74    */
75   public final void testToStringNativeArray ()
76   {
77      final int[] nullInput = null;
78      final String nullInputResult = ArraysUtil.toString((Object) nullInput);
79      assertEquals(
80          "Expected a 'null' string for an native array that is 'null'.",
81          NULL_STRING, nullInputResult);
82
83      final int[] emptyArray = {};
84      final String emptyArrayResult = ArraysUtil.toString(emptyArray);
85      assertEquals("Expected a '" + EMPTY_ARRAY_STRING
86            + "' string for an empty array.",
87            EMPTY_ARRAY_STRING, emptyArrayResult);
88
89      final int[] inputArray = {1, 0, -1};
90      final String output = ArraysUtil.toString(inputArray);
91      assertEquals("Unexpected string representation of array received.",
92            "[1, 0, -1]", output);
93   }
94
95   /**
96    * Tests the method {@link ArraysUtil#toString(Object)} with
97    * nested array.
98    */
99   public final void testToStringNested ()
100   {
101      final Object[] inputArray = {null, "test", new int[] {1, 0, -1}};
102      final String output = ArraysUtil.toString((Object) inputArray);
103      assertEquals(
104          "Unexpected string representation of nested array received.",
105          "[null, test, [1, 0, -1]]", output);
106   }
107
108   /**
109    * Tests the method {@link ArraysUtil#toString(Object)} with
110    * nested array.
111    */
112   public final void testToStringNestedBoolean ()
113   {
114      final Object[] inputArray = {null, "test", new boolean[] {true, false}};
115      final String output = ArraysUtil.toString(inputArray);
116      assertEquals(
117          "Unexpected string representation of nested array received.",
118          "[null, test, [true, false]]", output);
119   }
120
121}
Note: See TracBrowser for help on using the browser.