commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevencasw...@apache.org
Subject svn commit: r234394 - in /jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang: ArrayUtilsAddTest.java ArrayUtilsTest.java
Date Mon, 22 Aug 2005 00:16:06 GMT
Author: stevencaswell
Date: Sun Aug 21 17:16:03 2005
New Revision: 234394

URL: http://svn.apache.org/viewcvs?rev=234394&view=rev
Log:
increase ArrayUtils test coverage as reported by clover

Modified:
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java?rev=234394&r1=234393&r2=234394&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java
Sun Aug 21 17:16:03 2005
@@ -248,34 +248,82 @@
         assertTrue( Arrays.equals( new boolean[] { true, false, false, true }, 
             ArrayUtils.addAll( new boolean[] { true, false }, new boolean[] { false, true
} ) ) );
 
+        assertTrue( Arrays.equals( new boolean[] { false, true }, 
+            ArrayUtils.addAll( null, new boolean[] { false, true } ) ) );
+
+        assertTrue( Arrays.equals( new boolean[] { true, false }, 
+            ArrayUtils.addAll( new boolean[] { true, false }, null ) ) );
+
         // char
         assertTrue( Arrays.equals( new char[] { 'a', 'b', 'c', 'd' }, 
             ArrayUtils.addAll( new char[] { 'a', 'b' }, new char[] { 'c', 'd' } ) ) );
 
+        assertTrue( Arrays.equals( new char[] { 'c', 'd' }, 
+            ArrayUtils.addAll( null, new char[] { 'c', 'd' } ) ) );
+
+        assertTrue( Arrays.equals( new char[] { 'a', 'b' }, 
+            ArrayUtils.addAll( new char[] { 'a', 'b' }, null ) ) );
+
         // byte
         assertTrue( Arrays.equals( new byte[] { (byte) 0, (byte) 1, (byte) 2, (byte) 3 },

             ArrayUtils.addAll( new byte[] { (byte) 0, (byte) 1 }, new byte[] { (byte) 2,
(byte) 3 } ) ) );
 
+        assertTrue( Arrays.equals( new byte[] { (byte) 2, (byte) 3 }, 
+            ArrayUtils.addAll( null, new byte[] { (byte) 2, (byte) 3 } ) ) );
+
+        assertTrue( Arrays.equals( new byte[] { (byte) 0, (byte) 1 }, 
+            ArrayUtils.addAll( new byte[] { (byte) 0, (byte) 1 }, null ) ) );
+
         // short
         assertTrue( Arrays.equals( new short[] { (short) 10, (short) 20, (short) 30, (short)
40 }, 
             ArrayUtils.addAll( new short[] { (short) 10, (short) 20 }, new short[] { (short)
30, (short) 40 } ) ) );
 
+        assertTrue( Arrays.equals( new short[] { (short) 30, (short) 40 }, 
+            ArrayUtils.addAll( null, new short[] { (short) 30, (short) 40 } ) ) );
+
+        assertTrue( Arrays.equals( new short[] { (short) 10, (short) 20 }, 
+            ArrayUtils.addAll( new short[] { (short) 10, (short) 20 }, null ) ) );
+
         // int
         assertTrue( Arrays.equals( new int[] { 1, 1000, -1000, -1 }, 
             ArrayUtils.addAll( new int[] { 1, 1000 }, new int[] { -1000, -1 } ) ) );
 
+        assertTrue( Arrays.equals( new int[] { -1000, -1 }, 
+            ArrayUtils.addAll( null, new int[] { -1000, -1 } ) ) );
+
+        assertTrue( Arrays.equals( new int[] { 1, 1000 }, 
+            ArrayUtils.addAll( new int[] { 1, 1000 }, null ) ) );
+
         // long
         assertTrue( Arrays.equals( new long[] { 1L, -1L, 1000L, -1000L }, 
             ArrayUtils.addAll( new long[] { 1L, -1L }, new long[] { 1000L, -1000L } ) ) );
 
+        assertTrue( Arrays.equals( new long[] { 1000L, -1000L }, 
+            ArrayUtils.addAll( null, new long[] { 1000L, -1000L } ) ) );
+        
+        assertTrue( Arrays.equals( new long[] { 1L, -1L }, 
+            ArrayUtils.addAll( new long[] { 1L, -1L }, null ) ) );
+
         // float
         assertTrue( Arrays.equals( new float[] { 10.5f, 10.1f, 1.6f, 0.01f }, 
             ArrayUtils.addAll( new float[] { 10.5f, 10.1f }, new float[] { 1.6f, 0.01f }
) ) );
 
+        assertTrue( Arrays.equals( new float[] { 1.6f, 0.01f }, 
+            ArrayUtils.addAll( null, new float[] { 1.6f, 0.01f } ) ) );
+
+        assertTrue( Arrays.equals( new float[] { 10.5f, 10.1f }, 
+            ArrayUtils.addAll( new float[] { 10.5f, 10.1f }, null ) ) );
+
         // double
         assertTrue( Arrays.equals( new double[] { Math.PI, -Math.PI, 0, 9.99 }, 
             ArrayUtils.addAll( new double[] { Math.PI, -Math.PI }, new double[] { 0, 9.99
} ) ) );
 
+        assertTrue( Arrays.equals( new double[] { 0, 9.99 }, 
+            ArrayUtils.addAll( null, new double[] { 0, 9.99 } ) ) );
+
+        assertTrue( Arrays.equals( new double[] { Math.PI, -Math.PI }, 
+            ArrayUtils.addAll( new double[] { Math.PI, -Math.PI }, null ) ) );
+
     }    
     
     public void testAddObjectAtIndex() {
@@ -322,16 +370,36 @@
         // boolean tests
         boolean[] booleanArray = ArrayUtils.add( null, 0, true );
         assertTrue( Arrays.equals( new boolean[] { true }, booleanArray ) );
+        try {
+            booleanArray = ArrayUtils.add( null, -1, true );
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         booleanArray = ArrayUtils.add( new boolean[] { true }, 0, false);
         assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
         booleanArray = ArrayUtils.add( new boolean[] { false }, 1, true);
         assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
         booleanArray = ArrayUtils.add( new boolean[] { true, false }, 1, true);
         assertTrue( Arrays.equals( new boolean[] { true, true, false }, booleanArray ) );
+        try {
+            booleanArray = ArrayUtils.add( new boolean[] { true, false }, 4, true);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            booleanArray = ArrayUtils.add( new boolean[] { true, false }, -1, true);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // char tests
         char[] charArray = ArrayUtils.add( (char[]) null, 0, 'a' );
         assertTrue( Arrays.equals( new char[] { 'a' }, charArray ) );
+        try {
+            charArray = ArrayUtils.add( (char[]) null, -1, 'a' );
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         charArray = ArrayUtils.add( new char[] { 'a' }, 0, 'b');
         assertTrue( Arrays.equals( new char[] { 'b', 'a' }, charArray ) );
         charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 0, 'c');
@@ -340,66 +408,166 @@
         assertTrue( Arrays.equals( new char[] { 'a', 'k', 'b' }, charArray ) );
         charArray = ArrayUtils.add( new char[] { 'a', 'b', 'c' }, 1, 't');
         assertTrue( Arrays.equals( new char[] { 'a', 't', 'b', 'c' }, charArray ) );
+        try {
+            charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 4, 'c');
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            charArray = ArrayUtils.add( new char[] { 'a', 'b' }, -1, 'c');
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // short tests
         short[] shortArray = ArrayUtils.add( new short[] { 1 }, 0, (short) 2);
         assertTrue( Arrays.equals( new short[] { 2, 1 }, shortArray ) );
+        try {
+            shortArray = ArrayUtils.add( (short[]) null, -1, (short) 2);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         shortArray = ArrayUtils.add( new short[] { 2, 6 }, 2, (short) 10);
         assertTrue( Arrays.equals( new short[] { 2, 6, 10 }, shortArray ) );
         shortArray = ArrayUtils.add( new short[] { 2, 6 }, 0, (short) -4);
         assertTrue( Arrays.equals( new short[] { -4, 2, 6 }, shortArray ) );
         shortArray = ArrayUtils.add( new short[] { 2, 6, 3 }, 2, (short) 1);
         assertTrue( Arrays.equals( new short[] { 2, 6, 1, 3 }, shortArray ) );
+        try {
+            shortArray = ArrayUtils.add( new short[] { 2, 6 }, 4, (short) 10);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            shortArray = ArrayUtils.add( new short[] { 2, 6 }, -1, (short) 10);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // byte tests
         byte[] byteArray = ArrayUtils.add( new byte[] { 1 }, 0, (byte) 2);
         assertTrue( Arrays.equals( new byte[] { 2, 1 }, byteArray ) );
+        try {
+            byteArray = ArrayUtils.add( (byte[]) null, -1, (byte) 2);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 2, (byte) 3);
         assertTrue( Arrays.equals( new byte[] { 2, 6, 3 }, byteArray ) );
         byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 0, (byte) 1);
         assertTrue( Arrays.equals( new byte[] { 1, 2, 6 }, byteArray ) );
         byteArray = ArrayUtils.add( new byte[] { 2, 6, 3 }, 2, (byte) 1);
         assertTrue( Arrays.equals( new byte[] { 2, 6, 1, 3 }, byteArray ) );
+        try {
+            byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 4, (byte) 3);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            byteArray = ArrayUtils.add( new byte[] { 2, 6 }, -1, (byte) 3);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // int tests
         int[] intArray = ArrayUtils.add( new int[] { 1 }, 0, 2);
         assertTrue( Arrays.equals( new int[] { 2, 1 }, intArray ) );
+        try {
+            intArray = ArrayUtils.add( (int[]) null, -1, 2);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         intArray = ArrayUtils.add( new int[] { 2, 6 }, 2, 10);
         assertTrue( Arrays.equals( new int[] { 2, 6, 10 }, intArray ) );
         intArray = ArrayUtils.add( new int[] { 2, 6 }, 0, -4);
         assertTrue( Arrays.equals( new int[] { -4, 2, 6 }, intArray ) );
         intArray = ArrayUtils.add( new int[] { 2, 6, 3 }, 2, 1);
         assertTrue( Arrays.equals( new int[] { 2, 6, 1, 3 }, intArray ) );
+        try {
+            intArray = ArrayUtils.add( new int[] { 2, 6 }, 4, 10);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            intArray = ArrayUtils.add( new int[] { 2, 6 }, -1, 10);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // long tests
         long[] longArray = ArrayUtils.add( new long[] { 1L }, 0, 2L);
         assertTrue( Arrays.equals( new long[] { 2L, 1L }, longArray ) );
+        try {
+            longArray = ArrayUtils.add( (long[]) null, -1, 2L);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         longArray = ArrayUtils.add( new long[] { 2L, 6L }, 2, 10L);
         assertTrue( Arrays.equals( new long[] { 2L, 6L, 10L }, longArray ) );
         longArray = ArrayUtils.add( new long[] { 2L, 6L }, 0, -4L);
         assertTrue( Arrays.equals( new long[] { -4L, 2L, 6L }, longArray ) );
         longArray = ArrayUtils.add( new long[] { 2L, 6L, 3L }, 2, 1L);
         assertTrue( Arrays.equals( new long[] { 2L, 6L, 1L, 3L }, longArray ) );
+        try {
+            longArray = ArrayUtils.add( new long[] { 2L, 6L }, 4, 10L);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            longArray = ArrayUtils.add( new long[] { 2L, 6L }, -1, 10L);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // float tests
         float[] floatArray = ArrayUtils.add( new float[] { 1.1f }, 0, 2.2f);
         assertTrue( Arrays.equals( new float[] { 2.2f, 1.1f }, floatArray ) );
+        try {
+            floatArray = ArrayUtils.add( (float[]) null, -1, 2.2f);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 2, 10.5f);
         assertTrue( Arrays.equals( new float[] { 2.3f, 6.4f, 10.5f }, floatArray ) );
         floatArray = ArrayUtils.add( new float[] { 2.6f, 6.7f }, 0, -4.8f);
         assertTrue( Arrays.equals( new float[] { -4.8f, 2.6f, 6.7f }, floatArray ) );
         floatArray = ArrayUtils.add( new float[] { 2.9f, 6.0f, 0.3f }, 2, 1.0f);
         assertTrue( Arrays.equals( new float[] { 2.9f, 6.0f, 1.0f, 0.3f }, floatArray ) );
+        try {
+            floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 4, 10.5f);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, -1, 10.5f);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
 
         // double tests
         double[] doubleArray = ArrayUtils.add( new double[] { 1.1 }, 0, 2.2);
         assertTrue( Arrays.equals( new double[] { 2.2, 1.1 }, doubleArray ) );
+        try {
+          doubleArray = ArrayUtils.add( (double[]) null, -1, 2.2);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 0", e.getMessage());
+        }
         doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 2, 10.5);
         assertTrue( Arrays.equals( new double[] { 2.3, 6.4, 10.5 }, doubleArray ) );
         doubleArray = ArrayUtils.add( new double[] { 2.6, 6.7 }, 0, -4.8);
         assertTrue( Arrays.equals( new double[] { -4.8, 2.6, 6.7 }, doubleArray ) );
         doubleArray = ArrayUtils.add( new double[] { 2.9, 6.0, 0.3 }, 2, 1.0);
         assertTrue( Arrays.equals( new double[] { 2.9, 6.0, 1.0, 0.3 }, doubleArray ) );
+        try {
+            doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 4, 10.5);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: 4, Length: 2", e.getMessage());
+        }
+        try {
+            doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, -1, 10.5);
+        } catch(IndexOutOfBoundsException e) {
+            assertEquals("Index: -1, Length: 2", e.getMessage());
+        }
     }
     
 }

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java?rev=234394&r1=234393&r2=234394&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ArrayUtilsTest.java
Sun Aug 21 17:16:03 2005
@@ -1811,6 +1811,8 @@
         assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0));
         array = new double[0];
         assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0));
+        array = new double[] { (double) 3 };
+        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 1, 0, (double) 0));
         array = new double[] { 0, 1, 2, 3, 0 };
         assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 99, (double) 0.3));
         assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 3, (double) 0.3));



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message