Adding @throws and test for the ClassCastException thrown by the ComparableComparator

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@835771 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-11-13 08:05:11 +00:00
parent 89af393b32
commit 4c124cea28
2 changed files with 26 additions and 4 deletions

View File

@ -41,10 +41,11 @@ public class Range<T> {
*
* @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 @@ public class Range<T> {
* @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);
}
/**

View File

@ -51,6 +51,26 @@ public class RangeTest extends TestCase {
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);