Author: ggregory
Date: Sun Jul 31 17:30:42 2005
New Revision: 226708

URL: http://svn.apache.org/viewcvs?rev=226708&view=rev
Log:
Better unit test code coverage.

Modified:
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/AbstractRangeTest.java
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/DoubleRangeTest.java
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/FloatRangeTest.java
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/NumberRangeTest.java

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/AbstractRangeTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/AbstractRangeTest.java?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/AbstractRangeTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/AbstractRangeTest.java
 Sun Jul 31 17:30:42 2005
@@ -63,10 +63,9 @@
         public long longValue() {
             return 12L;
         }
-
     }
     
-    protected InnerNumber nonComparable = new InnerNumber();
+    protected InnerNumber nonComparableNumber = new InnerNumber();
 
 
     public AbstractRangeTest(String name) {
@@ -74,30 +73,30 @@
     }
 
     public void setUp() {
-        five        = new Integer(5);
-        ten         = new Integer(10);
-        twelve      = new Integer(12);
-        fifteen     = new Integer(15);
-        twenty      = new Integer(20);
-        twentyFive  = new Integer(25);
-        long8       = new Long(8);
-        long10      = new Long(10);
-        long12      = new Long(12);
-        long20      = new Long(20);
-        long21      = new Long(21);
-        double8     = new Double(8);
-        double10    = new Double(10);
-        double12    = new Double(12);
-        double20    = new Double(20);
-        double21    = new Double(21);
-        float8      = new Float(8);
-        float10     = new Float(10);
-        float12     = new Float(12);
-        float20     = new Float(20);
-        float21     = new Float(21);
+        five = new Integer(5);
+        ten = new Integer(10);
+        twelve = new Integer(12);
+        fifteen = new Integer(15);
+        twenty = new Integer(20);
+        twentyFive = new Integer(25);
+        long8 = new Long(8);
+        long10 = new Long(10);
+        long12 = new Long(12);
+        long20 = new Long(20);
+        long21 = new Long(21);
+        double8 = new Double(8);
+        double10 = new Double(10);
+        double12 = new Double(12);
+        double20 = new Double(20);
+        double21 = new Double(21);
+        float8 = new Float(8);
+        float10 = new Float(10);
+        float12 = new Float(12);
+        float20 = new Float(20);
+        float21 = new Float(21);
     }
 
-    
//--------------------------------------------------------------------------
+    // 
--------------------------------------------------------------------------
 
     public void testGetMinimum() {
         assertEquals(10L, tenToTwenty.getMinimumLong());
@@ -117,7 +116,7 @@
 
     public void testContainsLong() {
         assertEquals(false, tenToTwenty.containsLong(null));
-        assertEquals(true, tenToTwenty.containsLong(nonComparable));
+        assertEquals(true, tenToTwenty.containsLong(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsLong(five));
         assertEquals(true, tenToTwenty.containsLong(ten));
@@ -152,7 +151,7 @@
         
     public void testContainsInteger() {
         assertEquals(false, tenToTwenty.containsInteger(null));
-        assertEquals(true, tenToTwenty.containsInteger(nonComparable));
+        assertEquals(true, tenToTwenty.containsInteger(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsInteger(five));
         assertEquals(true, tenToTwenty.containsInteger(ten));
@@ -187,7 +186,7 @@
 
     public void testContainsDouble() {
         assertEquals(false, tenToTwenty.containsDouble(null));
-        assertEquals(true, tenToTwenty.containsDouble(nonComparable));
+        assertEquals(true, tenToTwenty.containsDouble(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsDouble(five));
         assertEquals(true, tenToTwenty.containsDouble(ten));
@@ -222,7 +221,7 @@
 
     public void testContainsFloat() {
         assertEquals(false, tenToTwenty.containsFloat(null));
-        assertEquals(true, tenToTwenty.containsFloat(nonComparable));
+        assertEquals(true, tenToTwenty.containsFloat(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsFloat(five));
         assertEquals(true, tenToTwenty.containsFloat(ten));

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/DoubleRangeTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/DoubleRangeTest.java?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/DoubleRangeTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/DoubleRangeTest.java
 Sun Jul 31 17:30:42 2005
@@ -67,7 +67,7 @@
         assertSame(double8, nr.getMinimumNumber());
         assertSame(double8, nr.getMaximumNumber());
         
-        Range r = new DoubleRange(nonComparable);
+        Range r = new DoubleRange(nonComparableNumber);
         
         try {
             new DoubleRange(null);
@@ -131,7 +131,7 @@
 
     public void testContainsNumber() {
         assertEquals(false, tenToTwenty.containsNumber(null));
-        assertEquals(true, tenToTwenty.containsNumber(nonComparable));
+        assertEquals(true, tenToTwenty.containsNumber(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsNumber(five));
         assertEquals(true, tenToTwenty.containsNumber(ten));

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/FloatRangeTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/FloatRangeTest.java?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/FloatRangeTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/FloatRangeTest.java
 Sun Jul 31 17:30:42 2005
@@ -67,7 +67,7 @@
         assertSame(float8, nr.getMinimumNumber());
         assertSame(float8, nr.getMaximumNumber());
         
-        Range r = new FloatRange(nonComparable);
+        Range r = new FloatRange(nonComparableNumber);
         
         try {
             new FloatRange(null);
@@ -131,7 +131,7 @@
 
     public void testContainsNumber() {
         assertEquals(false, tenToTwenty.containsNumber(null));
-        assertEquals(true, tenToTwenty.containsNumber(nonComparable));
+        assertEquals(true, tenToTwenty.containsNumber(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsNumber(five));
         assertEquals(true, tenToTwenty.containsNumber(ten));

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/IntRangeTest.java
 Sun Jul 31 17:30:42 2005
@@ -64,7 +64,7 @@
         assertSame(five, nr.getMinimumNumber());
         assertSame(five, nr.getMaximumNumber());
         
-        Range r = new IntRange(nonComparable);
+        Range r = new IntRange(nonComparableNumber);
         
         try {
             new IntRange(null);
@@ -124,7 +124,7 @@
 
     public void testContainsNumber() {
         assertEquals(false, tenToTwenty.containsNumber(null));
-        assertEquals(true, tenToTwenty.containsNumber(nonComparable));
+        assertEquals(true, tenToTwenty.containsNumber(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsNumber(five));
         assertEquals(true, tenToTwenty.containsNumber(ten));

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/LongRangeTest.java
 Sun Jul 31 17:30:42 2005
@@ -62,7 +62,7 @@
         assertSame(long8, nr.getMinimumNumber());
         assertSame(long8, nr.getMaximumNumber());
         
-        Range r = new LongRange(nonComparable);
+        Range r = new LongRange(nonComparableNumber);
         
         try {
             new LongRange(null);
@@ -112,7 +112,7 @@
 
     public void testContainsNumber() {
         assertEquals(false, tenToTwenty.containsNumber(null));
-        assertEquals(true, tenToTwenty.containsNumber(nonComparable));
+        assertEquals(true, tenToTwenty.containsNumber(nonComparableNumber));
         
         assertEquals(false, tenToTwenty.containsNumber(five));
         assertEquals(true, tenToTwenty.containsNumber(ten));

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/NumberRangeTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/NumberRangeTest.java?rev=226708&r1=226707&r2=226708&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/NumberRangeTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/math/NumberRangeTest.java
 Sun Jul 31 17:30:42 2005
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.commons.lang.math;
 
 import junit.framework.Test;
@@ -20,7 +21,7 @@
 
 /**
  * Test cases for the [EMAIL PROTECTED] NumberRange} class.
- *
+ * 
  * @author <a href="mailto:[EMAIL PROTECTED]">Christopher Elkins</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Ringo De Smet</a>
  * @author Stephen Colebourne
@@ -28,143 +29,119 @@
  */
 public final class NumberRangeTest extends AbstractRangeTest {
 
-    public NumberRangeTest(String name) {
-        super(name);
-    }
-
     public static Test suite() {
         TestSuite suite = new TestSuite(NumberRangeTest.class);
         suite.setName("NumberRange Tests");
         return suite;
     }
-    
-    public void setUp() {
-        super.setUp();
-        tenToTwenty = new NumberRange(ten, twenty);
-        otherRange = new IntRange(ten, twenty);
-    }
 
-    protected Range createRange(Integer integer1, Integer integer2) {
-        return new NumberRange(integer1, integer2);
-    }
-    protected Range createRange(Integer integer) {
-        return new NumberRange(integer);
+    public NumberRangeTest(String name) {
+        super(name);
     }
 
-    
//--------------------------------------------------------------------------
-
-    public void testConstructorExceptions() {
+    void checkConstructorException(Number num) {
         try {
-            new NumberRange (new Double (Double.NaN));
-            fail("no illegal argument exception");
+            new NumberRange(num);
+            fail("Expected an IllegalArgumentException");
         } catch (IllegalArgumentException e) {
+            // Expected.
         }
-        
-        try {
-            new NumberRange (new Double (Double.NaN), new Double (12.2));
-            fail("no illegal argument exception");
-        } catch (IllegalArgumentException e) {
-        }
-        
-        try {
-            new NumberRange (new Double (12.2), new Double (Double.NaN));
-            fail("no illegal argument exception");
-        } catch (IllegalArgumentException e) {
-        }
-        
-        try {
-            new NumberRange (new Float (Float.NaN));
-            fail("no illegal argument exception");
-        } catch (IllegalArgumentException e) {
-        }
-        
+    }
+
+    void checkConstructorException(Number num1, Number num2) {
         try {
-            new NumberRange (new Float (Float.NaN), new Float(12.2));
-            fail("no illegal argument exception");
+            new NumberRange(num1, num2);
+            fail("Expected an IllegalArgumentException");
         } catch (IllegalArgumentException e) {
+            // Expected.
         }
-        
-        try {
-            new NumberRange (new Float(12.2), new Float (Float.NaN));
-            fail("no illegal argument exception");
-        } catch (IllegalArgumentException e) {
-        }       
     }
-    
+
+    protected Range createRange(Integer integer) {
+        return new NumberRange(integer);
+    }
+
+    // 
--------------------------------------------------------------------------
+
+    protected Range createRange(Integer integer1, Integer integer2) {
+        return new NumberRange(integer1, integer2);
+    }
+
+    public void setUp() {
+        super.setUp();
+        tenToTwenty = new NumberRange(ten, twenty);
+        otherRange = new IntRange(ten, twenty);
+    }
+
+    /**
+     * Tests non-exceptional conditions for the one argument constructor.
+     */
     public void testConstructor1() {
         NumberRange nr = new NumberRange(five);
         assertSame(five, nr.getMinimumNumber());
         assertSame(five, nr.getMaximumNumber());
-        
-        try {
-            new NumberRange(null);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        try {
-            new NumberRange(nonComparable);
-            fail();
-        } catch (IllegalArgumentException ex) {}
     }
-    
+
+    /**
+     * Tests exceptional conditions for the one argument constructor.
+     */
+    public void testConstructor1Exceptions() {
+        this.checkConstructorException(null);
+        this.checkConstructorException(nonComparableNumber);
+        this.checkConstructorException(new Float(Float.NaN));
+        this.checkConstructorException(new Double(Double.NaN));
+    }
+
+    /**
+     * Tests non-exceptional conditions for the two argument constructor.
+     */
     public void testConstructor2() {
         NumberRange nr = new NumberRange(five, ten);
         assertSame(five, nr.getMinimumNumber());
         assertSame(ten, nr.getMaximumNumber());
-        
+
         nr = new NumberRange(ten, five);
         assertSame(five, nr.getMinimumNumber());
         assertSame(ten, nr.getMaximumNumber());
-        
-        // not null
-        try {
-            new NumberRange(five, null);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        try {
-            new NumberRange(null, five);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        try {
-            new NumberRange(null, null);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
-        // no mixed types
-        try {
-            new NumberRange(five, long21);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
-        // must be comparable
-        try {
-            new NumberRange(nonComparable, nonComparable);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
-        // no double NaN
-        try {
-            new NumberRange(new Double(0), new Double(Double.NaN));
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
-        try {
-            new NumberRange(new Double(Double.NaN), new Double(0));
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
-        // no float NaN
-        try {
-            new NumberRange(new Float(0), new Float(Float.NaN));
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
-        try {
-            new NumberRange(new Float(Float.NaN), new Float(0));
-            fail();
-        } catch (IllegalArgumentException ex) {}
     }
 
-    
//--------------------------------------------------------------------------
+    /**
+     * Tests exceptional conditions for the two argument constructor.
+     */
+    public void testConstructor2Exceptions() {
+        this.checkConstructorException(null, null);
+
+        this.checkConstructorException(new Float(12.2f), new Double(12.2));
+        this.checkConstructorException(new Float(Float.NaN), new Double(12.2));
+        this.checkConstructorException(new Double(Double.NaN), new 
Double(12.2));
+        this.checkConstructorException(new Double(12.2), new 
Double(Double.NaN));
+        this.checkConstructorException(new Double(Double.NaN), new 
Double(Double.NaN));
+        this.checkConstructorException(null, new Double(12.2));
+        this.checkConstructorException(new Double(12.2), null);
+
+        this.checkConstructorException(new Double(12.2f), new Float(12.2));
+        this.checkConstructorException(new Double(Double.NaN), new 
Float(12.2));
+        this.checkConstructorException(new Float(Float.NaN), new Float(12.2));
+        this.checkConstructorException(new Float(12.2), new Float(Float.NaN));
+        this.checkConstructorException(new Float(Float.NaN), new 
Float(Float.NaN));
+        this.checkConstructorException(null, new Float(12.2));
+        this.checkConstructorException(new Float(12.2), null);
+
+        this.checkConstructorException(nonComparableNumber, 
nonComparableNumber);
+        this.checkConstructorException(null, nonComparableNumber);
+        this.checkConstructorException(nonComparableNumber, null);
+        this.checkConstructorException(new Float(12.2), nonComparableNumber);
+        this.checkConstructorException(nonComparableNumber, new Float(12.2));
+    }
+
+    // 
--------------------------------------------------------------------------
+
+    public void testContainsLongBig() {
+        // original NumberRange class failed this test
+        NumberRange big = new NumberRange(new Long(Long.MAX_VALUE), new 
Long(Long.MAX_VALUE - 2));
+        assertEquals(true, big.containsLong(Long.MAX_VALUE - 1));
+        assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
+    }
 
     public void testContainsNumber() {
         assertEquals(false, tenToTwenty.containsNumber(null));
@@ -173,20 +150,14 @@
         assertEquals(true, tenToTwenty.containsNumber(fifteen));
         assertEquals(true, tenToTwenty.containsNumber(twenty));
         assertEquals(false, tenToTwenty.containsNumber(twentyFive));
-        
+
         try {
             tenToTwenty.containsNumber(long21);
             fail();
-        } catch (IllegalArgumentException ex) {}
-    }
-
-    public void testContainsLongBig() {
-        // original NumberRange class failed this test
-        NumberRange big = new NumberRange(new Long(Long.MAX_VALUE), new 
Long(Long.MAX_VALUE- 2));
-        assertEquals(true, big.containsLong(Long.MAX_VALUE - 1));
-        assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
+        } catch (IllegalArgumentException ex) {
+        }
     }
 
-    
//--------------------------------------------------------------------------
+    // 
--------------------------------------------------------------------------
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to