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:
parent
89af393b32
commit
4c124cea28
|
@ -41,10 +41,11 @@ public class Range<T> {
|
||||||
*
|
*
|
||||||
* @param element the value to use for this range, must not be <code>null</code>
|
* @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 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) {
|
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 element1 first value that defines the edge of the range, inclusive
|
||||||
* @param element2 second 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 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) {
|
public Range(T element1, T element2) {
|
||||||
this(element1, element2, ComparableComparator.INSTANCE);
|
this( element1, element2, ComparableComparator.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,6 +51,26 @@ public class RangeTest extends TestCase {
|
||||||
doubleRange = new Range<Double>((double) 10, (double) 20);
|
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() {
|
public void testEqualsObject() {
|
||||||
assertEquals(byteRange, byteRange);
|
assertEquals(byteRange, byteRange);
|
||||||
assertEquals(byteRange, byteRange2);
|
assertEquals(byteRange, byteRange2);
|
||||||
|
|
Loading…
Reference in New Issue