Author: bayard
Date: Fri Nov 13 08:05:11 2009
New Revision: 835771

URL: http://svn.apache.org/viewvc?rev=835771&view=rev
Log:
Adding @throws and test for the ClassCastException thrown by the 
ComparableComparator

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java?rev=835771&r1=835770&r2=835771&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java 
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java Fri 
Nov 13 08:05:11 2009
@@ -41,10 +41,11 @@
      *
      * @param element  the value to use for this range, must not be 
<code>null</code>
      * @throws IllegalArgumentException if the value is <code>null</code>
+     * @throws ClassCastException if the value is not Comparable
      */
-// TODO: Ideally this would only support <T extends Comparable<? super T>>
+    // TODO: Ideally the ClassCastException would be compile-time via generics
     public Range(T element) {
-        this(element, element);
+        this( element, element);
     }
 
     /**
@@ -59,10 +60,11 @@
      * @param element1  first value that defines the edge of the range, 
inclusive
      * @param element2  second value that defines the edge of the range, 
inclusive
      * @throws IllegalArgumentException if either value is <code>null</code>
+     * @throws ClassCastException if either value is not Comparable
      */
-// TODO: Ideally this would only support <T extends Comparable<? super T>>
+    // TODO: Ideally the ClassCastException would be compile-time via generics
     public Range(T element1, T element2) {
-        this(element1, element2, ComparableComparator.INSTANCE);
+        this( element1, element2, ComparableComparator.INSTANCE);
     }
 
     /**

Modified: 
commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java?rev=835771&r1=835770&r2=835771&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java 
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/RangeTest.java 
Fri Nov 13 08:05:11 2009
@@ -51,6 +51,26 @@
         doubleRange = new Range<Double>((double) 10, (double) 20);
     }
 
+    // 
--------------------------------------------------------------------------
+
+    public void testComparableConstructors() {
+        try {
+            Range range = new Range(new Object());
+            fail("IllegalArgumentException expected");
+        } catch(ClassCastException cce) {
+            // expected
+        }
+
+        try {
+            Range range = new Range(new Object(), new Object());
+            fail("ClassCastException expected");
+        } catch(ClassCastException cce) {
+            // expected
+        }
+    }
+
+    // 
--------------------------------------------------------------------------
+
     public void testEqualsObject() {
         assertEquals(byteRange, byteRange);
         assertEquals(byteRange, byteRange2);


Reply via email to