001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.lang;
019:
020: import java.util.Arrays;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025: import junit.textui.TestRunner;
026:
027: /**
028: * Tests ArrayUtils remove and removeElement methods.
029: *
030: * @author Maarten Coene
031: * @version $Id: ArrayUtilsRemoveTest.java 437554 2006-08-28 06:21:41Z bayard $
032: */
033: public class ArrayUtilsRemoveTest extends TestCase {
034: public static void main(String[] args) {
035: TestRunner.run(suite());
036: }
037:
038: public static Test suite() {
039: TestSuite suite = new TestSuite(ArrayUtilsRemoveTest.class);
040: suite.setName("ArrayUtils remove Tests");
041: return suite;
042: }
043:
044: public void testRemoveObjectArray() {
045: Object[] array;
046: array = ArrayUtils.remove(new Object[] { "a" }, 0);
047: assertTrue(Arrays.equals(ArrayUtils.EMPTY_OBJECT_ARRAY, array));
048: assertEquals(Object.class, array.getClass().getComponentType());
049: array = ArrayUtils.remove(new Object[] { "a", "b" }, 0);
050: assertTrue(Arrays.equals(new Object[] { "b" }, array));
051: assertEquals(Object.class, array.getClass().getComponentType());
052: array = ArrayUtils.remove(new Object[] { "a", "b" }, 1);
053: assertTrue(Arrays.equals(new Object[] { "a" }, array));
054: assertEquals(Object.class, array.getClass().getComponentType());
055: array = ArrayUtils.remove(new Object[] { "a", "b", "c" }, 1);
056: assertTrue(Arrays.equals(new Object[] { "a", "c" }, array));
057: assertEquals(Object.class, array.getClass().getComponentType());
058: try {
059: ArrayUtils.remove(new Object[] { "a", "b" }, -1);
060: fail("IndexOutOfBoundsException expected");
061: } catch (IndexOutOfBoundsException e) {
062: }
063: try {
064: ArrayUtils.remove(new Object[] { "a", "b" }, 2);
065: fail("IndexOutOfBoundsException expected");
066: } catch (IndexOutOfBoundsException e) {
067: }
068: try {
069: ArrayUtils.remove((Object[]) null, 0);
070: fail("IndexOutOfBoundsException expected");
071: } catch (IndexOutOfBoundsException e) {
072: }
073: }
074:
075: public void testRemoveBooleanArray() {
076: boolean[] array;
077: array = ArrayUtils.remove(new boolean[] { true }, 0);
078: assertTrue(Arrays.equals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array));
079: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
080: array = ArrayUtils.remove(new boolean[] { true, false }, 0);
081: assertTrue(Arrays.equals(new boolean[] { false }, array));
082: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
083: array = ArrayUtils.remove(new boolean[] { true, false }, 1);
084: assertTrue(Arrays.equals(new boolean[] { true }, array));
085: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
086: array = ArrayUtils.remove(new boolean[] { true, false, true },
087: 1);
088: assertTrue(Arrays.equals(new boolean[] { true, true }, array));
089: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
090: try {
091: ArrayUtils.remove(new boolean[] { true, false }, -1);
092: fail("IndexOutOfBoundsException expected");
093: } catch (IndexOutOfBoundsException e) {
094: }
095: try {
096: ArrayUtils.remove(new boolean[] { true, false }, 2);
097: fail("IndexOutOfBoundsException expected");
098: } catch (IndexOutOfBoundsException e) {
099: }
100: try {
101: ArrayUtils.remove((boolean[]) null, 0);
102: fail("IndexOutOfBoundsException expected");
103: } catch (IndexOutOfBoundsException e) {
104: }
105: }
106:
107: public void testRemoveByteArray() {
108: byte[] array;
109: array = ArrayUtils.remove(new byte[] { 1 }, 0);
110: assertTrue(Arrays.equals(ArrayUtils.EMPTY_BYTE_ARRAY, array));
111: assertEquals(Byte.TYPE, array.getClass().getComponentType());
112: array = ArrayUtils.remove(new byte[] { 1, 2 }, 0);
113: assertTrue(Arrays.equals(new byte[] { 2 }, array));
114: assertEquals(Byte.TYPE, array.getClass().getComponentType());
115: array = ArrayUtils.remove(new byte[] { 1, 2 }, 1);
116: assertTrue(Arrays.equals(new byte[] { 1 }, array));
117: assertEquals(Byte.TYPE, array.getClass().getComponentType());
118: array = ArrayUtils.remove(new byte[] { 1, 2, 1 }, 1);
119: assertTrue(Arrays.equals(new byte[] { 1, 1 }, array));
120: assertEquals(Byte.TYPE, array.getClass().getComponentType());
121: try {
122: ArrayUtils.remove(new byte[] { 1, 2 }, -1);
123: fail("IndexOutOfBoundsException expected");
124: } catch (IndexOutOfBoundsException e) {
125: }
126: try {
127: ArrayUtils.remove(new byte[] { 1, 2 }, 2);
128: fail("IndexOutOfBoundsException expected");
129: } catch (IndexOutOfBoundsException e) {
130: }
131: try {
132: ArrayUtils.remove((byte[]) null, 0);
133: fail("IndexOutOfBoundsException expected");
134: } catch (IndexOutOfBoundsException e) {
135: }
136: }
137:
138: public void testRemoveCharArray() {
139: char[] array;
140: array = ArrayUtils.remove(new char[] { 'a' }, 0);
141: assertTrue(Arrays.equals(ArrayUtils.EMPTY_CHAR_ARRAY, array));
142: assertEquals(Character.TYPE, array.getClass()
143: .getComponentType());
144: array = ArrayUtils.remove(new char[] { 'a', 'b' }, 0);
145: assertTrue(Arrays.equals(new char[] { 'b' }, array));
146: assertEquals(Character.TYPE, array.getClass()
147: .getComponentType());
148: array = ArrayUtils.remove(new char[] { 'a', 'b' }, 1);
149: assertTrue(Arrays.equals(new char[] { 'a' }, array));
150: assertEquals(Character.TYPE, array.getClass()
151: .getComponentType());
152: array = ArrayUtils.remove(new char[] { 'a', 'b', 'c' }, 1);
153: assertTrue(Arrays.equals(new char[] { 'a', 'c' }, array));
154: assertEquals(Character.TYPE, array.getClass()
155: .getComponentType());
156: try {
157: ArrayUtils.remove(new char[] { 'a', 'b' }, -1);
158: fail("IndexOutOfBoundsException expected");
159: } catch (IndexOutOfBoundsException e) {
160: }
161: try {
162: ArrayUtils.remove(new char[] { 'a', 'b' }, 2);
163: fail("IndexOutOfBoundsException expected");
164: } catch (IndexOutOfBoundsException e) {
165: }
166: try {
167: ArrayUtils.remove((char[]) null, 0);
168: fail("IndexOutOfBoundsException expected");
169: } catch (IndexOutOfBoundsException e) {
170: }
171: }
172:
173: public void testRemoveDoubleArray() {
174: double[] array;
175: array = ArrayUtils.remove(new double[] { 1 }, 0);
176: assertTrue(Arrays.equals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array));
177: assertEquals(Double.TYPE, array.getClass().getComponentType());
178: array = ArrayUtils.remove(new double[] { 1, 2 }, 0);
179: assertTrue(Arrays.equals(new double[] { 2 }, array));
180: assertEquals(Double.TYPE, array.getClass().getComponentType());
181: array = ArrayUtils.remove(new double[] { 1, 2 }, 1);
182: assertTrue(Arrays.equals(new double[] { 1 }, array));
183: assertEquals(Double.TYPE, array.getClass().getComponentType());
184: array = ArrayUtils.remove(new double[] { 1, 2, 1 }, 1);
185: assertTrue(Arrays.equals(new double[] { 1, 1 }, array));
186: assertEquals(Double.TYPE, array.getClass().getComponentType());
187: try {
188: ArrayUtils.remove(new double[] { 1, 2 }, -1);
189: fail("IndexOutOfBoundsException expected");
190: } catch (IndexOutOfBoundsException e) {
191: }
192: try {
193: ArrayUtils.remove(new double[] { 1, 2 }, 2);
194: fail("IndexOutOfBoundsException expected");
195: } catch (IndexOutOfBoundsException e) {
196: }
197: try {
198: ArrayUtils.remove((double[]) null, 0);
199: fail("IndexOutOfBoundsException expected");
200: } catch (IndexOutOfBoundsException e) {
201: }
202: }
203:
204: public void testRemoveFloatArray() {
205: float[] array;
206: array = ArrayUtils.remove(new float[] { 1 }, 0);
207: assertTrue(Arrays.equals(ArrayUtils.EMPTY_FLOAT_ARRAY, array));
208: assertEquals(Float.TYPE, array.getClass().getComponentType());
209: array = ArrayUtils.remove(new float[] { 1, 2 }, 0);
210: assertTrue(Arrays.equals(new float[] { 2 }, array));
211: assertEquals(Float.TYPE, array.getClass().getComponentType());
212: array = ArrayUtils.remove(new float[] { 1, 2 }, 1);
213: assertTrue(Arrays.equals(new float[] { 1 }, array));
214: assertEquals(Float.TYPE, array.getClass().getComponentType());
215: array = ArrayUtils.remove(new float[] { 1, 2, 1 }, 1);
216: assertTrue(Arrays.equals(new float[] { 1, 1 }, array));
217: assertEquals(Float.TYPE, array.getClass().getComponentType());
218: try {
219: ArrayUtils.remove(new float[] { 1, 2 }, -1);
220: fail("IndexOutOfBoundsException expected");
221: } catch (IndexOutOfBoundsException e) {
222: }
223: try {
224: ArrayUtils.remove(new float[] { 1, 2 }, 2);
225: fail("IndexOutOfBoundsException expected");
226: } catch (IndexOutOfBoundsException e) {
227: }
228: try {
229: ArrayUtils.remove((float[]) null, 0);
230: fail("IndexOutOfBoundsException expected");
231: } catch (IndexOutOfBoundsException e) {
232: }
233: }
234:
235: public void testRemoveIntArray() {
236: int[] array;
237: array = ArrayUtils.remove(new int[] { 1 }, 0);
238: assertTrue(Arrays.equals(ArrayUtils.EMPTY_INT_ARRAY, array));
239: assertEquals(Integer.TYPE, array.getClass().getComponentType());
240: array = ArrayUtils.remove(new int[] { 1, 2 }, 0);
241: assertTrue(Arrays.equals(new int[] { 2 }, array));
242: assertEquals(Integer.TYPE, array.getClass().getComponentType());
243: array = ArrayUtils.remove(new int[] { 1, 2 }, 1);
244: assertTrue(Arrays.equals(new int[] { 1 }, array));
245: assertEquals(Integer.TYPE, array.getClass().getComponentType());
246: array = ArrayUtils.remove(new int[] { 1, 2, 1 }, 1);
247: assertTrue(Arrays.equals(new int[] { 1, 1 }, array));
248: assertEquals(Integer.TYPE, array.getClass().getComponentType());
249: try {
250: ArrayUtils.remove(new int[] { 1, 2 }, -1);
251: fail("IndexOutOfBoundsException expected");
252: } catch (IndexOutOfBoundsException e) {
253: }
254: try {
255: ArrayUtils.remove(new int[] { 1, 2 }, 2);
256: fail("IndexOutOfBoundsException expected");
257: } catch (IndexOutOfBoundsException e) {
258: }
259: try {
260: ArrayUtils.remove((int[]) null, 0);
261: fail("IndexOutOfBoundsException expected");
262: } catch (IndexOutOfBoundsException e) {
263: }
264: }
265:
266: public void testRemoveLongArray() {
267: long[] array;
268: array = ArrayUtils.remove(new long[] { 1 }, 0);
269: assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array));
270: assertEquals(Long.TYPE, array.getClass().getComponentType());
271: array = ArrayUtils.remove(new long[] { 1, 2 }, 0);
272: assertTrue(Arrays.equals(new long[] { 2 }, array));
273: assertEquals(Long.TYPE, array.getClass().getComponentType());
274: array = ArrayUtils.remove(new long[] { 1, 2 }, 1);
275: assertTrue(Arrays.equals(new long[] { 1 }, array));
276: assertEquals(Long.TYPE, array.getClass().getComponentType());
277: array = ArrayUtils.remove(new long[] { 1, 2, 1 }, 1);
278: assertTrue(Arrays.equals(new long[] { 1, 1 }, array));
279: assertEquals(Long.TYPE, array.getClass().getComponentType());
280: try {
281: ArrayUtils.remove(new long[] { 1, 2 }, -1);
282: fail("IndexOutOfBoundsException expected");
283: } catch (IndexOutOfBoundsException e) {
284: }
285: try {
286: ArrayUtils.remove(new long[] { 1, 2 }, 2);
287: fail("IndexOutOfBoundsException expected");
288: } catch (IndexOutOfBoundsException e) {
289: }
290: try {
291: ArrayUtils.remove((long[]) null, 0);
292: fail("IndexOutOfBoundsException expected");
293: } catch (IndexOutOfBoundsException e) {
294: }
295: }
296:
297: public void testRemoveShortArray() {
298: short[] array;
299: array = ArrayUtils.remove(new short[] { 1 }, 0);
300: assertTrue(Arrays.equals(ArrayUtils.EMPTY_SHORT_ARRAY, array));
301: assertEquals(Short.TYPE, array.getClass().getComponentType());
302: array = ArrayUtils.remove(new short[] { 1, 2 }, 0);
303: assertTrue(Arrays.equals(new short[] { 2 }, array));
304: assertEquals(Short.TYPE, array.getClass().getComponentType());
305: array = ArrayUtils.remove(new short[] { 1, 2 }, 1);
306: assertTrue(Arrays.equals(new short[] { 1 }, array));
307: assertEquals(Short.TYPE, array.getClass().getComponentType());
308: array = ArrayUtils.remove(new short[] { 1, 2, 1 }, 1);
309: assertTrue(Arrays.equals(new short[] { 1, 1 }, array));
310: assertEquals(Short.TYPE, array.getClass().getComponentType());
311: try {
312: ArrayUtils.remove(new short[] { 1, 2 }, -1);
313: fail("IndexOutOfBoundsException expected");
314: } catch (IndexOutOfBoundsException e) {
315: }
316: try {
317: ArrayUtils.remove(new short[] { 1, 2 }, 2);
318: fail("IndexOutOfBoundsException expected");
319: } catch (IndexOutOfBoundsException e) {
320: }
321: try {
322: ArrayUtils.remove((short[]) null, 0);
323: fail("IndexOutOfBoundsException expected");
324: } catch (IndexOutOfBoundsException e) {
325: }
326: }
327:
328: public void testRemoveElementObjectArray() {
329: Object[] array;
330: array = ArrayUtils.removeElement((Object[]) null, "a");
331: assertNull(array);
332: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_OBJECT_ARRAY,
333: "a");
334: assertTrue(Arrays.equals(ArrayUtils.EMPTY_OBJECT_ARRAY, array));
335: assertEquals(Object.class, array.getClass().getComponentType());
336: array = ArrayUtils.removeElement(new Object[] { "a" }, "a");
337: assertTrue(Arrays.equals(ArrayUtils.EMPTY_OBJECT_ARRAY, array));
338: assertEquals(Object.class, array.getClass().getComponentType());
339: array = ArrayUtils
340: .removeElement(new Object[] { "a", "b" }, "a");
341: assertTrue(Arrays.equals(new Object[] { "b" }, array));
342: assertEquals(Object.class, array.getClass().getComponentType());
343: array = ArrayUtils.removeElement(
344: new Object[] { "a", "b", "a" }, "a");
345: assertTrue(Arrays.equals(new Object[] { "b", "a" }, array));
346: assertEquals(Object.class, array.getClass().getComponentType());
347: }
348:
349: public void testRemoveElementBooleanArray() {
350: boolean[] array;
351: array = ArrayUtils.removeElement((boolean[]) null, true);
352: assertNull(array);
353: array = ArrayUtils.removeElement(
354: ArrayUtils.EMPTY_BOOLEAN_ARRAY, true);
355: assertTrue(Arrays.equals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array));
356: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
357: array = ArrayUtils.removeElement(new boolean[] { true }, true);
358: assertTrue(Arrays.equals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array));
359: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
360: array = ArrayUtils.removeElement(new boolean[] { true, false },
361: true);
362: assertTrue(Arrays.equals(new boolean[] { false }, array));
363: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
364: array = ArrayUtils.removeElement(new boolean[] { true, false,
365: true }, true);
366: assertTrue(Arrays.equals(new boolean[] { false, true }, array));
367: assertEquals(Boolean.TYPE, array.getClass().getComponentType());
368: }
369:
370: public void testRemoveElementByteArray() {
371: byte[] array;
372: array = ArrayUtils.removeElement((byte[]) null, (byte) 1);
373: assertNull(array);
374: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_BYTE_ARRAY,
375: (byte) 1);
376: assertTrue(Arrays.equals(ArrayUtils.EMPTY_BYTE_ARRAY, array));
377: assertEquals(Byte.TYPE, array.getClass().getComponentType());
378: array = ArrayUtils.removeElement(new byte[] { 1 }, (byte) 1);
379: assertTrue(Arrays.equals(ArrayUtils.EMPTY_BYTE_ARRAY, array));
380: assertEquals(Byte.TYPE, array.getClass().getComponentType());
381: array = ArrayUtils.removeElement(new byte[] { 1, 2 }, (byte) 1);
382: assertTrue(Arrays.equals(new byte[] { 2 }, array));
383: assertEquals(Byte.TYPE, array.getClass().getComponentType());
384: array = ArrayUtils.removeElement(new byte[] { 1, 2, 1 },
385: (byte) 1);
386: assertTrue(Arrays.equals(new byte[] { 2, 1 }, array));
387: assertEquals(Byte.TYPE, array.getClass().getComponentType());
388: }
389:
390: public void testRemoveElementCharArray() {
391: char[] array;
392: array = ArrayUtils.removeElement((char[]) null, 'a');
393: assertNull(array);
394: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_CHAR_ARRAY,
395: 'a');
396: assertTrue(Arrays.equals(ArrayUtils.EMPTY_CHAR_ARRAY, array));
397: assertEquals(Character.TYPE, array.getClass()
398: .getComponentType());
399: array = ArrayUtils.removeElement(new char[] { 'a' }, 'a');
400: assertTrue(Arrays.equals(ArrayUtils.EMPTY_CHAR_ARRAY, array));
401: assertEquals(Character.TYPE, array.getClass()
402: .getComponentType());
403: array = ArrayUtils.removeElement(new char[] { 'a', 'b' }, 'a');
404: assertTrue(Arrays.equals(new char[] { 'b' }, array));
405: assertEquals(Character.TYPE, array.getClass()
406: .getComponentType());
407: array = ArrayUtils.removeElement(new char[] { 'a', 'b', 'a' },
408: 'a');
409: assertTrue(Arrays.equals(new char[] { 'b', 'a' }, array));
410: assertEquals(Character.TYPE, array.getClass()
411: .getComponentType());
412: }
413:
414: public void testRemoveElementDoubleArray() {
415: double[] array;
416: array = ArrayUtils.removeElement((double[]) null, (double) 1);
417: assertNull(array);
418: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_DOUBLE_ARRAY,
419: (double) 1);
420: assertTrue(Arrays.equals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array));
421: assertEquals(Double.TYPE, array.getClass().getComponentType());
422: array = ArrayUtils
423: .removeElement(new double[] { 1 }, (double) 1);
424: assertTrue(Arrays.equals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array));
425: assertEquals(Double.TYPE, array.getClass().getComponentType());
426: array = ArrayUtils.removeElement(new double[] { 1, 2 },
427: (double) 1);
428: assertTrue(Arrays.equals(new double[] { 2 }, array));
429: assertEquals(Double.TYPE, array.getClass().getComponentType());
430: array = ArrayUtils.removeElement(new double[] { 1, 2, 1 },
431: (double) 1);
432: assertTrue(Arrays.equals(new double[] { 2, 1 }, array));
433: assertEquals(Double.TYPE, array.getClass().getComponentType());
434: }
435:
436: public void testRemoveElementFloatArray() {
437: float[] array;
438: array = ArrayUtils.removeElement((float[]) null, (float) 1);
439: assertNull(array);
440: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_FLOAT_ARRAY,
441: (float) 1);
442: assertTrue(Arrays.equals(ArrayUtils.EMPTY_FLOAT_ARRAY, array));
443: assertEquals(Float.TYPE, array.getClass().getComponentType());
444: array = ArrayUtils.removeElement(new float[] { 1 }, (float) 1);
445: assertTrue(Arrays.equals(ArrayUtils.EMPTY_FLOAT_ARRAY, array));
446: assertEquals(Float.TYPE, array.getClass().getComponentType());
447: array = ArrayUtils.removeElement(new float[] { 1, 2 },
448: (float) 1);
449: assertTrue(Arrays.equals(new float[] { 2 }, array));
450: assertEquals(Float.TYPE, array.getClass().getComponentType());
451: array = ArrayUtils.removeElement(new float[] { 1, 2, 1 },
452: (float) 1);
453: assertTrue(Arrays.equals(new float[] { 2, 1 }, array));
454: assertEquals(Float.TYPE, array.getClass().getComponentType());
455: }
456:
457: public void testRemoveElementIntArray() {
458: int[] array;
459: array = ArrayUtils.removeElement((int[]) null, 1);
460: assertNull(array);
461: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_INT_ARRAY, 1);
462: assertTrue(Arrays.equals(ArrayUtils.EMPTY_INT_ARRAY, array));
463: assertEquals(Integer.TYPE, array.getClass().getComponentType());
464: array = ArrayUtils.removeElement(new int[] { 1 }, 1);
465: assertTrue(Arrays.equals(ArrayUtils.EMPTY_INT_ARRAY, array));
466: assertEquals(Integer.TYPE, array.getClass().getComponentType());
467: array = ArrayUtils.removeElement(new int[] { 1, 2 }, 1);
468: assertTrue(Arrays.equals(new int[] { 2 }, array));
469: assertEquals(Integer.TYPE, array.getClass().getComponentType());
470: array = ArrayUtils.removeElement(new int[] { 1, 2, 1 }, 1);
471: assertTrue(Arrays.equals(new int[] { 2, 1 }, array));
472: assertEquals(Integer.TYPE, array.getClass().getComponentType());
473: }
474:
475: public void testRemoveElementLongArray() {
476: long[] array;
477: array = ArrayUtils.removeElement((long[]) null, (long) 1);
478: assertNull(array);
479: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_LONG_ARRAY,
480: (long) 1);
481: assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array));
482: assertEquals(Long.TYPE, array.getClass().getComponentType());
483: array = ArrayUtils.removeElement(new long[] { 1 }, (long) 1);
484: assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array));
485: assertEquals(Long.TYPE, array.getClass().getComponentType());
486: array = ArrayUtils.removeElement(new long[] { 1, 2 }, (long) 1);
487: assertTrue(Arrays.equals(new long[] { 2 }, array));
488: assertEquals(Long.TYPE, array.getClass().getComponentType());
489: array = ArrayUtils.removeElement(new long[] { 1, 2, 1 },
490: (long) 1);
491: assertTrue(Arrays.equals(new long[] { 2, 1 }, array));
492: assertEquals(Long.TYPE, array.getClass().getComponentType());
493: }
494:
495: public void testRemoveElementShortArray() {
496: short[] array;
497: array = ArrayUtils.removeElement((short[]) null, (short) 1);
498: assertNull(array);
499: array = ArrayUtils.removeElement(ArrayUtils.EMPTY_SHORT_ARRAY,
500: (short) 1);
501: assertTrue(Arrays.equals(ArrayUtils.EMPTY_SHORT_ARRAY, array));
502: assertEquals(Short.TYPE, array.getClass().getComponentType());
503: array = ArrayUtils.removeElement(new short[] { 1 }, (short) 1);
504: assertTrue(Arrays.equals(ArrayUtils.EMPTY_SHORT_ARRAY, array));
505: assertEquals(Short.TYPE, array.getClass().getComponentType());
506: array = ArrayUtils.removeElement(new short[] { 1, 2 },
507: (short) 1);
508: assertTrue(Arrays.equals(new short[] { 2 }, array));
509: assertEquals(Short.TYPE, array.getClass().getComponentType());
510: array = ArrayUtils.removeElement(new short[] { 1, 2, 1 },
511: (short) 1);
512: assertTrue(Arrays.equals(new short[] { 2, 1 }, array));
513: assertEquals(Short.TYPE, array.getClass().getComponentType());
514: }
515:
516: }
|