Project Report: fawkez

Packagesummary org.jcoderz.commons.util

org.jcoderz.commons.util.ArraysUtilTest

LineHitsNoteSource
1  /*
2   * $Id: ArraysUtilTest.java 1561 2009-10-12 05:28:25Z amandel $
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   */
33  package org.jcoderz.commons.util;
34  
35  
36  import junit.framework.TestCase;
37  
38  
39  /**
40   * JUnit tests for class {@link org.jcoderz.commons.util.ArraysUtil}.
41   *
42   * @author Michael Griffel.
43   */
44100 public 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     {
55100       final Object[] nullInput = null;
56100       final String nullInputResult = ArraysUtil.toString(nullInput);
57100       assertEquals("Expected a 'null' string for an array that is 'null'.",
58              NULL_STRING, nullInputResult);
59  
60100       final Object[] emptyArray = {};
61100       final String emptyArrayResult = ArraysUtil.toString(emptyArray);
62100       assertEquals("Expected a '" + EMPTY_ARRAY_STRING
63              + "' string for an empty array.",
64              EMPTY_ARRAY_STRING, emptyArrayResult);
65  
66100       final Object[] inputArray = {null, "", "a string"};
67100       final String output = ArraysUtil.toString(inputArray);
68100       assertEquals("Unexpected string representation of array received.",
69              "[null, , a string]", output);
70100    }
71  
72     /**
73      * Tests the method {@link ArraysUtil#toString(Object)}.
74      */
75     public final void testToStringNativeArray ()
76     {
77100       final int[] nullInput = null;
78100       final String nullInputResult = ArraysUtil.toString((Object) nullInput);
79100       assertEquals(
80            "Expected a 'null' string for an native array that is 'null'.",
81            NULL_STRING, nullInputResult);
82  
83100       final int[] emptyArray = {};
84100       final String emptyArrayResult = ArraysUtil.toString(emptyArray);
85100       assertEquals("Expected a '" + EMPTY_ARRAY_STRING
86              + "' string for an empty array.",
87              EMPTY_ARRAY_STRING, emptyArrayResult);
88  
89100       final int[] inputArray = {1, 0, -1};
90100       final String output = ArraysUtil.toString(inputArray);
91100       assertEquals("Unexpected string representation of array received.",
92              "[1, 0, -1]", output);
93100    }
94  
95     /**
96      * Tests the method {@link ArraysUtil#toString(Object)} with
97      * nested array.
98      */
99     public final void testToStringNested ()
100     {
101100       final Object[] inputArray = {null, "test", new int[] {1, 0, -1}};
102100       final String output = ArraysUtil.toString((Object) inputArray);
103100       assertEquals(
104            "Unexpected string representation of nested array received.",
105            "[null, test, [1, 0, -1]]", output);
106100    }
107  
108     /**
109      * Tests the method {@link ArraysUtil#toString(Object)} with
110      * nested array.
111      */
112     public final void testToStringNestedBoolean ()
113     {
114100       final Object[] inputArray = {null, "test", new boolean[] {true, false}};
115100       final String output = ArraysUtil.toString(inputArray);
116100       assertEquals(
117            "Unexpected string representation of nested array received.",
118            "[null, test, [true, false]]", output);
119100    }
120  
121  }

Findings in this File