junit4ify RangeTest

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1147536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Jason Benson 2011-07-17 06:01:17 +00:00
parent fe235bbb83
commit 6c65862a68
1 changed files with 27 additions and 3 deletions

View File

@ -17,9 +17,12 @@
package org.apache.commons.lang3;
import static org.junit.Assert.*;
import java.util.Comparator;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
/**
* <p>
@ -29,7 +32,7 @@ import junit.framework.TestCase;
* @version $Id$
*/
@SuppressWarnings("boxing")
public class RangeTest extends TestCase {
public class RangeTest {
private Range<Byte> byteRange;
private Range<Byte> byteRange2;
@ -41,7 +44,7 @@ public class RangeTest extends TestCase {
private Range<Double> doubleRange;
@SuppressWarnings("cast") // intRange
@Override
@Before
public void setUp() {
byteRange = Range.between((byte) 0, (byte) 5);
byteRange2 = Range.between((byte) 0, (byte) 5);
@ -55,6 +58,7 @@ public class RangeTest extends TestCase {
//-----------------------------------------------------------------------
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testComparableConstructors() {
Comparable c =
new Comparable() {
@ -68,6 +72,7 @@ public class RangeTest extends TestCase {
assertEquals(true, r2.isNaturalOrdering());
}
@Test
public void testIsWithCompare(){
Comparator<Integer> c = new Comparator<Integer>(){
public int compare(Integer o1, Integer o2) {
@ -84,6 +89,7 @@ public class RangeTest extends TestCase {
assertTrue("should contain 11",ri.contains(11));
}
@Test
public void testBetweenWithCompare(){
// TODO add tests with a better comparator
Comparator<Integer> c = new Comparator<Integer>(){
@ -106,6 +112,7 @@ public class RangeTest extends TestCase {
}
//-----------------------------------------------------------------------
@Test
public void testRangeOfChars() {
Range<Character> chars = Range.between('a', 'z');
assertTrue(chars.contains('b'));
@ -113,6 +120,7 @@ public class RangeTest extends TestCase {
}
//-----------------------------------------------------------------------
@Test
public void testEqualsObject() {
assertEquals(byteRange, byteRange);
assertEquals(byteRange, byteRange2);
@ -125,6 +133,7 @@ public class RangeTest extends TestCase {
assertFalse(byteRange2.equals("Ni!"));
}
@Test
public void testHashCode() {
assertEquals(byteRange.hashCode(), byteRange2.hashCode());
assertFalse(byteRange.hashCode() == byteRange3.hashCode());
@ -133,6 +142,7 @@ public class RangeTest extends TestCase {
assertTrue(intRange.hashCode() != 0);
}
@Test
public void testToString() {
assertNotNull(byteRange.toString());
@ -141,12 +151,14 @@ public class RangeTest extends TestCase {
assertEquals("[-20..-10]", Range.between(-20, -10).toString());
}
@Test
public void testToStringFormat() {
String str = intRange.toString("From %1$s to %2$s");
assertEquals("From 10 to 20", str);
}
//-----------------------------------------------------------------------
@Test
public void testGetMinimum() {
assertEquals(10, (int) intRange.getMinimum());
assertEquals(10L, (long) longRange.getMinimum());
@ -154,6 +166,7 @@ public class RangeTest extends TestCase {
assertEquals(10d, doubleRange.getMinimum(), 0.00001d);
}
@Test
public void testGetMaximum() {
assertEquals(20, (int) intRange.getMaximum());
assertEquals(20L, (long) longRange.getMaximum());
@ -161,6 +174,7 @@ public class RangeTest extends TestCase {
assertEquals(20d, doubleRange.getMaximum(), 0.00001d);
}
@Test
public void testContains() {
assertFalse(intRange.contains(null));
@ -171,6 +185,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.contains(25));
}
@Test
public void testIsAfter() {
assertFalse(intRange.isAfter(null));
@ -181,6 +196,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.isAfter(25));
}
@Test
public void testIsStartedBy() {
assertFalse(intRange.isStartedBy(null));
@ -191,6 +207,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.isStartedBy(25));
}
@Test
public void testIsEndedBy() {
assertFalse(intRange.isEndedBy(null));
@ -201,6 +218,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.isEndedBy(25));
}
@Test
public void testIsBefore() {
assertFalse(intRange.isBefore(null));
@ -211,6 +229,7 @@ public class RangeTest extends TestCase {
assertTrue(intRange.isBefore(25));
}
@Test
public void testElementCompareTo() {
try {
intRange.elementCompareTo(null);
@ -227,6 +246,7 @@ public class RangeTest extends TestCase {
}
//-----------------------------------------------------------------------
@Test
public void testContainsRange() {
// null handling
@ -258,6 +278,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.containsRange(Range.between(-11, -18)));
}
@Test
public void testIsAfterRange() {
assertFalse(intRange.isAfterRange(null));
@ -273,6 +294,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.isAfterRange(Range.between(10, 20)));
}
@Test
public void testIsOverlappedBy() {
// null handling
@ -304,6 +326,7 @@ public class RangeTest extends TestCase {
assertFalse(intRange.isOverlappedBy(Range.between(-11, -18)));
}
@Test
public void testIsBeforeRange() {
assertFalse(intRange.isBeforeRange(null));
@ -320,6 +343,7 @@ public class RangeTest extends TestCase {
}
//-----------------------------------------------------------------------
@Test
public void testSerializing() {
SerializationUtils.clone(intRange);
}