Author: mbenson
Date: Sun Jul 17 05:33:33 2011
New Revision: 1147531

URL: http://svn.apache.org/viewvc?rev=1147531&view=rev
Log:
junit expected exceptions

Modified:
    
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java

Modified: 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=1147531&r1=1147530&r2=1147531&view=diff
==============================================================================
--- 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
 (original)
+++ 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
 Sun Jul 17 05:33:33 2011
@@ -348,19 +348,18 @@ public class NumberUtilsTest {
 
     // min/max tests
     // ----------------------------------------------------------------------
-    @Test
-    public void testMinLong() {
-        final long[] l = null;
-        try {
-            NumberUtils.min(l);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinLong_nullArray() {
+        NumberUtils.min((long[]) null);
+    }
 
-        try {
-            NumberUtils.min(new long[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinLong_emptyArray() {
+        NumberUtils.min(new long[0]);
+    }
 
+    @Test
+    public void testMinLong() {
         assertEquals(
             "min(long[]) failed for array length 1",
             5,
@@ -375,19 +374,18 @@ public class NumberUtilsTest {
         assertEquals(-10, NumberUtils.min(new long[] { -5, 0, -10, 5, 10 }));
     }
 
-    @Test
-    public void testMinInt() {
-        final int[] i = null;
-        try {
-            NumberUtils.min(i);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinInt_nullArray() {
+        NumberUtils.min((int[]) null);
+    }
 
-        try {
-            NumberUtils.min(new int[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinInt_emptyArray() {
+        NumberUtils.min(new int[0]);
+    }
 
+    @Test
+    public void testMinInt() {
         assertEquals(
             "min(int[]) failed for array length 1",
             5,
@@ -402,19 +400,18 @@ public class NumberUtilsTest {
         assertEquals(-10, NumberUtils.min(new int[] { -5, 0, -10, 5, 10 }));
     }
 
-    @Test
-    public void testMinShort() {
-        final short[] s = null;
-        try {
-            NumberUtils.min(s);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinShort_nullArray() {
+        NumberUtils.min((short[]) null);
+    }
 
-        try {
-            NumberUtils.min(new short[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinShort_emptyArray() {
+        NumberUtils.min(new short[0]);
+    }
 
+    @Test
+    public void testMinShort() {
         assertEquals(
             "min(short[]) failed for array length 1",
             5,
@@ -429,19 +426,18 @@ public class NumberUtilsTest {
         assertEquals(-10, NumberUtils.min(new short[] { -5, 0, -10, 5, 10 }));
     }
 
-    @Test
-    public void testMinByte() {
-        final byte[] b = null;
-        try {
-            NumberUtils.min(b);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinByte_nullArray() {
+        NumberUtils.min((byte[]) null);
+    }
 
-        try {
-            NumberUtils.min(new byte[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinByte_emptyArray() {
+        NumberUtils.min(new byte[0]);
+    }
 
+    @Test
+    public void testMinByte() {
         assertEquals(
             "min(byte[]) failed for array length 1",
             5,
@@ -456,19 +452,18 @@ public class NumberUtilsTest {
         assertEquals(-10, NumberUtils.min(new byte[] { -5, 0, -10, 5, 10 }));
     }
 
-    @Test
-    public void testMinDouble() {
-        final double[] d = null;
-        try {
-            NumberUtils.min(d);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinDouble_nullArray() {
+        NumberUtils.min((double[]) null);
+    }
 
-        try {
-            NumberUtils.min(new double[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinDouble_emptyArray() {
+        NumberUtils.min(new double[0]);
+    }
 
+    @Test
+    public void testMinDouble() {
         assertEquals(
             "min(double[]) failed for array length 1",
             5.12,
@@ -490,19 +485,18 @@ public class NumberUtilsTest {
         assertEquals(-10, NumberUtils.min(new double[] { -5, 0, -10, 5, 10 }), 
0.0001);
     }
 
-    @Test
-    public void testMinFloat() {
-        final float[] f = null;
-        try {
-            NumberUtils.min(f);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinFloat_nullArray() {
+        NumberUtils.min((float[]) null);
+    }
 
-        try {
-            NumberUtils.min(new float[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMinFloat_emptyArray() {
+        NumberUtils.min(new float[0]);
+    }
 
+    @Test
+    public void testMinFloat() {
         assertEquals(
             "min(float[]) failed for array length 1",
             5.9f,
@@ -524,19 +518,18 @@ public class NumberUtilsTest {
         assertEquals(-10, NumberUtils.min(new float[] { -5, 0, -10, 5, 10 }), 
0.0001f);
     }
 
-    @Test
-    public void testMaxLong() {
-        final long[] l = null;
-        try {
-            NumberUtils.max(l);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxLong_nullArray() {
+        NumberUtils.max((long[]) null);
+    }
 
-        try {
-            NumberUtils.max(new long[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxLong_emptyArray() {
+        NumberUtils.max(new long[0]);
+    }
 
+    @Test
+    public void testMaxLong() {
         assertEquals(
             "max(long[]) failed for array length 1",
             5,
@@ -555,19 +548,18 @@ public class NumberUtilsTest {
         assertEquals(10, NumberUtils.max(new long[] { -5, 0, 10, 5, -10 }));
     }
 
-    @Test
-    public void testMaxInt() {
-        final int[] i = null;
-        try {
-            NumberUtils.max(i);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxInt_nullArray() {
+        NumberUtils.max((int[]) null);
+    }
 
-        try {
-            NumberUtils.max(new int[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxInt_emptyArray() {
+        NumberUtils.max(new int[0]);
+    }
 
+    @Test
+    public void testMaxInt() {
         assertEquals(
             "max(int[]) failed for array length 1",
             5,
@@ -586,19 +578,18 @@ public class NumberUtilsTest {
         assertEquals(10, NumberUtils.max(new int[] { -5, 0, 10, 5, -10 }));
     }
 
-    @Test
-    public void testMaxShort() {
-        final short[] s = null;
-        try {
-            NumberUtils.max(s);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxShort_nullArray() {
+        NumberUtils.max((short[]) null);
+    }
 
-        try {
-            NumberUtils.max(new short[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxShort_emptyArray() {
+        NumberUtils.max(new short[0]);
+    }
 
+    @Test
+    public void testMaxShort() {
         assertEquals(
             "max(short[]) failed for array length 1",
             5,
@@ -617,19 +608,18 @@ public class NumberUtilsTest {
         assertEquals(10, NumberUtils.max(new short[] { -5, 0, 10, 5, -10 }));
     }
 
-    @Test
-    public void testMaxByte() {
-        final byte[] b = null;
-        try {
-            NumberUtils.max(b);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxByte_nullArray() {
+        NumberUtils.max((byte[]) null);
+    }
 
-        try {
-            NumberUtils.max(new byte[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxByte_emptyArray() {
+        NumberUtils.max(new byte[0]);
+    }
 
+    @Test
+    public void testMaxByte() {
         assertEquals(
             "max(byte[]) failed for array length 1",
             5,
@@ -648,6 +638,16 @@ public class NumberUtilsTest {
         assertEquals(10, NumberUtils.max(new byte[] { -5, 0, 10, 5, -10 }));
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxDouble_nullArray() {
+        NumberUtils.max((double[]) null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxDouble_emptyArray() {
+        NumberUtils.max(new double[0]);
+    }
+
     @Test
     public void testMaxDouble() {
         final double[] d = null;
@@ -682,19 +682,18 @@ public class NumberUtilsTest {
         assertEquals(10, NumberUtils.max(new double[] { -5, 0, 10, 5, -10 }), 
0.0001);
     }
 
-    @Test
-    public void testMaxFloat() {
-        final float[] f = null;
-        try {
-            NumberUtils.max(f);
-            fail("No exception was thrown for null input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxFloat_nullArray() {
+        NumberUtils.max((float[]) null);
+    }
 
-        try {
-            NumberUtils.max(new float[0]);
-            fail("No exception was thrown for empty input.");
-        } catch (IllegalArgumentException ex) {}
+    @Test(expected = IllegalArgumentException.class)
+    public void testMaxFloat_emptyArray() {
+        NumberUtils.max(new float[0]);
+    }
 
+    @Test
+    public void testMaxFloat() {
         assertEquals(
             "max(float[]) failed for array length 1",
             5.1f,


Reply via email to