001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.util;
032:
033: import junit.framework.TestCase;
034: import java.util.*;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class ArraysJava6TestCase extends TestCase {
040:
041: public void testCopyOf() {
042: assertEquals("[true, false]", Arrays.toString(Arrays.copyOf(
043: new boolean[] { true, false, true }, 2)));
044: assertEquals("[true, false, true, false]", Arrays
045: .toString(Arrays.copyOf(new boolean[] { true, false,
046: true }, 4)));
047:
048: assertEquals("[1, 2]", Arrays.toString(Arrays.copyOf(
049: new byte[] { 1, 2, 3 }, 2)));
050: assertEquals("[1, 2, 3, 0]", Arrays.toString(Arrays.copyOf(
051: new byte[] { 1, 2, 3 }, 4)));
052:
053: assertEquals("[a, b]", Arrays.toString(Arrays.copyOf(
054: new char[] { 'a', 'b', 'c' }, 2)));
055: assertEquals("[a, b, c, \u0000]", Arrays.toString(Arrays
056: .copyOf(new char[] { 'a', 'b', 'c' }, 4)));
057:
058: assertEquals("[1.1, 2.2]", Arrays.toString(Arrays.copyOf(
059: new double[] { 1.1, 2.2, 3.3 }, 2)));
060: assertEquals("[1.1, 2.2, 3.3, 0.0]", Arrays.toString(Arrays
061: .copyOf(new double[] { 1.1, 2.2, 3.3 }, 4)));
062:
063: assertEquals("[1.1, 2.2]", Arrays.toString(Arrays.copyOf(
064: new float[] { 1.1f, 2.2f, 3.3f }, 2)));
065: assertEquals("[1.1, 2.2, 3.3, 0.0]", Arrays.toString(Arrays
066: .copyOf(new float[] { 1.1f, 2.2f, 3.3f }, 4)));
067:
068: assertEquals("[1, 2]", Arrays.toString(Arrays.copyOf(new int[] {
069: 1, 2, 3 }, 2)));
070: assertEquals("[1, 2, 3, 0]", Arrays.toString(Arrays.copyOf(
071: new int[] { 1, 2, 3 }, 4)));
072:
073: assertEquals("[1, 2]", Arrays.toString(Arrays.copyOf(
074: new long[] { 1, 2, 3 }, 2)));
075: assertEquals("[1, 2, 3, 0]", Arrays.toString(Arrays.copyOf(
076: new long[] { 1, 2, 3 }, 4)));
077:
078: assertEquals("[1, 2]", Arrays.toString(Arrays.copyOf(
079: new short[] { 1, 2, 3 }, 2)));
080: assertEquals("[1, 2, 3, 0]", Arrays.toString(Arrays.copyOf(
081: new short[] { 1, 2, 3 }, 4)));
082:
083: assertEquals("[a, b]", Arrays.toString(Arrays.copyOf(
084: new Object[] { "a", "b", "c" }, 2)));
085: assertEquals("[a, b, c, null]", Arrays.toString(Arrays.copyOf(
086: new Object[] { "a", "b", "c" }, 4)));
087:
088: assertEquals("[a, b]", Arrays.toString(Arrays.copyOf(
089: new Object[] { "a", "b", "c" }, 2, String[].class)));
090: assertEquals("[a, b, c, null]", Arrays.toString(Arrays.copyOf(
091: new Object[] { "a", "b", "c" }, 4, String[].class)));
092: }
093:
094: public void testCopyOfRange() {
095: assertEquals("[false, true]", Arrays.toString(Arrays
096: .copyOfRange(
097: new boolean[] { true, false, true, false }, 1,
098: 3)));
099:
100: assertEquals("[2, 3]", Arrays.toString(Arrays.copyOfRange(
101: new byte[] { 1, 2, 3, 4 }, 1, 3)));
102:
103: assertEquals("[b, c]", Arrays.toString(Arrays.copyOfRange(
104: new char[] { 'a', 'b', 'c', 'd' }, 1, 3)));
105:
106: assertEquals("[2.2, 3.3]", Arrays.toString(Arrays.copyOfRange(
107: new double[] { 1.1, 2.2, 3.3, 4.4 }, 1, 3)));
108:
109: assertEquals("[2.2, 3.3]", Arrays.toString(Arrays.copyOfRange(
110: new float[] { 1.1f, 2.2f, 3.3f, 4.4f }, 1, 3)));
111:
112: assertEquals("[2, 3]", Arrays.toString(Arrays.copyOfRange(
113: new int[] { 1, 2, 3, 4 }, 1, 3)));
114:
115: assertEquals("[2, 3]", Arrays.toString(Arrays.copyOfRange(
116: new long[] { 1, 2, 3, 4 }, 1, 3)));
117:
118: assertEquals("[2, 3]", Arrays.toString(Arrays.copyOfRange(
119: new short[] { 1, 2, 3, 4 }, 1, 3)));
120:
121: assertEquals("[b, c]", Arrays.toString(Arrays.copyOfRange(
122: new Object[] { "a", "b", "c", "d" }, 1, 3)));
123:
124: assertEquals("[b, c]", Arrays.toString(Arrays.copyOfRange(
125: new Object[] { "a", "b", "c", "d" }, 1, 3,
126: String[].class)));
127: }
128:
129: }
|