[LANG-824] Conversion of 3.x JUnit tests to 4.x; thanks to Duncan Jones
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1387361 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index af1b122..9e41408 100644
--- a/pom.xml
+++ b/pom.xml
@@ -260,6 +260,9 @@
<name>Marc Johnson</name>
</contributor>
<contributor>
+ <name>Duncan Jones</name>
+ </contributor>
+ <contributor>
<name>Shaun Kalley</name>
</contributor>
<contributor>
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index b5beb6f..5eb879f 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -16,26 +16,33 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.ArrayUtils}.
*
* @version $Id$
*/
-public class ArrayUtilsTest extends TestCase {
-
- public ArrayUtilsTest(String name) {
- super(name);
- }
+public class ArrayUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new ArrayUtils());
Constructor<?>[] cons = ArrayUtils.class.getDeclaredConstructors();
@@ -46,6 +53,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testToString() {
assertEquals("{}", ArrayUtils.toString(null));
assertEquals("{}", ArrayUtils.toString(new Object[0]));
@@ -61,6 +69,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testHashCode() {
long[][] array1 = new long[][] {{2,5}, {4,5}};
long[][] array2 = new long[][] {{2,5}, {4,6}};
@@ -90,6 +99,7 @@
assertEquals(false, ArrayUtils.isEquals(array2, array1));
}
+ @Test
public void testIsEquals() {
long[][] larray1 = new long[][]{{2, 5}, {4, 5}};
long[][] larray2 = new long[][]{{2, 5}, {4, 6}};
@@ -144,6 +154,7 @@
/**
* Tests generic array creation with parameters of same type.
*/
+ @Test
public void testArrayCreation()
{
final String[] array = ArrayUtils.toArray("foo", "bar");
@@ -155,6 +166,7 @@
/**
* Tests generic array creation with general return type.
*/
+ @Test
public void testArrayCreationWithGeneralReturnType()
{
final Object obj = ArrayUtils.toArray("foo", "bar");
@@ -164,6 +176,7 @@
/**
* Tests generic array creation with parameters of common base type.
*/
+ @Test
public void testArrayCreationWithDifferentTypes()
{
final Number[] array = ArrayUtils.<Number>toArray(Integer.valueOf(42), Double.valueOf(Math.PI));
@@ -175,6 +188,7 @@
/**
* Tests generic array creation with generic type.
*/
+ @Test
public void testIndirectArrayCreation()
{
final String[] array = toArrayPropagatingType("foo", "bar");
@@ -186,6 +200,7 @@
/**
* Tests generic empty array creation with generic type.
*/
+ @Test
public void testEmptyArrayCreation()
{
final String[] array = ArrayUtils.<String>toArray();
@@ -195,6 +210,7 @@
/**
* Tests indirect generic empty array creation with generic type.
*/
+ @Test
public void testIndirectEmptyArrayCreation()
{
final String[] array = ArrayUtilsTest.<String>toArrayPropagatingType();
@@ -207,6 +223,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testToMap() {
Map<?, ?> map = ArrayUtils.toMap(new String[][] {{"foo", "bar"}, {"hello", "world"}});
@@ -253,8 +270,9 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testClone() {
- assertEquals(null, ArrayUtils.clone((Object[]) null));
+ assertArrayEquals(null, ArrayUtils.clone((Object[]) null));
Object[] original1 = new Object[0];
Object[] cloned1 = ArrayUtils.clone(original1);
assertTrue(Arrays.equals(original1, cloned1));
@@ -270,6 +288,7 @@
assertSame(original1[2], cloned1[2]);
}
+ @Test
public void testCloneBoolean() {
assertEquals(null, ArrayUtils.clone((boolean[]) null));
boolean[] original = new boolean[] {true, false};
@@ -278,6 +297,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneLong() {
assertEquals(null, ArrayUtils.clone((long[]) null));
long[] original = new long[] {0L, 1L};
@@ -286,6 +306,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneInt() {
assertEquals(null, ArrayUtils.clone((int[]) null));
int[] original = new int[] {5, 8};
@@ -294,6 +315,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneShort() {
assertEquals(null, ArrayUtils.clone((short[]) null));
short[] original = new short[] {1, 4};
@@ -302,6 +324,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneChar() {
assertEquals(null, ArrayUtils.clone((char[]) null));
char[] original = new char[] {'a', '4'};
@@ -310,6 +333,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneByte() {
assertEquals(null, ArrayUtils.clone((byte[]) null));
byte[] original = new byte[] {1, 6};
@@ -318,6 +342,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneDouble() {
assertEquals(null, ArrayUtils.clone((double[]) null));
double[] original = new double[] {2.4d, 5.7d};
@@ -326,6 +351,7 @@
assertTrue(original != cloned);
}
+ @Test
public void testCloneFloat() {
assertEquals(null, ArrayUtils.clone((float[]) null));
float[] original = new float[] {2.6f, 6.4f};
@@ -336,6 +362,7 @@
//-----------------------------------------------------------------------
+ @Test
public void testNullToEmptyBoolean() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.nullToEmpty((boolean[]) null));
@@ -349,6 +376,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyLong() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.nullToEmpty((long[]) null));
@@ -362,6 +390,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyInt() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.nullToEmpty((int[]) null));
@@ -375,6 +404,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyShort() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.nullToEmpty((short[]) null));
@@ -388,6 +418,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyChar() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.nullToEmpty((char[]) null));
@@ -401,6 +432,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyByte() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.nullToEmpty((byte[]) null));
@@ -414,6 +446,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyDouble() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.nullToEmpty((double[]) null));
@@ -427,6 +460,7 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyFloat() {
// Test null handling
assertEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.nullToEmpty((float[]) null));
@@ -440,140 +474,151 @@
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Object[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Object[]) null));
// Test valid array handling
Object[] original = new Object[] {Boolean.TRUE, Boolean.FALSE};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Object[] empty = new Object[]{};
Object[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyString() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.nullToEmpty((String[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.nullToEmpty((String[]) null));
// Test valid array handling
String[] original = new String[] {"abc", "def"};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
String[] empty = new String[]{};
String[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_STRING_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyBooleanObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Boolean[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Boolean[]) null));
// Test valid array handling
Boolean[] original = new Boolean[] {Boolean.TRUE, Boolean.FALSE};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Boolean[] empty = new Boolean[]{};
Boolean[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyLongObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Long[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Long[]) null));
// Test valid array handling
@SuppressWarnings("boxing")
Long[] original = new Long[] {1L, 2L};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Long[] empty = new Long[]{};
Long[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyIntObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Integer[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Integer[]) null));
// Test valid array handling
Integer[] original = new Integer[] {1, 2};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Integer[] empty = new Integer[]{};
Integer[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyShortObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Short[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Short[]) null));
// Test valid array handling
@SuppressWarnings("boxing")
Short[] original = new Short[] {1, 2};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Short[] empty = new Short[]{};
Short[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyCharObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Character[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Character[]) null));
// Test valid array handling
Character[] original = new Character[] {'a', 'b'};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Character[] empty = new Character[]{};
Character[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyByteObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Byte[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Byte[]) null));
// Test valid array handling
Byte[] original = new Byte[] {0x0F, 0x0E};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Byte[] empty = new Byte[]{};
Byte[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyDoubleObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Double[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Double[]) null));
// Test valid array handling
Double[] original = new Double[] {1D, 2D};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Double[] empty = new Double[]{};
Double[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
+ @Test
public void testNullToEmptyFloatObject() {
// Test null handling
- assertEquals(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Float[]) null));
+ assertArrayEquals(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, ArrayUtils.nullToEmpty((Float[]) null));
// Test valid array handling
Float[] original = new Float[] {2.6f, 3.8f};
- assertEquals(original, ArrayUtils.nullToEmpty(original));
+ assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
// Test empty array handling
Float[] empty = new Float[]{};
Float[] result = ArrayUtils.nullToEmpty(empty);
- assertEquals(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, result);
+ assertArrayEquals(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, result);
assertTrue(empty != result);
}
//-----------------------------------------------------------------------
+ @Test
public void testSubarrayObject() {
Object[] nullArray = null;
Object[] objectArray = { "a", "b", "c", "d", "e", "f"};
@@ -620,6 +665,7 @@
} catch (ClassCastException e) {}
}
+ @Test
public void testSubarrayLong() {
long[] nullArray = null;
long[] array = { 999910, 999911, 999912, 999913, 999914, 999915 };
@@ -696,6 +742,7 @@
}
+ @Test
public void testSubarrayInt() {
int[] nullArray = null;
int[] array = { 10, 11, 12, 13, 14, 15 };
@@ -773,6 +820,7 @@
}
+ @Test
public void testSubarrayShort() {
short[] nullArray = null;
short[] array = { 10, 11, 12, 13, 14, 15 };
@@ -850,6 +898,7 @@
}
+ @Test
public void testSubarrChar() {
char[] nullArray = null;
char[] array = { 'a', 'b', 'c', 'd', 'e', 'f' };
@@ -927,6 +976,7 @@
}
+ @Test
public void testSubarrayByte() {
byte[] nullArray = null;
byte[] array = { 10, 11, 12, 13, 14, 15 };
@@ -1004,6 +1054,7 @@
}
+ @Test
public void testSubarrayDouble() {
double[] nullArray = null;
double[] array = { 10.123, 11.234, 12.345, 13.456, 14.567, 15.678 };
@@ -1081,6 +1132,7 @@
}
+ @Test
public void testSubarrayFloat() {
float[] nullArray = null;
float[] array = { 10, 11, 12, 13, 14, 15 };
@@ -1158,6 +1210,7 @@
}
+ @Test
public void testSubarrayBoolean() {
boolean[] nullArray = null;
boolean[] array = { true, true, false, true, false, true };
@@ -1236,6 +1289,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSameLength() {
Object[] nullArray = null;
Object[] emptyArray = new Object[0];
@@ -1263,6 +1317,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthBoolean() {
boolean[] nullArray = null;
boolean[] emptyArray = new boolean[0];
@@ -1290,6 +1345,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthLong() {
long[] nullArray = null;
long[] emptyArray = new long[0];
@@ -1317,6 +1373,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthInt() {
int[] nullArray = null;
int[] emptyArray = new int[0];
@@ -1344,6 +1401,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthShort() {
short[] nullArray = null;
short[] emptyArray = new short[0];
@@ -1371,6 +1429,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthChar() {
char[] nullArray = null;
char[] emptyArray = new char[0];
@@ -1398,6 +1457,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthByte() {
byte[] nullArray = null;
byte[] emptyArray = new byte[0];
@@ -1425,6 +1485,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthDouble() {
double[] nullArray = null;
double[] emptyArray = new double[0];
@@ -1452,6 +1513,7 @@
assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
}
+ @Test
public void testSameLengthFloat() {
float[] nullArray = null;
float[] emptyArray = new float[0];
@@ -1480,6 +1542,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSameType() {
try {
ArrayUtils.isSameType(null, null);
@@ -1502,6 +1565,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReverse() {
StringBuffer str1 = new StringBuffer("pick");
String str2 = "a";
@@ -1523,9 +1587,10 @@
array = null;
ArrayUtils.reverse(array);
- assertEquals(null, array);
+ assertArrayEquals(null, array);
}
+ @Test
public void testReverseLong() {
long[] array = new long[] {1L, 2L, 3L};
ArrayUtils.reverse(array);
@@ -1538,6 +1603,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseInt() {
int[] array = new int[] {1, 2, 3};
ArrayUtils.reverse(array);
@@ -1550,6 +1616,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseShort() {
short[] array = new short[] {1, 2, 3};
ArrayUtils.reverse(array);
@@ -1562,6 +1629,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseChar() {
char[] array = new char[] {'a', 'f', 'C'};
ArrayUtils.reverse(array);
@@ -1574,6 +1642,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseByte() {
byte[] array = new byte[] {2, 3, 4};
ArrayUtils.reverse(array);
@@ -1586,6 +1655,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseDouble() {
double[] array = new double[] {0.3d, 0.4d, 0.5d};
ArrayUtils.reverse(array);
@@ -1598,6 +1668,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseFloat() {
float[] array = new float[] {0.3f, 0.4f, 0.5f};
ArrayUtils.reverse(array);
@@ -1610,6 +1681,7 @@
assertEquals(null, array);
}
+ @Test
public void testReverseBoolean() {
boolean[] array = new boolean[] {false, false, true};
ArrayUtils.reverse(array);
@@ -1623,6 +1695,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOf() {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(-1, ArrayUtils.indexOf(null, null));
@@ -1636,6 +1709,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, "notInArray"));
}
+ @Test
public void testIndexOfWithStartIndex() {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(-1, ArrayUtils.indexOf(null, null, 2));
@@ -1653,6 +1727,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, "0", 8));
}
+ @Test
public void testLastIndexOf() {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(-1, ArrayUtils.lastIndexOf(null, null));
@@ -1665,6 +1740,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, "notInArray"));
}
+ @Test
public void testLastIndexOfWithStartIndex() {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(-1, ArrayUtils.lastIndexOf(null, null, 2));
@@ -1682,6 +1758,7 @@
assertEquals(5, ArrayUtils.lastIndexOf(array, "0", 88));
}
+ @Test
public void testContains() {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(false, ArrayUtils.contains(null, null));
@@ -1695,6 +1772,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfLong() {
long[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, 0));
@@ -1706,6 +1784,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, 99));
}
+ @Test
public void testIndexOfLongWithStartIndex() {
long[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
@@ -1719,6 +1798,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
}
+ @Test
public void testLastIndexOfLong() {
long[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
@@ -1730,6 +1810,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
}
+ @Test
public void testLastIndexOfLongWithStartIndex() {
long[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
@@ -1743,6 +1824,7 @@
assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
}
+ @Test
public void testContainsLong() {
long[] array = null;
assertEquals(false, ArrayUtils.contains(array, 1));
@@ -1755,6 +1837,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfInt() {
int[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, 0));
@@ -1766,6 +1849,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, 99));
}
+ @Test
public void testIndexOfIntWithStartIndex() {
int[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
@@ -1779,6 +1863,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
}
+ @Test
public void testLastIndexOfInt() {
int[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
@@ -1790,6 +1875,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
}
+ @Test
public void testLastIndexOfIntWithStartIndex() {
int[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
@@ -1803,6 +1889,7 @@
assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
}
+ @Test
public void testContainsInt() {
int[] array = null;
assertEquals(false, ArrayUtils.contains(array, 1));
@@ -1815,6 +1902,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfShort() {
short[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (short) 0));
@@ -1826,6 +1914,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, (short) 99));
}
+ @Test
public void testIndexOfShortWithStartIndex() {
short[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 2));
@@ -1839,6 +1928,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 6));
}
+ @Test
public void testLastIndexOfShort() {
short[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0));
@@ -1850,6 +1940,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 99));
}
+ @Test
public void testLastIndexOfShortWithStartIndex() {
short[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0, 2));
@@ -1863,6 +1954,7 @@
assertEquals(4, ArrayUtils.lastIndexOf(array, (short) 0, 88));
}
+ @Test
public void testContainsShort() {
short[] array = null;
assertEquals(false, ArrayUtils.contains(array, (short) 1));
@@ -1875,6 +1967,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfChar() {
char[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, 'a'));
@@ -1886,6 +1979,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, 'e'));
}
+ @Test
public void testIndexOfCharWithStartIndex() {
char[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, 'a', 2));
@@ -1899,6 +1993,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, 'a', 6));
}
+ @Test
public void testLastIndexOfChar() {
char[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a'));
@@ -1910,6 +2005,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, 'e'));
}
+ @Test
public void testLastIndexOfCharWithStartIndex() {
char[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a', 2));
@@ -1923,6 +2019,7 @@
assertEquals(4, ArrayUtils.lastIndexOf(array, 'a', 88));
}
+ @Test
public void testContainsChar() {
char[] array = null;
assertEquals(false, ArrayUtils.contains(array, 'b'));
@@ -1935,6 +2032,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfByte() {
byte[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0));
@@ -1946,6 +2044,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 99));
}
+ @Test
public void testIndexOfByteWithStartIndex() {
byte[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 2));
@@ -1959,6 +2058,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 6));
}
+ @Test
public void testLastIndexOfByte() {
byte[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0));
@@ -1970,6 +2070,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 99));
}
+ @Test
public void testLastIndexOfByteWithStartIndex() {
byte[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0, 2));
@@ -1983,6 +2084,7 @@
assertEquals(4, ArrayUtils.lastIndexOf(array, (byte) 0, 88));
}
+ @Test
public void testContainsByte() {
byte[] array = null;
assertEquals(false, ArrayUtils.contains(array, (byte) 1));
@@ -1996,6 +2098,7 @@
//-----------------------------------------------------------------------
@SuppressWarnings("cast")
+ @Test
public void testIndexOfDouble() {
double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0));
@@ -2011,6 +2114,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testIndexOfDoubleTolerance() {
double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, (double) 0));
@@ -2024,6 +2128,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testIndexOfDoubleWithStartIndex() {
double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2));
@@ -2039,6 +2144,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testIndexOfDoubleWithStartIndexTolerance() {
double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2, (double) 0));
@@ -2056,6 +2162,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testLastIndexOfDouble() {
double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0));
@@ -2070,6 +2177,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testLastIndexOfDoubleTolerance() {
double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, (double) 0));
@@ -2083,6 +2191,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testLastIndexOfDoubleWithStartIndex() {
double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2));
@@ -2099,6 +2208,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testLastIndexOfDoubleWithStartIndexTolerance() {
double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0));
@@ -2116,6 +2226,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testContainsDouble() {
double[] array = null;
assertEquals(false, ArrayUtils.contains(array, (double) 1));
@@ -2128,6 +2239,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testContainsDoubleTolerance() {
double[] array = null;
assertEquals(false, ArrayUtils.contains(array, (double) 1, (double) 0));
@@ -2140,6 +2252,7 @@
//-----------------------------------------------------------------------
@SuppressWarnings("cast")
+ @Test
public void testIndexOfFloat() {
float[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0));
@@ -2154,6 +2267,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testIndexOfFloatWithStartIndex() {
float[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2));
@@ -2170,6 +2284,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testLastIndexOfFloat() {
float[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0));
@@ -2184,6 +2299,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testLastIndexOfFloatWithStartIndex() {
float[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2));
@@ -2200,6 +2316,7 @@
}
@SuppressWarnings("cast")
+ @Test
public void testContainsFloat() {
float[] array = null;
assertEquals(false, ArrayUtils.contains(array, (float) 1));
@@ -2212,6 +2329,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfBoolean() {
boolean[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, true));
@@ -2224,6 +2342,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, false));
}
+ @Test
public void testIndexOfBooleanWithStartIndex() {
boolean[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, true, 2));
@@ -2239,6 +2358,7 @@
assertEquals(-1, ArrayUtils.indexOf(array, false, -1));
}
+ @Test
public void testLastIndexOfBoolean() {
boolean[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, true));
@@ -2251,6 +2371,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, false));
}
+ @Test
public void testLastIndexOfBooleanWithStartIndex() {
boolean[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, true, 2));
@@ -2266,6 +2387,7 @@
assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
}
+ @Test
public void testContainsBoolean() {
boolean[] array = null;
assertEquals(false, ArrayUtils.contains(array, true));
@@ -2279,6 +2401,7 @@
// testToPrimitive/Object for boolean
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_boolean() {
final Boolean[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2294,6 +2417,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_boolean_boolean() {
assertEquals(null, ArrayUtils.toPrimitive(null, false));
assertSame(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.toPrimitive(new Boolean[0], false));
@@ -2311,9 +2435,10 @@
);
}
+ @Test
public void testToObject_boolean() {
final boolean[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayUtils.toObject(new boolean[0]));
assertTrue(Arrays.equals(
new Boolean[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE},
@@ -2323,6 +2448,7 @@
// testToPrimitive/Object for byte
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_char() {
final Character[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2341,6 +2467,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_char_char() {
final Character[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b, Character.MIN_VALUE));
@@ -2362,9 +2489,10 @@
);
}
+ @Test
public void testToObject_char() {
final char[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY,
ArrayUtils.toObject(new char[0]));
@@ -2379,6 +2507,7 @@
// testToPrimitive/Object for byte
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_byte() {
final Byte[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2397,6 +2526,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_byte_byte() {
final Byte[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b, Byte.MIN_VALUE));
@@ -2418,9 +2548,10 @@
);
}
+ @Test
public void testToObject_byte() {
final byte[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY,
ArrayUtils.toObject(new byte[0]));
@@ -2435,6 +2566,7 @@
// testToPrimitive/Object for short
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_short() {
final Short[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2453,6 +2585,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_short_short() {
final Short[] s = null;
assertEquals(null, ArrayUtils.toPrimitive(s, Short.MIN_VALUE));
@@ -2473,9 +2606,10 @@
);
}
+ @Test
public void testToObject_short() {
final short[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY,
ArrayUtils.toObject(new short[0]));
@@ -2490,6 +2624,7 @@
// testToPrimitive/Object for int
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_int() {
final Integer[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2506,6 +2641,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_int_int() {
final Long[] l = null;
assertEquals(null, ArrayUtils.toPrimitive(l, Integer.MIN_VALUE));
@@ -2522,14 +2658,16 @@
);
}
+ @Test
public void testToPrimitive_intNull() {
Integer[] iArray = null;
assertEquals(null, ArrayUtils.toPrimitive(iArray, Integer.MIN_VALUE));
}
+ @Test
public void testToObject_int() {
final int[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(
ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY,
@@ -2547,6 +2685,7 @@
// testToPrimitive/Object for long
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_long() {
final Long[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2566,6 +2705,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_long_long() {
final Long[] l = null;
assertEquals(null, ArrayUtils.toPrimitive(l, Long.MIN_VALUE));
@@ -2585,9 +2725,10 @@
);
}
+ @Test
public void testToObject_long() {
final long[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(
ArrayUtils.EMPTY_LONG_OBJECT_ARRAY,
@@ -2605,6 +2746,7 @@
// testToPrimitive/Object for float
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_float() {
final Float[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2624,6 +2766,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_float_float() {
final Float[] l = null;
assertEquals(null, ArrayUtils.toPrimitive(l, Float.MIN_VALUE));
@@ -2643,9 +2786,10 @@
);
}
+ @Test
public void testToObject_float() {
final float[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(
ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY,
@@ -2663,6 +2807,7 @@
// testToPrimitive/Object for double
// -----------------------------------------------------------------------
+ @Test
public void testToPrimitive_double() {
final Double[] b = null;
assertEquals(null, ArrayUtils.toPrimitive(b));
@@ -2682,6 +2827,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testToPrimitive_double_double() {
final Double[] l = null;
assertEquals(null, ArrayUtils.toPrimitive(l, Double.MIN_VALUE));
@@ -2701,9 +2847,10 @@
);
}
+ @Test
public void testToObject_double() {
final double[] b = null;
- assertEquals(null, ArrayUtils.toObject(b));
+ assertArrayEquals(null, ArrayUtils.toObject(b));
assertSame(
ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY,
@@ -2723,6 +2870,7 @@
/**
* Test for {@link ArrayUtils#isEmpty(java.lang.Object[])}.
*/
+ @Test
public void testIsEmptyObject() {
Object[] emptyArray = new Object[] {};
Object[] notEmptyArray = new Object[] { new String("Value") };
@@ -2741,6 +2889,7 @@
* {@link ArrayUtils#isEmpty(float[])} and
* {@link ArrayUtils#isEmpty(boolean[])}.
*/
+ @Test
public void testIsEmptyPrimitives() {
long[] emptyLongArray = new long[] {};
long[] notEmptyLongArray = new long[] { 1L };
@@ -2794,6 +2943,7 @@
/**
* Test for {@link ArrayUtils#isNotEmpty(java.lang.Object[])}.
*/
+ @Test
public void testIsNotEmptyObject() {
Object[] emptyArray = new Object[] {};
Object[] notEmptyArray = new Object[] { new String("Value") };
@@ -2812,6 +2962,7 @@
* {@link ArrayUtils#isNotEmpty(float[])} and
* {@link ArrayUtils#isNotEmpty(boolean[])}.
*/
+ @Test
public void testIsNotEmptyPrimitives() {
long[] emptyLongArray = new long[] {};
long[] notEmptyLongArray = new long[] { 1L };
@@ -2862,6 +3013,7 @@
assertTrue(ArrayUtils.isNotEmpty(notEmptyBooleanArray));
}
// ------------------------------------------------------------------------
+ @Test
public void testGetLength() {
assertEquals(0, ArrayUtils.getLength(null));
diff --git a/src/test/java/org/apache/commons/lang3/BitFieldTest.java b/src/test/java/org/apache/commons/lang3/BitFieldTest.java
index 1277816..872a67c 100644
--- a/src/test/java/org/apache/commons/lang3/BitFieldTest.java
+++ b/src/test/java/org/apache/commons/lang3/BitFieldTest.java
@@ -16,31 +16,26 @@
*/
package org.apache.commons.lang3;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* Class to test BitField functionality
*
* @version $Id$
*/
-public class BitFieldTest extends TestCase {
+public class BitFieldTest {
private static final BitField bf_multi = new BitField(0x3F80);
private static final BitField bf_single = new BitField(0x4000);
private static final BitField bf_zero = new BitField(0);
/**
- * Constructor BitFieldTest
- *
- * @param name
- */
- public BitFieldTest(String name) {
- super(name);
- }
-
- /**
* test the getValue() method
*/
+ @Test
public void testGetValue() {
assertEquals(bf_multi.getValue(-1), 127);
assertEquals(bf_multi.getValue(0), 0);
@@ -53,6 +48,7 @@
/**
* test the getShortValue() method
*/
+ @Test
public void testGetShortValue() {
assertEquals(bf_multi.getShortValue((short) - 1), (short) 127);
assertEquals(bf_multi.getShortValue((short) 0), (short) 0);
@@ -65,6 +61,7 @@
/**
* test the getRawValue() method
*/
+ @Test
public void testGetRawValue() {
assertEquals(bf_multi.getRawValue(-1), 0x3F80);
assertEquals(bf_multi.getRawValue(0), 0);
@@ -77,6 +74,7 @@
/**
* test the getShortRawValue() method
*/
+ @Test
public void testGetShortRawValue() {
assertEquals(bf_multi.getShortRawValue((short) - 1), (short) 0x3F80);
assertEquals(bf_multi.getShortRawValue((short) 0), (short) 0);
@@ -89,6 +87,7 @@
/**
* test the isSet() method
*/
+ @Test
public void testIsSet() {
assertTrue(!bf_multi.isSet(0));
assertTrue(!bf_zero.isSet(0));
@@ -105,6 +104,7 @@
/**
* test the isAllSet() method
*/
+ @Test
public void testIsAllSet() {
for (int j = 0; j < 0x3F80; j += 0x80) {
assertTrue(!bf_multi.isAllSet(j));
@@ -118,6 +118,7 @@
/**
* test the setValue() method
*/
+ @Test
public void testSetValue() {
for (int j = 0; j < 128; j++) {
assertEquals(bf_multi.getValue(bf_multi.setValue(0, j)), j);
@@ -142,6 +143,7 @@
/**
* test the setShortValue() method
*/
+ @Test
public void testSetShortValue() {
for (int j = 0; j < 128; j++) {
assertEquals(bf_multi.getShortValue(bf_multi.setShortValue((short) 0, (short) j)), (short) j);
@@ -163,6 +165,7 @@
assertEquals(bf_single.setShortValue((short) 0x4000, (short) 2), (short) 0);
}
+ @Test
public void testByte() {
assertEquals(0, new BitField(0).setByteBoolean((byte) 0, true));
assertEquals(1, new BitField(1).setByteBoolean((byte) 0, true));
@@ -191,6 +194,7 @@
/**
* test the clear() method
*/
+ @Test
public void testClear() {
assertEquals(bf_multi.clear(-1), 0xFFFFC07F);
assertEquals(bf_single.clear(-1), 0xFFFFBFFF);
@@ -200,6 +204,7 @@
/**
* test the clearShort() method
*/
+ @Test
public void testClearShort() {
assertEquals(bf_multi.clearShort((short) - 1), (short) 0xC07F);
assertEquals(bf_single.clearShort((short) - 1), (short) 0xBFFF);
@@ -209,6 +214,7 @@
/**
* test the set() method
*/
+ @Test
public void testSet() {
assertEquals(bf_multi.set(0), 0x3F80);
assertEquals(bf_single.set(0), 0x4000);
@@ -218,6 +224,7 @@
/**
* test the setShort() method
*/
+ @Test
public void testSetShort() {
assertEquals(bf_multi.setShort((short) 0), (short) 0x3F80);
assertEquals(bf_single.setShort((short) 0), (short) 0x4000);
@@ -227,6 +234,7 @@
/**
* test the setBoolean() method
*/
+ @Test
public void testSetBoolean() {
assertEquals(bf_multi.set(0), bf_multi.setBoolean(0, true));
assertEquals(bf_single.set(0), bf_single.setBoolean(0, true));
@@ -239,6 +247,7 @@
/**
* test the setShortBoolean() method
*/
+ @Test
public void testSetShortBoolean() {
assertEquals(bf_multi.setShort((short) 0), bf_multi.setShortBoolean((short) 0, true));
assertEquals(bf_single.setShort((short) 0), bf_single.setShortBoolean((short) 0, true));
diff --git a/src/test/java/org/apache/commons/lang3/CharEncodingTest.java b/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
index da9a692..ec71749 100644
--- a/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
@@ -20,7 +20,10 @@
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* Tests CharEncoding.
@@ -28,7 +31,7 @@
* @see CharEncoding
* @version $Id$
*/
-public class CharEncodingTest extends TestCase {
+public class CharEncodingTest {
private void assertSupportedEncoding(String name) {
assertTrue("Encoding should be supported: " + name, CharEncoding.isSupported(name));
@@ -37,10 +40,12 @@
/**
* The class can be instantiated.
*/
+ @Test
public void testConstructor() {
new CharEncoding();
}
+ @Test
public void testMustBeSupportedJava1_3_1() {
if (SystemUtils.isJavaVersionAtLeast(JAVA_1_3)) {
this.assertSupportedEncoding(CharEncoding.ISO_8859_1);
@@ -54,12 +59,14 @@
}
}
+ @Test
public void testSupported() {
assertTrue(CharEncoding.isSupported("UTF8"));
assertTrue(CharEncoding.isSupported("UTF-8"));
assertTrue(CharEncoding.isSupported("ASCII"));
}
+ @Test
public void testNotSupported() {
assertFalse(CharEncoding.isSupported(null));
assertFalse(CharEncoding.isSupported(""));
@@ -69,6 +76,7 @@
assertFalse(CharEncoding.isSupported("this is not a valid encoding name"));
}
+ @Test
public void testWorksOnJava1_1_8() {
//
// In this test, I simply deleted the encodings from the 1.3.1 list.
@@ -83,6 +91,7 @@
}
}
+ @Test
public void testWorksOnJava1_2_2() {
//
// In this test, I simply deleted the encodings from the 1.3.1 list.
diff --git a/src/test/java/org/apache/commons/lang3/CharRangeTest.java b/src/test/java/org/apache/commons/lang3/CharRangeTest.java
index 4b04e0d..c36ebbe 100644
--- a/src/test/java/org/apache/commons/lang3/CharRangeTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharRangeTest.java
@@ -18,24 +18,27 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.CharRange}.
*
* @version $Id$
*/
-public class CharRangeTest extends TestCase {
-
- public CharRangeTest(String name) {
- super(name);
- }
+public class CharRangeTest {
//-----------------------------------------------------------------------
+ @Test
public void testClass() {
// class changed to non-public in 3.0
assertEquals(false, Modifier.isPublic(CharRange.class.getModifiers()));
@@ -43,6 +46,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructorAccessors_is() {
CharRange rangea = CharRange.is('a');
assertEquals('a', rangea.getStart());
@@ -51,6 +55,7 @@
assertEquals("a", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isNot() {
CharRange rangea = CharRange.isNot('a');
assertEquals('a', rangea.getStart());
@@ -59,6 +64,7 @@
assertEquals("^a", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isIn_Same() {
CharRange rangea = CharRange.isIn('a', 'a');
assertEquals('a', rangea.getStart());
@@ -67,6 +73,7 @@
assertEquals("a", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isIn_Normal() {
CharRange rangea = CharRange.isIn('a', 'e');
assertEquals('a', rangea.getStart());
@@ -75,6 +82,7 @@
assertEquals("a-e", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isIn_Reversed() {
CharRange rangea = CharRange.isIn('e', 'a');
assertEquals('a', rangea.getStart());
@@ -83,6 +91,7 @@
assertEquals("a-e", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isNotIn_Same() {
CharRange rangea = CharRange.isNotIn('a', 'a');
assertEquals('a', rangea.getStart());
@@ -91,6 +100,7 @@
assertEquals("^a", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isNotIn_Normal() {
CharRange rangea = CharRange.isNotIn('a', 'e');
assertEquals('a', rangea.getStart());
@@ -99,6 +109,7 @@
assertEquals("^a-e", rangea.toString());
}
+ @Test
public void testConstructorAccessors_isNotIn_Reversed() {
CharRange rangea = CharRange.isNotIn('e', 'a');
assertEquals('a', rangea.getStart());
@@ -108,6 +119,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testEquals_Object() {
CharRange rangea = CharRange.is('a');
CharRange rangeae = CharRange.isIn('a', 'e');
@@ -130,6 +142,7 @@
assertEquals(false, rangenotbf.equals(rangeae));
}
+ @Test
public void testHashCode() {
CharRange rangea = CharRange.is('a');
CharRange rangeae = CharRange.isIn('a', 'e');
@@ -151,6 +164,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testContains_Char() {
CharRange range = CharRange.is('c');
assertEquals(false, range.contains('b'));
@@ -180,6 +194,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testContains_Charrange() {
CharRange a = CharRange.is('a');
CharRange b = CharRange.is('b');
@@ -294,6 +309,7 @@
assertEquals(true, notbd.contains(notae));
}
+ @Test
public void testContainsNullArg() {
CharRange range = CharRange.is('a');
try {
@@ -304,6 +320,7 @@
}
}
+ @Test
public void testIterator() {
CharRange a = CharRange.is('a');
CharRange ad = CharRange.isIn('a', 'd');
@@ -371,6 +388,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSerialization() {
CharRange range = CharRange.is('a');
assertEquals(range, SerializationUtils.clone(range));
diff --git a/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java b/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
index ea8fa0c..5683d01 100644
--- a/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
@@ -16,20 +16,25 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Assert;
-import junit.framework.TestCase;
+
+import org.junit.Test;
/**
* Tests CharSequenceUtils
*
* @version $Id: CharSequenceUtilsTest.java 1066341 2011-02-02 06:21:53Z bayard $
*/
-public class CharSequenceUtilsTest extends TestCase {
+public class CharSequenceUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new CharSequenceUtils());
Constructor<?>[] cons = CharSequenceUtils.class.getDeclaredConstructors();
@@ -40,6 +45,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSubSequence() {
//
// null input
diff --git a/src/test/java/org/apache/commons/lang3/CharSetTest.java b/src/test/java/org/apache/commons/lang3/CharSetTest.java
index 17a9d23..5a0ceee 100644
--- a/src/test/java/org/apache/commons/lang3/CharSetTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharSetTest.java
@@ -18,28 +18,29 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
import java.lang.reflect.Modifier;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.CharSet}.
*
* @version $Id$
*/
-public class CharSetTest extends TestCase {
-
- public CharSetTest(String name) {
- super(name);
- }
+public class CharSetTest {
//-----------------------------------------------------------------------
+ @Test
public void testClass() {
assertEquals(true, Modifier.isPublic(CharSet.class.getModifiers()));
assertEquals(false, Modifier.isFinal(CharSet.class.getModifiers()));
}
//-----------------------------------------------------------------------
+ @Test
public void testGetInstance() {
assertSame(CharSet.EMPTY, CharSet.getInstance( (String) null));
assertSame(CharSet.EMPTY, CharSet.getInstance(""));
@@ -51,6 +52,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetInstance_Stringarray() {
assertEquals(null, CharSet.getInstance((String[]) null));
assertEquals("[]", CharSet.getInstance(new String[0]).toString());
@@ -59,6 +61,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_String_simple() {
CharSet set;
CharRange[] array;
@@ -98,6 +101,7 @@
assertEquals("^a-e", array[0].toString());
}
+ @Test
public void testConstructor_String_combo() {
CharSet set;
CharRange[] array;
@@ -136,6 +140,7 @@
assertEquals(true, ArrayUtils.contains(array, CharRange.is('z')));
}
+ @Test
public void testConstructor_String_comboNegated() {
CharSet set;
CharRange[] array;
@@ -176,6 +181,7 @@
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
}
+ @Test
public void testConstructor_String_oddDash() {
CharSet set;
CharRange[] array;
@@ -223,6 +229,7 @@
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('-', 'a')));
}
+ @Test
public void testConstructor_String_oddNegate() {
CharSet set;
CharRange[] array;
@@ -282,6 +289,7 @@
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-'))); // "-"
}
+ @Test
public void testConstructor_String_oddCombinations() {
CharSet set;
CharRange[] array = null;
@@ -331,6 +339,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testEquals_Object() {
CharSet abc = CharSet.getInstance("abc");
CharSet abc2 = CharSet.getInstance("abc");
@@ -357,6 +366,7 @@
assertEquals(true, notatoc.equals(notatoc2));
}
+ @Test
public void testHashCode() {
CharSet abc = CharSet.getInstance("abc");
CharSet abc2 = CharSet.getInstance("abc");
@@ -374,6 +384,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testContains_Char() {
CharSet btod = CharSet.getInstance("b-d");
CharSet dtob = CharSet.getInstance("d-b");
@@ -417,6 +428,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSerialization() {
CharSet set = CharSet.getInstance("a");
assertEquals(set, SerializationUtils.clone(set));
@@ -427,6 +439,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testStatics() {
CharRange[] array;
diff --git a/src/test/java/org/apache/commons/lang3/CharSetUtilsTest.java b/src/test/java/org/apache/commons/lang3/CharSetUtilsTest.java
index 94c8c6f..bcac4d1 100644
--- a/src/test/java/org/apache/commons/lang3/CharSetUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharSetUtilsTest.java
@@ -16,23 +16,23 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.CharSetUtils}.
*
* @version $Id$
*/
-public class CharSetUtilsTest extends TestCase {
-
- public CharSetUtilsTest(String name) {
- super(name);
- }
+public class CharSetUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new CharSetUtils());
Constructor<?>[] cons = CharSetUtils.class.getDeclaredConstructors();
@@ -43,6 +43,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSqueeze_StringString() {
assertEquals(null, CharSetUtils.squeeze(null, (String) null));
assertEquals(null, CharSetUtils.squeeze(null, ""));
@@ -59,6 +60,7 @@
assertEquals("hello", CharSetUtils.squeeze("helloo", "^l"));
}
+ @Test
public void testSqueeze_StringStringarray() {
assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
assertEquals(null, CharSetUtils.squeeze(null, new String[0]));
@@ -82,6 +84,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCount_StringString() {
assertEquals(0, CharSetUtils.count(null, (String) null));
assertEquals(0, CharSetUtils.count(null, ""));
@@ -96,6 +99,7 @@
assertEquals(3, CharSetUtils.count("hello", "l-p"));
}
+ @Test
public void testCount_StringStringarray() {
assertEquals(0, CharSetUtils.count(null, (String[]) null));
assertEquals(0, CharSetUtils.count(null, new String[0]));
@@ -120,6 +124,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testKeep_StringString() {
assertEquals(null, CharSetUtils.keep(null, (String) null));
assertEquals(null, CharSetUtils.keep(null, ""));
@@ -136,6 +141,7 @@
assertEquals("ell", CharSetUtils.keep("hello", "el"));
}
+ @Test
public void testKeep_StringStringarray() {
assertEquals(null, CharSetUtils.keep(null, (String[]) null));
assertEquals(null, CharSetUtils.keep(null, new String[0]));
@@ -161,6 +167,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testDelete_StringString() {
assertEquals(null, CharSetUtils.delete(null, (String) null));
assertEquals(null, CharSetUtils.delete(null, ""));
@@ -176,6 +183,7 @@
assertEquals("hello", CharSetUtils.delete("hello", "z"));
}
+ @Test
public void testDelete_StringStringarray() {
assertEquals(null, CharSetUtils.delete(null, (String[]) null));
assertEquals(null, CharSetUtils.delete(null, new String[0]));
diff --git a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
index b524a93..19d45d2 100644
--- a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
@@ -17,6 +17,15 @@
package org.apache.commons.lang3;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_5;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@@ -29,24 +38,21 @@
import java.util.Map;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.ClassUtils}.
*
* @version $Id$
*/
-public class ClassUtilsTest extends TestCase {
-
- public ClassUtilsTest(String name) {
- super(name);
- }
+public class ClassUtilsTest {
private static class Inner {
private class DeeplyNested{}
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new ClassUtils());
Constructor<?>[] cons = ClassUtils.class.getDeclaredConstructors();
@@ -57,6 +63,7 @@
}
// -------------------------------------------------------------------------
+ @Test
public void test_getShortClassName_Object() {
assertEquals("ClassUtils", ClassUtils.getShortClassName(new ClassUtils(), "<null>"));
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), "<null>"));
@@ -70,6 +77,7 @@
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), "<null>"));
}
+ @Test
public void test_getShortClassName_Class() {
assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class));
assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class));
@@ -113,6 +121,7 @@
+ @Test
public void test_getShortClassName_String() {
assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class.getName()));
assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class.getName()));
@@ -120,6 +129,7 @@
assertEquals("", ClassUtils.getShortClassName(""));
}
+ @Test
public void test_getSimpleName_Class() {
assertEquals("ClassUtils", ClassUtils.getSimpleName(ClassUtils.class));
assertEquals("Entry", ClassUtils.getSimpleName(Map.Entry.class));
@@ -160,6 +170,7 @@
assertEquals("Named", ClassUtils.getSimpleName(Named.class));
}
+ @Test
public void test_getSimpleName_Object() {
assertEquals("ClassUtils", ClassUtils.getSimpleName(new ClassUtils(), "<null>"));
assertEquals("Inner", ClassUtils.getSimpleName(new Inner(), "<null>"));
@@ -168,12 +179,14 @@
}
// -------------------------------------------------------------------------
+ @Test
public void test_getPackageName_Object() {
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new ClassUtils(), "<null>"));
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new Inner(), "<null>"));
assertEquals("<null>", ClassUtils.getPackageName(null, "<null>"));
}
+ @Test
public void test_getPackageName_Class() {
assertEquals("java.lang", ClassUtils.getPackageName(String.class));
assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class));
@@ -203,6 +216,7 @@
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(Named.class));
}
+ @Test
public void test_getPackageName_String() {
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(ClassUtils.class.getName()));
assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class.getName()));
@@ -211,6 +225,7 @@
}
// -------------------------------------------------------------------------
+ @Test
public void test_getAllSuperclasses_Class() {
List<?> list = ClassUtils.getAllSuperclasses(CY.class);
assertEquals(2, list.size());
@@ -220,6 +235,7 @@
assertEquals(null, ClassUtils.getAllSuperclasses(null));
}
+ @Test
public void test_getAllInterfaces_Class() {
List<?> list = ClassUtils.getAllInterfaces(CY.class);
assertEquals(6, list.size());
@@ -251,6 +267,7 @@
}
// -------------------------------------------------------------------------
+ @Test
public void test_convertClassNamesToClasses_List() {
List<String> list = new ArrayList<String>();
List<Class<?>> result = ClassUtils.convertClassNamesToClasses(list);
@@ -275,6 +292,7 @@
assertEquals(null, ClassUtils.convertClassNamesToClasses(null));
}
+ @Test
public void test_convertClassesToClassNames_List() {
List<Class<?>> list = new ArrayList<Class<?>>();
List<String> result = ClassUtils.convertClassesToClassNames(list);
@@ -300,6 +318,7 @@
}
// -------------------------------------------------------------------------
+ @Test
public void test_isInnerClass_Class() {
assertEquals(true, ClassUtils.isInnerClass(Inner.class));
assertEquals(true, ClassUtils.isInnerClass(Map.Entry.class));
@@ -311,6 +330,7 @@
}
// -------------------------------------------------------------------------
+ @Test
public void test_isAssignable_ClassArray_ClassArray() throws Exception {
Class<?>[] array2 = new Class[] {Object.class, Object.class};
Class<?>[] array1 = new Class[] {Object.class};
@@ -341,6 +361,7 @@
assertTrue(ClassUtils.isAssignable(arrayWrappers, array2));
}
+ @Test
public void test_isAssignable_ClassArray_ClassArray_Autoboxing() throws Exception {
Class<?>[] array2 = new Class[] {Object.class, Object.class};
Class<?>[] array1 = new Class[] {Object.class};
@@ -368,6 +389,7 @@
assertTrue(ClassUtils.isAssignable(arrayWrappers, array2, true));
}
+ @Test
public void test_isAssignable_ClassArray_ClassArray_NoAutoboxing() throws Exception {
Class<?>[] array2 = new Class[] {Object.class, Object.class};
Class<?>[] array1 = new Class[] {Object.class};
@@ -395,6 +417,7 @@
assertFalse(ClassUtils.isAssignable(arrayPrimitives, array2, false));
}
+ @Test
public void test_isAssignable() throws Exception {
assertFalse(ClassUtils.isAssignable((Class<?>) null, null));
assertFalse(ClassUtils.isAssignable(String.class, null));
@@ -422,6 +445,7 @@
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class));
}
+ @Test
public void test_isAssignable_Autoboxing() throws Exception {
assertFalse(ClassUtils.isAssignable((Class<?>) null, null, true));
assertFalse(ClassUtils.isAssignable(String.class, null, true));
@@ -445,6 +469,7 @@
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class, true));
}
+ @Test
public void test_isAssignable_NoAutoboxing() throws Exception {
assertFalse(ClassUtils.isAssignable((Class<?>) null, null, false));
assertFalse(ClassUtils.isAssignable(String.class, null, false));
@@ -468,6 +493,7 @@
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class, false));
}
+ @Test
public void test_isAssignable_Widening() throws Exception {
// test byte conversions
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.TYPE, Character.TYPE));
@@ -550,6 +576,7 @@
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
}
+ @Test
public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
@@ -634,6 +661,7 @@
assertEquals("boolean -> boolean", autoboxing, ClassUtils.isAssignable(Boolean.class, Boolean.TYPE));
}
+ @Test
public void test_isAssignable_Unboxing_Widening() throws Exception {
// test byte conversions
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE, true));
@@ -716,6 +744,7 @@
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true));
}
+ @Test
public void testIsPrimitiveOrWrapper() {
// test primitive wrapper classes
@@ -746,6 +775,7 @@
assertFalse("this.getClass()", ClassUtils.isPrimitiveOrWrapper(this.getClass()));
}
+ @Test
public void testIsPrimitiveWrapper() {
// test primitive wrapper classes
@@ -776,6 +806,7 @@
assertFalse("this.getClass()", ClassUtils.isPrimitiveWrapper(this.getClass()));
}
+ @Test
public void testPrimitiveToWrapper() {
// test primitive classes
@@ -810,6 +841,7 @@
ClassUtils.primitiveToWrapper(null));
}
+ @Test
public void testPrimitivesToWrappers() {
// test null
// assertNull("null -> null", ClassUtils.primitivesToWrappers(null)); // generates warning
@@ -820,7 +852,7 @@
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
// test empty array is returned unchanged
// TODO this is not documented
- assertEquals("empty -> empty",
+ assertArrayEquals("empty -> empty",
ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY));
// test an array of various classes
@@ -847,6 +879,7 @@
assertNotSame("unmodified", noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives));
}
+ @Test
public void testWrapperToPrimitive() {
// an array with classes to convert
final Class<?>[] primitives = {
@@ -861,14 +894,17 @@
}
}
+ @Test
public void testWrapperToPrimitiveNoWrapper() {
assertNull("Wrong result for non wrapper class", ClassUtils.wrapperToPrimitive(String.class));
}
+ @Test
public void testWrapperToPrimitiveNull() {
assertNull("Wrong result for null class", ClassUtils.wrapperToPrimitive(null));
}
+ @Test
public void testWrappersToPrimitives() {
// an array with classes to test
final Class<?>[] classes = {
@@ -887,6 +923,7 @@
}
}
+ @Test
public void testWrappersToPrimitivesNull() {
// assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives(null)); // generates warning
assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives((Class<?>[]) null)); // equivalent cast
@@ -896,17 +933,20 @@
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
}
+ @Test
public void testWrappersToPrimitivesEmpty() {
Class<?>[] empty = new Class[0];
- assertEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
+ assertArrayEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
}
+ @Test
public void testGetClassClassNotFound() throws Exception {
assertGetClassThrowsClassNotFound( "bool" );
assertGetClassThrowsClassNotFound( "bool[]" );
assertGetClassThrowsClassNotFound( "integer[]" );
}
+ @Test
public void testGetClassInvalidArguments() throws Exception {
assertGetClassThrowsNullPointerException( null );
assertGetClassThrowsClassNotFound( "[][][]" );
@@ -917,6 +957,7 @@
assertGetClassThrowsClassNotFound( "hello..world" );
}
+ @Test
public void testWithInterleavingWhitespace() throws ClassNotFoundException {
assertEquals( int[].class, ClassUtils.getClass( " int [ ] " ) );
assertEquals( long[].class, ClassUtils.getClass( "\rlong\t[\n]\r" ) );
@@ -924,6 +965,7 @@
assertEquals( byte[].class, ClassUtils.getClass( "byte[\t\t\n\r] " ) );
}
+ @Test
public void testGetInnerClass() throws ClassNotFoundException {
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner.DeeplyNested" ) );
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner$DeeplyNested" ) );
@@ -931,6 +973,7 @@
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest$Inner.DeeplyNested" ) );
}
+ @Test
public void testGetClassByNormalNameArrays() throws ClassNotFoundException {
assertEquals( int[].class, ClassUtils.getClass( "int[]" ) );
assertEquals( long[].class, ClassUtils.getClass( "long[]" ) );
@@ -947,6 +990,7 @@
assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "[Ljava.util.Map$Entry;" ) );
}
+ @Test
public void testGetClassByNormalNameArrays2D() throws ClassNotFoundException {
assertEquals( int[][].class, ClassUtils.getClass( "int[][]" ) );
assertEquals( long[][].class, ClassUtils.getClass( "long[][]" ) );
@@ -959,6 +1003,7 @@
assertEquals( String[][].class, ClassUtils.getClass( "java.lang.String[][]" ) );
}
+ @Test
public void testGetClassWithArrayClasses2D() throws Exception {
assertGetClassReturnsClass( String[][].class );
assertGetClassReturnsClass( int[][].class );
@@ -971,6 +1016,7 @@
assertGetClassReturnsClass( boolean[][].class );
}
+ @Test
public void testGetClassWithArrayClasses() throws Exception {
assertGetClassReturnsClass( String[].class );
assertGetClassReturnsClass( int[].class );
@@ -983,6 +1029,7 @@
assertGetClassReturnsClass( boolean[].class );
}
+ @Test
public void testGetClassRawPrimitives() throws ClassNotFoundException {
assertEquals( int.class, ClassUtils.getClass( "int" ) );
assertEquals( long.class, ClassUtils.getClass( "long" ) );
@@ -1018,6 +1065,7 @@
// Show the Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957
// We may have to delete this if a JDK fixes the bug.
+ @Test
public void testShowJavaBug() throws Exception {
// Tests with Collections$UnmodifiableSet
Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
@@ -1030,6 +1078,7 @@
}
}
+ @Test
public void testGetPublicMethod() throws Exception {
// Tests with Collections$UnmodifiableSet
Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
@@ -1047,6 +1096,7 @@
assertEquals(Object.class.getMethod("toString", new Class[0]), toStringMethod);
}
+ @Test
public void testToClass_object() {
// assertNull(ClassUtils.toClass(null)); // generates warning
assertNull(ClassUtils.toClass((Object[]) null)); // equivalent explicit cast
@@ -1065,6 +1115,7 @@
ClassUtils.toClass(new Object[] { "Test", null, Double.valueOf(99d) })));
}
+ @Test
public void test_getShortCanonicalName_Object() {
assertEquals("<null>", ClassUtils.getShortCanonicalName(null, "<null>"));
assertEquals("ClassUtils", ClassUtils.getShortCanonicalName(new ClassUtils(), "<null>"));
@@ -1080,6 +1131,7 @@
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName(new Inner(), "<null>"));
}
+ @Test
public void test_getShortCanonicalName_Class() {
assertEquals("ClassUtils", ClassUtils.getShortCanonicalName(ClassUtils.class));
assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName(ClassUtils[].class));
@@ -1094,6 +1146,7 @@
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName(Inner.class));
}
+ @Test
public void test_getShortCanonicalName_String() {
assertEquals("ClassUtils", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils"));
assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
@@ -1111,6 +1164,7 @@
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner"));
}
+ @Test
public void test_getPackageCanonicalName_Object() {
assertEquals("<null>", ClassUtils.getPackageCanonicalName(null, "<null>"));
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new ClassUtils(), "<null>"));
@@ -1126,6 +1180,7 @@
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new Inner(), "<null>"));
}
+ @Test
public void test_getPackageCanonicalName_Class() {
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils.class));
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils[].class));
@@ -1140,6 +1195,7 @@
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(Inner.class));
}
+ @Test
public void test_getPackageCanonicalName_String() {
assertEquals("org.apache.commons.lang3",
ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils"));
diff --git a/src/test/java/org/apache/commons/lang3/JavaVersionTest.java b/src/test/java/org/apache/commons/lang3/JavaVersionTest.java
index 713fbd1..781fcf8 100644
--- a/src/test/java/org/apache/commons/lang3/JavaVersionTest.java
+++ b/src/test/java/org/apache/commons/lang3/JavaVersionTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.commons.lang3;
+import org.junit.Test;
+import static org.junit.Assert.*;
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
@@ -29,15 +31,15 @@
import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.commons.lang3.JavaVersion.get;
import static org.apache.commons.lang3.JavaVersion.getJavaVersion;
-import junit.framework.TestCase;
/**
* Unit tests {@link org.apache.commons.lang3.JavaVersion}.
*
* @version $Id: JavaVersionTest.java 918366 2010-03-03 08:56:22Z bayard $
*/
-public class JavaVersionTest extends TestCase {
+public class JavaVersionTest {
+ @Test
public void testGetJavaVersion() {
assertEquals("0.9 failed", JAVA_0_9, get("0.9"));
assertEquals("1.1 failed", JAVA_1_1, get("1.1"));
@@ -52,6 +54,7 @@
assertEquals("Wrapper method failed", get("1.5"), getJavaVersion("1.5"));
}
+ @Test
public void testAtLeast() {
assertFalse("1.2 at least 1.5 passed", JAVA_1_2.atLeast(JAVA_1_5));
assertTrue("1.5 at least 1.2 failed", JAVA_1_5.atLeast(JAVA_1_2));
@@ -61,6 +64,7 @@
assertFalse("0.9 at least 1.6 passed", JAVA_0_9.atLeast(JAVA_1_6));
}
+ @Test
public void testToString() {
assertEquals("1.2", JAVA_1_2.toString());
}
diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
index 15b9107..490a446 100644
--- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
@@ -17,6 +17,11 @@
package org.apache.commons.lang3;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
@@ -28,14 +33,15 @@
import java.util.Locale;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
/**
* Unit tests for {@link LocaleUtils}.
*
* @version $Id$
*/
-public class LocaleUtilsTest extends TestCase {
+public class LocaleUtilsTest {
private static final Locale LOCALE_EN = new Locale("en", "");
private static final Locale LOCALE_EN_US = new Locale("en", "US");
@@ -45,19 +51,10 @@
private static final Locale LOCALE_QQ = new Locale("qq", "");
private static final Locale LOCALE_QQ_ZZ = new Locale("qq", "ZZ");
- /**
- * Constructor.
- *
- * @param name
- */
- public LocaleUtilsTest(String name) {
- super(name);
- }
- @Override
+
+ @Before
public void setUp() throws Exception {
- super.setUp();
-
// Testing #LANG-304. Must be called before availableLocaleSet is called.
LocaleUtils.isAvailableLocale(Locale.getDefault());
}
@@ -66,6 +63,7 @@
/**
* Test that constructors are public, and work, etc.
*/
+ @Test
public void testConstructor() {
assertNotNull(new LocaleUtils());
Constructor<?>[] cons = LocaleUtils.class.getDeclaredConstructors();
@@ -128,6 +126,7 @@
/**
* Test toLocale() method.
*/
+ @Test
public void testToLocale_1Part() {
assertEquals(null, LocaleUtils.toLocale((String) null));
@@ -174,6 +173,7 @@
/**
* Test toLocale() method.
*/
+ @Test
public void testToLocale_2Part() {
assertValidToLocale("us_EN", "us", "EN");
//valid though doesnt exist
@@ -208,6 +208,7 @@
/**
* Test toLocale() method.
*/
+ @Test
public void testToLocale_3Part() {
assertValidToLocale("us_EN_A", "us", "EN", "A");
// this isn't pretty, but was caused by a jdk bug it seems
@@ -252,6 +253,7 @@
/**
* Test localeLookupList() method.
*/
+ @Test
public void testLocaleLookupList_Locale() {
assertLocaleLookupList(null, null, new Locale[0]);
assertLocaleLookupList(LOCALE_QQ, null, new Locale[]{LOCALE_QQ});
@@ -271,6 +273,7 @@
/**
* Test localeLookupList() method.
*/
+ @Test
public void testLocaleLookupList_LocaleLocale() {
assertLocaleLookupList(LOCALE_QQ, LOCALE_QQ,
new Locale[]{LOCALE_QQ});
@@ -325,6 +328,7 @@
/**
* Test availableLocaleList() method.
*/
+ @Test
public void testAvailableLocaleList() {
List<Locale> list = LocaleUtils.availableLocaleList();
List<Locale> list2 = LocaleUtils.availableLocaleList();
@@ -341,6 +345,7 @@
/**
* Test availableLocaleSet() method.
*/
+ @Test
public void testAvailableLocaleSet() {
Set<Locale> set = LocaleUtils.availableLocaleSet();
Set<Locale> set2 = LocaleUtils.availableLocaleSet();
@@ -358,6 +363,7 @@
/**
* Test availableLocaleSet() method.
*/
+ @Test
public void testIsAvailableLocale() {
Set<Locale> set = LocaleUtils.availableLocaleSet();
assertEquals(set.contains(LOCALE_EN), LocaleUtils.isAvailableLocale(LOCALE_EN));
@@ -411,6 +417,7 @@
/**
* Test languagesByCountry() method.
*/
+ @Test
public void testLanguagesByCountry() {
assertLanguageByCountry(null, new String[0]);
assertLanguageByCountry("GB", new String[]{"en"});
@@ -461,6 +468,7 @@
/**
* Test countriesByLanguage() method.
*/
+ @Test
public void testCountriesByLanguage() {
assertCountriesByLanguage(null, new String[0]);
assertCountriesByLanguage("de", new String[]{"DE", "CH", "AT", "LU"});
@@ -481,6 +489,7 @@
/**
* Tests #LANG-328 - only language+variant
*/
+ @Test
public void testLang328() {
assertValidToLocale("fr__POSIX", "fr", "", "POSIX");
}
diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
index a7f57bf..a22002e 100644
--- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
@@ -16,24 +16,26 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Random;
+import org.junit.Test;
+
/**
* Unit tests {@link org.apache.commons.lang3.RandomStringUtils}.
*
* @version $Id$
*/
-public class RandomStringUtilsTest extends junit.framework.TestCase {
- /**
- * Construct a new instance of RandomStringUtilsTest with the specified name
- */
- public RandomStringUtilsTest(String name) {
- super(name);
- }
+public class RandomStringUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new RandomStringUtils());
Constructor<?>[] cons = RandomStringUtils.class.getDeclaredConstructors();
@@ -47,6 +49,7 @@
/**
* Test the implementation
*/
+ @Test
public void testRandomStringUtils() {
String r1 = RandomStringUtils.random(50);
assertEquals("random(50) length", 50, r1.length());
@@ -125,11 +128,13 @@
assertEquals("random(0).equals(\"\")", "", r1);
}
+ @Test
public void testLANG805() {
long seed = System.currentTimeMillis();
assertEquals("aaa", RandomStringUtils.random(3,0,0,false,false,new char[]{'a'},new Random(seed)));
}
+ @Test
public void testLANG807() {
try {
RandomStringUtils.random(3,5,5,false,false);
@@ -141,6 +146,7 @@
}
}
+ @Test
public void testExceptions() {
final char[] DUMMY = new char[]{'a'}; // valid char array
try {
@@ -185,6 +191,7 @@
* Make sure boundary alphanumeric characters are generated by randomAlphaNumeric
* This test will fail randomly with probability = 6 * (61/62)**1000 ~ 5.2E-7
*/
+ @Test
public void testRandomAlphaNumeric() {
char[] testChars = {'a', 'z', 'A', 'Z', '0', '9'};
boolean[] found = {false, false, false, false, false, false};
@@ -208,6 +215,7 @@
* Make sure '0' and '9' are generated by randomNumeric
* This test will fail randomly with probability = 2 * (9/10)**1000 ~ 3.5E-46
*/
+ @Test
public void testRandomNumeric() {
char[] testChars = {'0','9'};
boolean[] found = {false, false};
@@ -231,6 +239,7 @@
* Make sure boundary alpha characters are generated by randomAlphabetic
* This test will fail randomly with probability = 4 * (51/52)**1000 ~ 1.58E-8
*/
+ @Test
public void testRandomAlphabetic() {
char[] testChars = {'a', 'z', 'A', 'Z'};
boolean[] found = {false, false, false, false};
@@ -254,6 +263,7 @@
* Make sure 32 and 127 are generated by randomNumeric
* This test will fail randomly with probability = 2*(95/96)**1000 ~ 5.7E-5
*/
+ @Test
public void testRandomAscii() {
char[] testChars = {(char) 32, (char) 126};
boolean[] found = {false, false};
@@ -280,6 +290,7 @@
* in generated strings. Will fail randomly about 1 in 1000 times.
* Repeated failures indicate a problem.
*/
+ @Test
public void testRandomStringUtilsHomog() {
String set = "abc";
char[] chars = set.toCharArray();
@@ -325,6 +336,7 @@
*
* @throws Exception
*/
+ @Test
public void testLang100() throws Exception {
int size = 5000;
String encoding = "UTF-8";
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index f514b6d..e2e370e 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -16,20 +16,22 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import java.util.Locale;
-import junit.framework.TestCase;
-
import org.hamcrest.core.IsNot;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
*
* @version $Id$
*/
-public class StringUtilsEqualsIndexOfTest extends TestCase {
+public class StringUtilsEqualsIndexOfTest {
private static final String BAR = "bar";
/**
* Supplementary character U+20000
@@ -59,10 +61,7 @@
private static final String[] FOOBAR_SUB_ARRAY = new String[] {"ob", "ba"};
- public StringUtilsEqualsIndexOfTest(String name) {
- super(name);
- }
-
+ @Test
public void testContains_Char() {
assertEquals(false, StringUtils.contains(null, ' '));
assertEquals(false, StringUtils.contains("", ' '));
@@ -74,6 +73,7 @@
assertEquals(false, StringUtils.contains("abc", 'z'));
}
+ @Test
public void testContains_String() {
assertEquals(false, StringUtils.contains(null, null));
assertEquals(false, StringUtils.contains(null, ""));
@@ -91,6 +91,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContains_StringWithBadSupplementaryChars() {
// Test edge case: 1/2 of a (broken) supplementary char
assertEquals(false, StringUtils.contains(CharUSuppCharHigh, CharU20001));
@@ -105,6 +106,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContains_StringWithSupplementaryChars() {
assertEquals(true, StringUtils.contains(CharU20000 + CharU20001, CharU20000));
assertEquals(true, StringUtils.contains(CharU20000 + CharU20001, CharU20001));
@@ -112,6 +114,7 @@
assertEquals(false, StringUtils.contains(CharU20000, CharU20001));
}
+ @Test
public void testContainsAny_StringCharArray() {
assertFalse(StringUtils.containsAny(null, (char[]) null));
assertFalse(StringUtils.containsAny(null, new char[0]));
@@ -131,6 +134,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsAny_StringCharArrayWithBadSupplementaryChars() {
// Test edge case: 1/2 of a (broken) supplementary char
assertEquals(false, StringUtils.containsAny(CharUSuppCharHigh, CharU20001.toCharArray()));
@@ -145,6 +149,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsAny_StringCharArrayWithSupplementaryChars() {
assertEquals(true, StringUtils.containsAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(true, StringUtils.containsAny("a" + CharU20000 + CharU20001, "a".toCharArray()));
@@ -161,6 +166,7 @@
assertEquals(false, StringUtils.containsAny(CharU20001, CharU20000.toCharArray()));
}
+ @Test
public void testContainsAny_StringString() {
assertFalse(StringUtils.containsAny(null, (String) null));
assertFalse(StringUtils.containsAny(null, ""));
@@ -180,6 +186,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsAny_StringWithBadSupplementaryChars() {
// Test edge case: 1/2 of a (broken) supplementary char
assertEquals(false, StringUtils.containsAny(CharUSuppCharHigh, CharU20001));
@@ -193,6 +200,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsAny_StringWithSupplementaryChars() {
assertEquals(true, StringUtils.containsAny(CharU20000 + CharU20001, CharU20000));
assertEquals(true, StringUtils.containsAny(CharU20000 + CharU20001, CharU20001));
@@ -206,6 +214,7 @@
assertEquals(false, StringUtils.containsAny(CharU20001, CharU20000));
}
+ @Test
public void testContainsIgnoreCase_LocaleIndependence() {
Locale orig = Locale.getDefault();
@@ -240,6 +249,7 @@
}
}
+ @Test
public void testContainsIgnoreCase_StringString() {
assertFalse(StringUtils.containsIgnoreCase(null, null));
@@ -274,6 +284,7 @@
assertTrue(StringUtils.containsIgnoreCase("xabcz", "ABC"));
}
+ @Test
public void testContainsNone_CharArray() {
String str1 = "a";
String str2 = "b";
@@ -302,6 +313,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsNone_CharArrayWithBadSupplementaryChars() {
// Test edge case: 1/2 of a (broken) supplementary char
assertEquals(true, StringUtils.containsNone(CharUSuppCharHigh, CharU20001.toCharArray()));
@@ -316,6 +328,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsNone_CharArrayWithSupplementaryChars() {
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20001.toCharArray()));
@@ -329,6 +342,7 @@
assertEquals(true, StringUtils.containsNone(CharU20001, CharU20000.toCharArray()));
}
+ @Test
public void testContainsNone_String() {
String str1 = "a";
String str2 = "b";
@@ -356,6 +370,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsNone_StringWithBadSupplementaryChars() {
// Test edge case: 1/2 of a (broken) supplementary char
assertEquals(true, StringUtils.containsNone(CharUSuppCharHigh, CharU20001));
@@ -370,6 +385,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testContainsNone_StringWithSupplementaryChars() {
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20000));
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20001));
@@ -383,6 +399,7 @@
assertEquals(true, StringUtils.containsNone(CharU20001, CharU20000));
}
+ @Test
public void testContainsOnly_CharArray() {
String str1 = "a";
String str2 = "b";
@@ -408,6 +425,7 @@
assertEquals(true, StringUtils.containsOnly(str3, chars3));
}
+ @Test
public void testContainsOnly_String() {
String str1 = "a";
String str2 = "b";
@@ -432,6 +450,7 @@
assertEquals(true, StringUtils.containsOnly(str3, chars3));
}
+ @Test
public void testContainsWhitespace() {
assertFalse( StringUtils.containsWhitespace("") );
assertTrue( StringUtils.containsWhitespace(" ") );
@@ -483,12 +502,14 @@
}
}
+ @Test
public void testCustomCharSequence() {
assertThat(new CustomCharSequence(FOO), IsNot.<CharSequence>not(FOO));
assertThat(FOO, IsNot.<CharSequence>not(new CustomCharSequence(FOO)));
assertEquals(new CustomCharSequence(FOO), new CustomCharSequence(FOO));
}
+ @Test
public void testEquals() {
final CharSequence fooCs = FOO, barCs = BAR, foobarCs = FOOBAR;
assertTrue(StringUtils.equals(null, null));
@@ -505,6 +526,7 @@
assertFalse(StringUtils.equals(foobarCs, fooCs));
}
+ @Test
public void testEqualsOnStrings() {
assertTrue(StringUtils.equals(null, null));
assertTrue(StringUtils.equals(FOO, FOO));
@@ -517,6 +539,7 @@
assertFalse(StringUtils.equals(FOOBAR, FOO));
}
+ @Test
public void testEqualsIgnoreCase() {
assertEquals(true, StringUtils.equalsIgnoreCase(null, null));
assertEquals(true, StringUtils.equalsIgnoreCase(FOO, FOO));
@@ -530,6 +553,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOf_char() {
assertEquals(-1, StringUtils.indexOf(null, ' '));
assertEquals(-1, StringUtils.indexOf("", ' '));
@@ -539,6 +563,7 @@
assertEquals(2, StringUtils.indexOf(new StringBuilder("aabaabaa"), 'b'));
}
+ @Test
public void testIndexOf_charInt() {
assertEquals(-1, StringUtils.indexOf(null, ' ', 0));
assertEquals(-1, StringUtils.indexOf(null, ' ', -1));
@@ -553,6 +578,7 @@
assertEquals(5, StringUtils.indexOf(new StringBuilder("aabaabaa"), 'b', 3));
}
+ @Test
public void testIndexOf_String() {
assertEquals(-1, StringUtils.indexOf(null, null));
assertEquals(-1, StringUtils.indexOf("", null));
@@ -565,6 +591,7 @@
assertEquals(2, StringUtils.indexOf(new StringBuilder("aabaabaa"), "b"));
}
+ @Test
public void testIndexOf_StringInt() {
assertEquals(-1, StringUtils.indexOf(null, null, 0));
assertEquals(-1, StringUtils.indexOf(null, null, -1));
@@ -590,6 +617,7 @@
assertEquals(5, StringUtils.indexOf(new StringBuilder("aabaabaa"), "b", 3));
}
+ @Test
public void testIndexOfAny_StringCharArray() {
assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAny(null, new char[0]));
@@ -609,6 +637,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testIndexOfAny_StringCharArrayWithSupplementaryChars() {
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray()));
@@ -616,6 +645,7 @@
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray()));
}
+ @Test
public void testIndexOfAny_StringString() {
assertEquals(-1, StringUtils.indexOfAny(null, (String) null));
assertEquals(-1, StringUtils.indexOfAny(null, ""));
@@ -632,6 +662,7 @@
assertEquals(-1, StringUtils.indexOfAny("ab", "z"));
}
+ @Test
public void testIndexOfAny_StringStringArray() {
assertEquals(-1, StringUtils.indexOfAny(null, (String[]) null));
assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY));
@@ -652,6 +683,7 @@
/**
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
+ @Test
public void testIndexOfAny_StringStringWithSupplementaryChars() {
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000));
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001));
@@ -659,6 +691,7 @@
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001));
}
+ @Test
public void testIndexOfAnyBut_StringCharArray() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0]));
@@ -677,6 +710,7 @@
}
+ @Test
public void testIndexOfAnyBut_StringCharArrayWithSupplementaryChars() {
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001.toCharArray()));
@@ -684,6 +718,7 @@
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001.toCharArray()));
}
+ @Test
public void testIndexOfAnyBut_StringString() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, ""));
@@ -700,6 +735,7 @@
assertEquals(0, StringUtils.indexOfAnyBut("ab", "z"));
}
+ @Test
public void testIndexOfAnyBut_StringStringWithSupplementaryChars() {
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001));
@@ -707,6 +743,7 @@
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001));
}
+ @Test
public void testIndexOfIgnoreCase_String() {
assertEquals(-1, StringUtils.indexOfIgnoreCase(null, null));
assertEquals(-1, StringUtils.indexOfIgnoreCase(null, ""));
@@ -721,6 +758,7 @@
assertEquals(0, StringUtils.indexOfIgnoreCase("aabaabaa", ""));
}
+ @Test
public void testIndexOfIgnoreCase_StringInt() {
assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", -1));
assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 0));
@@ -738,6 +776,7 @@
assertEquals(-1, StringUtils.indexOfIgnoreCase("aab", "AAB", 1));
}
+ @Test
public void testLastIndexOf_char() {
assertEquals(-1, StringUtils.lastIndexOf(null, ' '));
assertEquals(-1, StringUtils.lastIndexOf("", ' '));
@@ -747,6 +786,7 @@
assertEquals(5, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), 'b'));
}
+ @Test
public void testLastIndexOf_charInt() {
assertEquals(-1, StringUtils.lastIndexOf(null, ' ', 0));
assertEquals(-1, StringUtils.lastIndexOf(null, ' ', -1));
@@ -762,6 +802,7 @@
assertEquals(2, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), 'b', 2));
}
+ @Test
public void testLastIndexOf_String() {
assertEquals(-1, StringUtils.lastIndexOf(null, null));
assertEquals(-1, StringUtils.lastIndexOf("", null));
@@ -775,6 +816,7 @@
assertEquals(4, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), "ab"));
}
+ @Test
public void testLastIndexOf_StringInt() {
assertEquals(-1, StringUtils.lastIndexOf(null, null, 0));
assertEquals(-1, StringUtils.lastIndexOf(null, null, -1));
@@ -800,6 +842,7 @@
assertEquals(2, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), "b", 3));
}
+ @Test
public void testLastIndexOfAny_StringStringArray() {
assertEquals(-1, StringUtils.lastIndexOfAny(null, (CharSequence) null)); // test both types of ...
assertEquals(-1, StringUtils.lastIndexOfAny(null, (CharSequence[]) null)); // ... varargs invocation
@@ -821,6 +864,7 @@
assertEquals(-1, StringUtils.lastIndexOfAny(null, new String[] {null}));
}
+ @Test
public void testLastIndexOfIgnoreCase_String() {
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null));
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", null));
@@ -838,6 +882,7 @@
assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aab", "AAB"));
}
+ @Test
public void testLastIndexOfIgnoreCase_StringInt() {
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, 0));
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, -1));
@@ -862,6 +907,7 @@
assertEquals(1, StringUtils.lastIndexOfIgnoreCase("aab", "AB", 1));
}
+ @Test
public void testLastOrdinalIndexOf() {
assertEquals(-1, StringUtils.lastOrdinalIndexOf(null, "*", 42) );
assertEquals(-1, StringUtils.lastOrdinalIndexOf("*", null, 42) );
@@ -876,6 +922,7 @@
assertEquals(8, StringUtils.lastOrdinalIndexOf("aabaabaa", "", 2) );
}
+ @Test
public void testOrdinalIndexOf() {
assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MIN_VALUE));
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java
index 9848d84..cfc32bb 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java
@@ -16,21 +16,20 @@
*/
package org.apache.commons.lang3;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
*
* @version $Id$
*/
-public class StringUtilsIsTest extends TestCase {
-
- public StringUtilsIsTest(String name) {
- super(name);
- }
+public class StringUtilsIsTest {
//-----------------------------------------------------------------------
+ @Test
public void testIsAlpha() {
assertEquals(false, StringUtils.isAlpha(null));
assertEquals(false, StringUtils.isAlpha(""));
@@ -45,6 +44,7 @@
assertEquals(false, StringUtils.isAlpha("hkHKHik*khbkuh"));
}
+ @Test
public void testIsAlphanumeric() {
assertEquals(false, StringUtils.isAlphanumeric(null));
assertEquals(false, StringUtils.isAlphanumeric(""));
@@ -59,6 +59,7 @@
assertEquals(false, StringUtils.isAlphanumeric("hkHKHik*khbkuh"));
}
+ @Test
public void testIsWhitespace() {
assertEquals(false, StringUtils.isWhitespace(null));
assertEquals(true, StringUtils.isWhitespace(""));
@@ -74,6 +75,7 @@
assertEquals(false, StringUtils.isWhitespace(StringUtilsTest.NON_WHITESPACE));
}
+ @Test
public void testIsAlphaspace() {
assertEquals(false, StringUtils.isAlphaSpace(null));
assertEquals(true, StringUtils.isAlphaSpace(""));
@@ -88,6 +90,7 @@
assertEquals(false, StringUtils.isAlphaSpace("hkHKHik*khbkuh"));
}
+ @Test
public void testIsAlphanumericSpace() {
assertEquals(false, StringUtils.isAlphanumericSpace(null));
assertEquals(true, StringUtils.isAlphanumericSpace(""));
@@ -102,6 +105,7 @@
assertEquals(false, StringUtils.isAlphanumericSpace("hkHKHik*khbkuh"));
}
+ @Test
public void testIsAsciiPrintable_String() {
assertEquals(false, StringUtils.isAsciiPrintable(null));
assertEquals(true, StringUtils.isAsciiPrintable(""));
@@ -127,6 +131,7 @@
assertEquals(false, StringUtils.isAsciiPrintable("G\u00fclc\u00fc"));
}
+ @Test
public void testIsNumeric() {
assertEquals(false, StringUtils.isNumeric(null));
assertEquals(false, StringUtils.isNumeric(""));
@@ -146,6 +151,7 @@
assertEquals(false, StringUtils.isNumeric("-123"));
}
+ @Test
public void testIsNumericSpace() {
assertEquals(false, StringUtils.isNumericSpace(null));
assertEquals(true, StringUtils.isNumericSpace(""));
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsStartsEndsWithTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsStartsEndsWithTest.java
index 5343e01..d994e8f 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsStartsEndsWithTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsStartsEndsWithTest.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.lang3;
-import junit.framework.TestCase;
-
+import org.junit.Test;
+import static org.junit.Assert.*;
import org.apache.commons.lang3.text.StrBuilder;
/**
@@ -25,7 +25,7 @@
*
* @version $Id$
*/
-public class StringUtilsStartsEndsWithTest extends TestCase {
+public class StringUtilsStartsEndsWithTest {
private static final String foo = "foo";
private static final String bar = "bar";
private static final String foobar = "foobar";
@@ -33,15 +33,12 @@
private static final String BAR = "BAR";
private static final String FOOBAR = "FOOBAR";
- public StringUtilsStartsEndsWithTest(String name) {
- super(name);
- }
-
//-----------------------------------------------------------------------
/**
* Test StringUtils.startsWith()
*/
+ @Test
public void testStartsWith() {
assertTrue("startsWith(null, null)", StringUtils.startsWith(null, (String)null));
assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, (String)null));
@@ -65,6 +62,7 @@
/**
* Test StringUtils.testStartsWithIgnoreCase()
*/
+ @Test
public void testStartsWithIgnoreCase() {
assertTrue("startsWithIgnoreCase(null, null)", StringUtils.startsWithIgnoreCase(null, (String)null));
assertFalse("startsWithIgnoreCase(FOOBAR, null)", StringUtils.startsWithIgnoreCase(FOOBAR, (String)null));
@@ -85,6 +83,7 @@
assertFalse("startsWithIgnoreCase(FOOBAR, bar)", StringUtils.startsWithIgnoreCase(FOOBAR, bar));
}
+ @Test
public void testStartsWithAny() {
assertFalse(StringUtils.startsWithAny(null, (String[])null));
assertFalse(StringUtils.startsWithAny(null, "abc"));
@@ -102,6 +101,7 @@
/**
* Test StringUtils.endsWith()
*/
+ @Test
public void testEndsWith() {
assertTrue("endsWith(null, null)", StringUtils.endsWith(null, (String)null));
assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR, (String)null));
@@ -125,6 +125,7 @@
/**
* Test StringUtils.endsWithIgnoreCase()
*/
+ @Test
public void testEndsWithIgnoreCase() {
assertTrue("endsWithIgnoreCase(null, null)", StringUtils.endsWithIgnoreCase(null, (String)null));
assertFalse("endsWithIgnoreCase(FOOBAR, null)", StringUtils.endsWithIgnoreCase(FOOBAR, (String)null));
@@ -150,6 +151,7 @@
assertFalse(StringUtils.endsWithIgnoreCase("ABCDEF", "cde"));
}
+ @Test
public void testEndsWithAny() {
assertFalse("StringUtils.endsWithAny(null, null)", StringUtils.endsWithAny(null, (String)null));
assertFalse("StringUtils.endsWithAny(null, new String[] {abc})", StringUtils.endsWithAny(null, new String[] {"abc"}));
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
index 788cc93..d1acba3 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java
@@ -16,27 +16,27 @@
*/
package org.apache.commons.lang3;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
*
* @version $Id$
*/
-public class StringUtilsSubstringTest extends TestCase {
+public class StringUtilsSubstringTest {
private static final String FOO = "foo";
private static final String BAR = "bar";
private static final String BAZ = "baz";
private static final String FOOBAR = "foobar";
private static final String SENTENCE = "foo bar baz";
- public StringUtilsSubstringTest(String name) {
- super(name);
- }
-
//-----------------------------------------------------------------------
-
+ @Test
public void testSubstring_StringInt() {
assertEquals(null, StringUtils.substring(null, 0));
assertEquals("", StringUtils.substring("", 0));
@@ -57,6 +57,7 @@
assertEquals("", StringUtils.substring("abc", 4));
}
+ @Test
public void testSubstring_StringIntInt() {
assertEquals(null, StringUtils.substring(null, 0, 0));
assertEquals(null, StringUtils.substring(null, 1, 2));
@@ -74,6 +75,7 @@
assertEquals("b",StringUtils.substring("abc", -2, -1));
}
+ @Test
public void testLeft_String() {
assertSame(null, StringUtils.left(null, -1));
assertSame(null, StringUtils.left(null, 0));
@@ -89,6 +91,7 @@
assertSame(FOOBAR, StringUtils.left(FOOBAR, 80));
}
+ @Test
public void testRight_String() {
assertSame(null, StringUtils.right(null, -1));
assertSame(null, StringUtils.right(null, 0));
@@ -104,6 +107,7 @@
assertSame(FOOBAR, StringUtils.right(FOOBAR, 80));
}
+ @Test
public void testMid_String() {
assertSame(null, StringUtils.mid(null, -1, 0));
assertSame(null, StringUtils.mid(null, 0, -1));
@@ -126,6 +130,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSubstringBefore_StringString() {
assertEquals("foo", StringUtils.substringBefore("fooXXbarXXbaz", "XX"));
@@ -145,6 +150,7 @@
assertEquals("", StringUtils.substringBefore("abc", ""));
}
+ @Test
public void testSubstringAfter_StringString() {
assertEquals("barXXbaz", StringUtils.substringAfter("fooXXbarXXbaz", "XX"));
@@ -164,6 +170,7 @@
assertEquals("", StringUtils.substringAfter("abc", "d"));
}
+ @Test
public void testSubstringBeforeLast_StringString() {
assertEquals("fooXXbar", StringUtils.substringBeforeLast("fooXXbarXXbaz", "XX"));
@@ -187,6 +194,7 @@
assertEquals("", StringUtils.substringBeforeLast("a", "a"));
}
+ @Test
public void testSubstringAfterLast_StringString() {
assertEquals("baz", StringUtils.substringAfterLast("fooXXbarXXbaz", "XX"));
@@ -208,6 +216,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSubstringBetween_StringString() {
assertEquals(null, StringUtils.substringBetween(null, "tag"));
assertEquals("", StringUtils.substringBetween("", ""));
@@ -221,6 +230,7 @@
assertEquals("bar", StringUtils.substringBetween("\nbar\n", "\n"));
}
+ @Test
public void testSubstringBetween_StringStringString() {
assertEquals(null, StringUtils.substringBetween(null, "", ""));
assertEquals(null, StringUtils.substringBetween("", null, ""));
@@ -236,6 +246,7 @@
/**
* Tests the substringsBetween method that returns an String Array of substrings.
*/
+ @Test
public void testSubstringsBetween_StringStringString() {
String[] results = StringUtils.substringsBetween("[one], [two], [three]", "[", "]");
@@ -294,6 +305,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCountMatches_String() {
assertEquals(0, StringUtils.countMatches(null, null));
assertEquals(0, StringUtils.countMatches("blah", null));
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTrimEmptyTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTrimEmptyTest.java
index a3c8503..6965509 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTrimEmptyTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTrimEmptyTest.java
@@ -16,21 +16,22 @@
*/
package org.apache.commons.lang3;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Trim/Empty methods
*
* @version $Id$
*/
-public class StringUtilsTrimEmptyTest extends TestCase {
+public class StringUtilsTrimEmptyTest {
private static final String FOO = "foo";
- public StringUtilsTrimEmptyTest(String name) {
- super(name);
- }
-
//-----------------------------------------------------------------------
+ @Test
public void testIsEmpty() {
assertEquals(true, StringUtils.isEmpty(null));
assertEquals(true, StringUtils.isEmpty(""));
@@ -39,6 +40,7 @@
assertEquals(false, StringUtils.isEmpty(" foo "));
}
+ @Test
public void testIsNotEmpty() {
assertEquals(false, StringUtils.isNotEmpty(null));
assertEquals(false, StringUtils.isNotEmpty(""));
@@ -47,6 +49,7 @@
assertEquals(true, StringUtils.isNotEmpty(" foo "));
}
+ @Test
public void testIsBlank() {
assertEquals(true, StringUtils.isBlank(null));
assertEquals(true, StringUtils.isBlank(""));
@@ -55,6 +58,7 @@
assertEquals(false, StringUtils.isBlank(" foo "));
}
+ @Test
public void testIsNotBlank() {
assertEquals(false, StringUtils.isNotBlank(null));
assertEquals(false, StringUtils.isNotBlank(""));
@@ -64,6 +68,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTrim() {
assertEquals(FOO, StringUtils.trim(FOO + " "));
assertEquals(FOO, StringUtils.trim(" " + FOO + " "));
@@ -76,6 +81,7 @@
assertEquals(null, StringUtils.trim(null));
}
+ @Test
public void testTrimToNull() {
assertEquals(FOO, StringUtils.trimToNull(FOO + " "));
assertEquals(FOO, StringUtils.trimToNull(" " + FOO + " "));
@@ -88,6 +94,7 @@
assertEquals(null, StringUtils.trimToNull(null));
}
+ @Test
public void testTrimToEmpty() {
assertEquals(FOO, StringUtils.trimToEmpty(FOO + " "));
assertEquals(FOO, StringUtils.trimToEmpty(" " + FOO + " "));
@@ -101,6 +108,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testStrip_String() {
assertEquals(null, StringUtils.strip(null));
assertEquals("", StringUtils.strip(""));
@@ -110,6 +118,7 @@
StringUtils.strip(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE));
}
+ @Test
public void testStripToNull_String() {
assertEquals(null, StringUtils.stripToNull(null));
assertEquals(null, StringUtils.stripToNull(""));
@@ -120,6 +129,7 @@
StringUtils.stripToNull(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE));
}
+ @Test
public void testStripToEmpty_String() {
assertEquals("", StringUtils.stripToEmpty(null));
assertEquals("", StringUtils.stripToEmpty(""));
@@ -130,6 +140,7 @@
StringUtils.stripToEmpty(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE));
}
+ @Test
public void testStrip_StringString() {
// null strip
assertEquals(null, StringUtils.strip(null, null));
@@ -161,6 +172,7 @@
assertEquals(StringUtilsTest.WHITESPACE, StringUtils.strip(StringUtilsTest.WHITESPACE, ""));
}
+ @Test
public void testStripStart_StringString() {
// null stripStart
assertEquals(null, StringUtils.stripStart(null, null));
@@ -192,6 +204,7 @@
assertEquals(StringUtilsTest.WHITESPACE, StringUtils.stripStart(StringUtilsTest.WHITESPACE, ""));
}
+ @Test
public void testStripEnd_StringString() {
// null stripEnd
assertEquals(null, StringUtils.stripEnd(null, null));
@@ -223,6 +236,7 @@
assertEquals(StringUtilsTest.WHITESPACE, StringUtils.stripEnd(StringUtilsTest.WHITESPACE, ""));
}
+ @Test
public void testStripAll() {
// test stripAll method, merely an array version of the above strip
String[] empty = new String[0];
@@ -230,8 +244,7 @@
String[] fooDots = new String[] { ".."+FOO+"..", ".."+FOO, FOO+".." };
String[] foo = new String[] { FOO, FOO, FOO };
-// assertEquals(null, StringUtils.stripAll(null)); // generates warning
- assertEquals(null, StringUtils.stripAll((String[]) null)); // equivalent explicit cast
+ assertNull(StringUtils.stripAll((String[]) null));
// Additional varargs tests
assertArrayEquals(empty, StringUtils.stripAll()); // empty array
assertArrayEquals(new String[]{null}, StringUtils.stripAll((String) null)); // == new String[]{null}
@@ -239,11 +252,12 @@
assertArrayEquals(empty, StringUtils.stripAll(empty));
assertArrayEquals(foo, StringUtils.stripAll(fooSpace));
- assertEquals(null, StringUtils.stripAll(null, null));
+ assertNull(StringUtils.stripAll(null, null));
assertArrayEquals(foo, StringUtils.stripAll(fooSpace, null));
assertArrayEquals(foo, StringUtils.stripAll(fooDots, "."));
}
+ @Test
public void testStripAccents() {
String cue = "\u00C7\u00FA\u00EA";
assertEquals( "Failed to strip accents from " + cue, "Cue", StringUtils.stripAccents(cue));
@@ -260,24 +274,4 @@
assertEquals( "Failed to handle non-accented text", "control", StringUtils.stripAccents("control") );
assertEquals( "Failed to handle easy example", "eclair", StringUtils.stripAccents("\u00E9clair") );
}
-
- //-----------------------------------------------------------------------
-
- private void assertArrayEquals(Object[] o1, Object[] o2) {
- if(o1 == null) {
- assertEquals(o1,o2);
- return;
- }
- assertEquals("Length not equal. ", o1.length, o2.length);
- int sz = o1.length;
- for(int i=0; i<sz; i++) {
- if(o1[i] instanceof Object[]) {
- // do an assert equals on type....
- assertArrayEquals( (Object[]) o1[i], (Object[]) o2[i] );
- } else {
- assertEquals(o1[i], o2[i]);
- }
- }
- }
-
}
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index 7977494..312f9be 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -19,6 +19,8 @@
package org.apache.commons.lang3;
+import org.junit.Test;
+import static org.junit.Assert.*;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
import java.io.File;
@@ -27,7 +29,6 @@
import java.util.Locale;
import junit.framework.Assert;
-import junit.framework.TestCase;
/**
* Unit tests {@link org.apache.commons.lang3.SystemUtils}.
@@ -36,12 +37,9 @@
*
* @version $Id$
*/
-public class SystemUtilsTest extends TestCase {
+public class SystemUtilsTest {
- public SystemUtilsTest(String name) {
- super(name);
- }
-
+ @Test
public void testConstructor() {
assertNotNull(new SystemUtils());
Constructor<?>[] cons = SystemUtils.class.getDeclaredConstructors();
@@ -54,6 +52,7 @@
/**
* Assums no security manager exists.
*/
+ @Test
public void testGetJavaHome() {
File dir = SystemUtils.getJavaHome();
Assert.assertNotNull(dir);
@@ -63,6 +62,7 @@
/**
* Assums no security manager exists.
*/
+ @Test
public void testGetJavaIoTmpDir() {
File dir = SystemUtils.getJavaIoTmpDir();
Assert.assertNotNull(dir);
@@ -72,6 +72,7 @@
/**
* Assums no security manager exists.
*/
+ @Test
public void testGetUserDir() {
File dir = SystemUtils.getUserDir();
Assert.assertNotNull(dir);
@@ -81,12 +82,14 @@
/**
* Assums no security manager exists.
*/
+ @Test
public void testGetUserHome() {
File dir = SystemUtils.getUserHome();
Assert.assertNotNull(dir);
Assert.assertTrue(dir.exists());
}
+ @Test
public void testIS_JAVA() {
String javaVersion = System.getProperty("java.version");
if (javaVersion == null) {
@@ -150,6 +153,7 @@
}
}
+ @Test
public void testIS_OS() {
String osName = System.getProperty("os.name");
if (osName == null) {
@@ -186,6 +190,7 @@
}
}
+ @Test
public void testJavaVersionMatches() {
String javaVersion = null;
assertEquals(false, SystemUtils.isJavaVersionMatch(javaVersion, "1.0"));
@@ -306,6 +311,7 @@
assertEquals(true, SystemUtils.isJavaVersionMatch(javaVersion, "1.7"));
}
+ @Test
public void testOSMatchesName() {
String osName = null;
assertEquals(false, SystemUtils.isOSNameMatch(osName, "Windows"));
@@ -319,6 +325,7 @@
assertEquals(false, SystemUtils.isOSNameMatch(osName, "Windows"));
}
+ @Test
public void testOSMatchesNameAndVersion() {
String osName = null;
String osVersion = null;
@@ -343,6 +350,7 @@
assertEquals(false, SystemUtils.isOSMatch(osName, osVersion, "Windows 9", "4.1"));
}
+ @Test
public void testJavaAwtHeadless() {
boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(JAVA_1_4);
String expectedStringValue = System.getProperty("java.awt.headless");
diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java
index b802130..4bdd0cd 100644
--- a/src/test/java/org/apache/commons/lang3/ValidateTest.java
+++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java
@@ -18,6 +18,11 @@
*/
package org.apache.commons.lang3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.AbstractList;
@@ -28,20 +33,17 @@
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.Validate}.
*
* @version $Id$
*/
-public class ValidateTest extends TestCase {
-
- public ValidateTest(String name) {
- super(name);
- }
-
+public class ValidateTest {
+
//-----------------------------------------------------------------------
+ @Test
public void testIsTrue1() {
Validate.isTrue(true);
try {
@@ -53,6 +55,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsTrue2() {
Validate.isTrue(true, "MSG");
try {
@@ -64,6 +67,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsTrue3() {
Validate.isTrue(true, "MSG", 6);
try {
@@ -75,6 +79,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsTrue4() {
Validate.isTrue(true, "MSG", 7);
try {
@@ -86,6 +91,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsTrue5() {
Validate.isTrue(true, "MSG", 7.4d);
try {
@@ -98,6 +104,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNotNull1() {
Validate.notNull(new Object());
try {
@@ -113,6 +120,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotNull2() {
Validate.notNull(new Object(), "MSG");
try {
@@ -129,6 +137,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyArray1() {
Validate.notEmpty(new Object[] {null});
try {
@@ -150,6 +159,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyArray2() {
Validate.notEmpty(new Object[] {null}, "MSG");
try {
@@ -172,6 +182,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyCollection1() {
Collection<Integer> coll = new ArrayList<Integer>();
try {
@@ -194,6 +205,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyCollection2() {
Collection<Integer> coll = new ArrayList<Integer>();
try {
@@ -217,6 +229,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyMap1() {
Map<String, Integer> map = new HashMap<String, Integer>();
try {
@@ -239,6 +252,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyMap2() {
Map<String, Integer> map = new HashMap<String, Integer>();
try {
@@ -262,6 +276,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyString1() {
Validate.notEmpty("hjl");
try {
@@ -283,6 +298,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotEmptyString2() {
Validate.notEmpty("a", "MSG");
try {
@@ -305,6 +321,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankNullStringShouldThrow() {
//given
String string = null;
@@ -320,6 +337,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgNullStringShouldThrow() {
//given
String string = null;
@@ -335,6 +353,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankEmptyStringShouldThrow() {
//given
String string = "";
@@ -350,6 +369,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankBlankStringWithWhitespacesShouldThrow() {
//given
String string = " ";
@@ -365,6 +385,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankBlankStringWithNewlinesShouldThrow() {
//given
String string = " \n \t \r \n ";
@@ -380,6 +401,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgBlankStringShouldThrow() {
//given
String string = " \n \t \r \n ";
@@ -395,6 +417,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgBlankStringWithWhitespacesShouldThrow() {
//given
String string = " ";
@@ -410,6 +433,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgEmptyStringShouldThrow() {
//given
String string = "";
@@ -425,6 +449,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankNotBlankStringShouldNotThrow() {
//given
String string = "abc";
@@ -436,6 +461,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankNotBlankStringWithWhitespacesShouldNotThrow() {
//given
String string = " abc ";
@@ -447,6 +473,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankNotBlankStringWithNewlinesShouldNotThrow() {
//given
String string = " \n \t abc \r \n ";
@@ -458,6 +485,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgNotBlankStringShouldNotThrow() {
//given
String string = "abc";
@@ -469,6 +497,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgNotBlankStringWithWhitespacesShouldNotThrow() {
//given
String string = " abc ";
@@ -480,6 +509,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankMsgNotBlankStringWithNewlinesShouldNotThrow() {
//given
String string = " \n \t abc \r \n ";
@@ -491,12 +521,14 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNotBlankReturnValues1() {
String str = "Hi";
String test = Validate.notBlank(str);
assertSame(str, test);
}
+ @Test
public void testNotBlankReturnValues2() {
String str = "Hi";
String test = Validate.notBlank(str, "Message");
@@ -505,6 +537,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNoNullElementsArray1() {
String[] array = new String[] {"a", "b"};
Validate.noNullElements(array);
@@ -528,6 +561,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNoNullElementsArray2() {
String[] array = new String[] {"a", "b"};
Validate.noNullElements(array, "MSG");
@@ -552,6 +586,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testNoNullElementsCollection1() {
List<String> coll = new ArrayList<String>();
coll.add("a");
@@ -577,6 +612,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNoNullElementsCollection2() {
List<String> coll = new ArrayList<String>();
coll.add("a");
@@ -603,6 +639,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new Validate());
Constructor<?>[] cons = Validate.class.getDeclaredConstructors();
@@ -614,6 +651,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testValidIndex_withMessage_array() {
Object[] array = new Object[2];
Validate.validIndex(array, 0, "Broken: ");
@@ -636,6 +674,7 @@
assertSame(strArray, test);
}
+ @Test
public void testValidIndex_array() {
Object[] array = new Object[2];
Validate.validIndex(array, 0);
@@ -660,6 +699,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testValidIndex_withMessage_collection() {
Collection<String> coll = new ArrayList<String>();
coll.add(null);
@@ -684,6 +724,7 @@
assertSame(strColl, test);
}
+ @Test
public void testValidIndex_collection() {
Collection<String> coll = new ArrayList<String>();
coll.add(null);
@@ -710,6 +751,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
+ @Test
public void testValidIndex_withMessage_charSequence() {
CharSequence str = "Hi";
Validate.validIndex(str, 0, "Broken: ");
@@ -732,6 +774,7 @@
assertSame(input, test);
}
+ @Test
public void testValidIndex_charSequence() {
CharSequence str = "Hi";
Validate.validIndex(str, 0);
@@ -754,6 +797,7 @@
assertSame(input, test);
}
+ @Test
public void testMatchesPattern()
{
CharSequence str = "hi";
@@ -769,6 +813,7 @@
}
}
+ @Test
public void testMatchesPattern_withMessage()
{
CharSequence str = "hi";
@@ -784,6 +829,7 @@
}
}
+ @Test
public void testInclusiveBetween()
{
Validate.inclusiveBetween("a", "c", "b");
@@ -797,6 +843,7 @@
}
}
+ @Test
public void testInclusiveBetween_withMessage()
{
Validate.inclusiveBetween("a", "c", "b", "Error");
@@ -810,6 +857,7 @@
}
}
+ @Test
public void testExclusiveBetween()
{
Validate.exclusiveBetween("a", "c", "b");
@@ -828,6 +876,7 @@
}
}
+ @Test
public void testExclusiveBetween_withMessage()
{
Validate.exclusiveBetween("a", "c", "b", "Error");
@@ -846,11 +895,13 @@
}
}
+ @Test
public void testIsInstanceOf() {
Validate.isInstanceOf(String.class, "hi");
Validate.isInstanceOf(Integer.class, 1);
}
+ @Test
public void testIsInstanceOfExceptionMessage() {
try {
Validate.isInstanceOf(List.class, "hi");
@@ -860,6 +911,7 @@
}
}
+ @Test
public void testIsInstanceOf_withMessage() {
Validate.isInstanceOf(String.class, "hi", "Error");
Validate.isInstanceOf(Integer.class, 1, "Error");
@@ -871,11 +923,13 @@
}
}
+ @Test
public void testIsAssignable() {
Validate.isAssignableFrom(CharSequence.class, String.class);
Validate.isAssignableFrom(AbstractList.class, ArrayList.class);
}
+ @Test
public void testIsAssignableExceptionMessage() {
try {
Validate.isAssignableFrom(List.class, String.class);
@@ -885,6 +939,7 @@
}
}
+ @Test
public void testIsAssignable_withMessage() {
Validate.isAssignableFrom(CharSequence.class, String.class, "Error");
Validate.isAssignableFrom(AbstractList.class, ArrayList.class, "Error");
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java
index 4872280..f5f6301 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java
@@ -16,15 +16,15 @@
*/
package org.apache.commons.lang3.concurrent;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import junit.framework.TestCase;
-
-public class BackgroundInitializerTest extends TestCase {
+public class BackgroundInitializerTest {
/**
* Helper method for checking whether the initialize() method was correctly
* called. start() must already have been invoked.
@@ -45,6 +45,7 @@
/**
* Tests whether initialize() is invoked.
*/
+ @Test
public void testInitialize() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
init.start();
@@ -55,6 +56,7 @@
* Tries to obtain the executor before start(). It should not have been
* initialized yet.
*/
+ @Test
public void testGetActiveExecutorBeforeStart() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
assertNull("Got an executor", init.getActiveExecutor());
@@ -63,6 +65,7 @@
/**
* Tests whether an external executor is correctly detected.
*/
+ @Test
public void testGetActiveExecutorExternal() {
ExecutorService exec = Executors.newSingleThreadExecutor();
try {
@@ -79,6 +82,7 @@
/**
* Tests getActiveExecutor() for a temporary executor.
*/
+ @Test
public void testGetActiveExecutorTemp() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
init.start();
@@ -90,6 +94,7 @@
* Tests the execution of the background task if a temporary executor has to
* be created.
*/
+ @Test
public void testInitializeTempExecutor() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
assertTrue("Wrong result of start()", init.start());
@@ -102,6 +107,7 @@
* Tests whether an external executor can be set using the
* setExternalExecutor() method.
*/
+ @Test
public void testSetExternalExecutor() throws Exception {
ExecutorService exec = Executors.newCachedThreadPool();
try {
@@ -121,6 +127,7 @@
/**
* Tests that setting an executor after start() causes an exception.
*/
+ @Test
public void testSetExternalExecutorAfterStart() throws ConcurrentException {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
init.start();
@@ -136,6 +143,7 @@
* Tests invoking start() multiple times. Only the first invocation should
* have an effect.
*/
+ @Test
public void testStartMultipleTimes() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
assertTrue("Wrong result for start()", init.start());
@@ -148,6 +156,7 @@
/**
* Tests calling get() before start(). This should cause an exception.
*/
+ @Test
public void testGetBeforeStart() throws ConcurrentException {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
try {
@@ -162,6 +171,7 @@
* Tests the get() method if background processing causes a runtime
* exception.
*/
+ @Test
public void testGetRuntimeException() throws Exception {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
RuntimeException rex = new RuntimeException();
@@ -179,6 +189,7 @@
* Tests the get() method if background processing causes a checked
* exception.
*/
+ @Test
public void testGetCheckedException() throws Exception {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
Exception ex = new Exception();
@@ -195,6 +206,7 @@
/**
* Tests the get() method if waiting for the initialization is interrupted.
*/
+ @Test
public void testGetInterruptedException() throws Exception {
ExecutorService exec = Executors.newSingleThreadExecutor();
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl(
@@ -229,6 +241,7 @@
/**
* Tests isStarted() before start() was called.
*/
+ @Test
public void testIsStartedFalse() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
assertFalse("Already started", init.isStarted());
@@ -237,6 +250,7 @@
/**
* Tests isStarted() after start().
*/
+ @Test
public void testIsStartedTrue() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
init.start();
@@ -246,6 +260,7 @@
/**
* Tests isStarted() after the background task has finished.
*/
+ @Test
public void testIsStartedAfterGet() {
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
init.start();
diff --git a/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
index b0cd013..16c0425 100644
--- a/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
+++ b/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
@@ -16,18 +16,21 @@
*/
package org.apache.commons.lang3.concurrent;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Test class for {@code CallableBackgroundInitializer}
*
* @version $Id$
*/
-public class CallableBackgroundInitializerTest extends TestCase {
+public class CallableBackgroundInitializerTest {
/** Constant for the result of the call() invocation. */
private static final Integer RESULT = Integer.valueOf(42);
@@ -35,6 +38,7 @@
* Tries to create an instance without a Callable. This should cause an
* exception.
*/
+ @Test
public void testInitNullCallable() {
try {
new CallableBackgroundInitializer<Object>(null);
@@ -48,6 +52,7 @@
* Tests whether the executor service is correctly passed to the super
* class.
*/
+ @Test
public void testInitExecutor() {
ExecutorService exec = Executors.newSingleThreadExecutor();
CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<Integer>(
@@ -59,6 +64,7 @@
* Tries to pass a null Callable to the constructor that takes an executor.
* This should cause an exception.
*/
+ @Test
public void testInitExecutorNullCallable() {
ExecutorService exec = Executors.newSingleThreadExecutor();
try {
@@ -72,6 +78,7 @@
/**
* Tests the implementation of initialize().
*/
+ @Test
public void testInitialize() throws Exception {
TestCallable call = new TestCallable();
CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<Integer>(
diff --git a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java
index edb1df4..40ab464 100644
--- a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java
+++ b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java
@@ -17,6 +17,10 @@
package org.apache.commons.lang3.event;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
@@ -30,16 +34,16 @@
import java.util.Date;
import java.util.List;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
+import org.junit.Test;
/**
* @since 3.0
* @version $Id$
*/
-public class EventListenerSupportTest extends TestCase
+public class EventListenerSupportTest
{
+ @Test
public void testAddNullListener()
{
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
@@ -54,6 +58,7 @@
}
}
+ @Test
public void testRemoveNullListener()
{
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
@@ -68,6 +73,7 @@
}
}
+ @Test
public void testEventDispatchOrder() throws PropertyVetoException
{
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
@@ -83,6 +89,7 @@
assertSame(calledListeners.get(1), listener2);
}
+ @Test
public void testCreateWithNonInterfaceParameter()
{
try
@@ -96,6 +103,7 @@
}
}
+ @Test
public void testCreateWithNullParameter()
{
try
@@ -109,6 +117,7 @@
}
}
+ @Test
public void testRemoveListenerDuringEvent() throws PropertyVetoException
{
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
@@ -121,6 +130,7 @@
assertEquals(listenerSupport.getListenerCount(), 0);
}
+ @Test
public void testGetListeners() {
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
@@ -143,6 +153,7 @@
assertSame(empty, listenerSupport.getListeners());
}
+ @Test
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
listenerSupport.addListener(new VetoableChangeListener() {
@@ -183,6 +194,7 @@
assertEquals(0, deserializedListenerSupport.getListeners().length);
}
+ @Test
public void testSubclassInvocationHandling() throws PropertyVetoException {
@SuppressWarnings("serial")
diff --git a/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java b/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java
index 2f49bf8..0202555 100644
--- a/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java
@@ -16,6 +16,10 @@
*/
package org.apache.commons.lang3.event;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
@@ -30,15 +34,16 @@
import javax.naming.event.ObjectChangeListener;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* @since 3.0
* @version $Id$
*/
-public class EventUtilsTest extends TestCase
+public class EventUtilsTest
{
+ @Test
public void testConstructor() {
assertNotNull(new EventUtils());
Constructor<?>[] cons = EventUtils.class.getDeclaredConstructors();
@@ -48,6 +53,7 @@
assertEquals(false, Modifier.isFinal(EventUtils.class.getModifiers()));
}
+ @Test
public void testAddEventListener()
{
final PropertyChangeSource src = new PropertyChangeSource();
@@ -60,6 +66,7 @@
assertEquals(1, handler.getEventCount("propertyChange"));
}
+ @Test
public void testAddEventListenerWithNoAddMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
@@ -76,6 +83,7 @@
}
}
+ @Test
public void testAddEventListenerThrowsException()
{
final ExceptionEventSource src = new ExceptionEventSource();
@@ -97,6 +105,7 @@
}
}
+ @Test
public void testAddEventListenerWithPrivateAddMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
@@ -113,6 +122,7 @@
}
}
+ @Test
public void testBindEventsToMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
@@ -124,6 +134,7 @@
}
+ @Test
public void testBindEventsToMethodWithEvent()
{
final PropertyChangeSource src = new PropertyChangeSource();
@@ -135,6 +146,7 @@
}
+ @Test
public void testBindFilteredEventsToMethod()
{
final MultipleEventSource src = new MultipleEventSource();
diff --git a/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java b/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java
index 3c964b2..457de71 100644
--- a/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.commons.lang3.exception;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
@@ -23,8 +26,6 @@
import java.util.List;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.tuple.Pair;
@@ -32,7 +33,7 @@
/**
* Abstract test of an ExceptionContext implementation.
*/
-public abstract class AbstractExceptionContextTest<T extends ExceptionContext & Serializable> extends TestCase {
+public abstract class AbstractExceptionContextTest<T extends ExceptionContext & Serializable> {
protected static final String TEST_MESSAGE_2 = "This is monotonous";
protected static final String TEST_MESSAGE = "Test Message";
@@ -45,8 +46,9 @@
}
}
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
exceptionContext
.addContextValue("test1", null)
.addContextValue("test2", "some value")
@@ -55,6 +57,7 @@
.addContextValue("test Poorly written obj", new ObjectWithFaultyToString());
}
+ @Test
public void testAddContextValue() {
String message = exceptionContext.getFormattedExceptionMessage(TEST_MESSAGE);
assertTrue(message.indexOf(TEST_MESSAGE) >= 0);
@@ -82,6 +85,7 @@
assertTrue(contextMessage.indexOf(TEST_MESSAGE) == -1);
}
+ @Test
public void testSetContextValue() {
exceptionContext.addContextValue("test2", "different value");
exceptionContext.setContextValue("test3", "3");
@@ -114,6 +118,7 @@
assertTrue(contextMessage.indexOf(TEST_MESSAGE) == -1);
}
+ @Test
public void testGetFirstContextValue() {
exceptionContext.addContextValue("test2", "different value");
@@ -126,6 +131,7 @@
assertTrue(exceptionContext.getFirstContextValue("test2").equals("another"));
}
+ @Test
public void testGetContextValues() {
exceptionContext.addContextValue("test2", "different value");
@@ -137,6 +143,7 @@
assertTrue(exceptionContext.getFirstContextValue("test2").equals("another"));
}
+ @Test
public void testGetContextLabels() {
assertEquals(5, exceptionContext.getContextEntries().size());
@@ -151,6 +158,7 @@
assertTrue(labels.contains("test Nbr"));
}
+ @Test
public void testGetContextEntries() {
assertEquals(5, exceptionContext.getContextEntries().size());
@@ -166,6 +174,7 @@
assertEquals("test2", entries.get(5).getKey());
}
+ @Test
public void testJavaSerialization() {
exceptionContext.setContextValue("test Poorly written obj", "serializable replacement");
diff --git a/src/test/java/org/apache/commons/lang3/exception/ContextedExceptionTest.java b/src/test/java/org/apache/commons/lang3/exception/ContextedExceptionTest.java
index 4a7c5ad..ac54000 100644
--- a/src/test/java/org/apache/commons/lang3/exception/ContextedExceptionTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/ContextedExceptionTest.java
@@ -16,9 +16,14 @@
*/
package org.apache.commons.lang3.exception;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
/**
* JUnit tests for ContextedException.
@@ -31,6 +36,7 @@
super.setUp();
}
+ @Test
public void testContextedException() {
exceptionContext = new ContextedException();
String message = exceptionContext.getMessage();
@@ -39,6 +45,7 @@
assertTrue(StringUtils.isEmpty(message));
}
+ @Test
public void testContextedExceptionString() {
exceptionContext = new ContextedException(TEST_MESSAGE);
assertEquals(TEST_MESSAGE, exceptionContext.getMessage());
@@ -47,6 +54,7 @@
assertTrue(trace.indexOf(TEST_MESSAGE)>=0);
}
+ @Test
public void testContextedExceptionThrowable() {
exceptionContext = new ContextedException(new Exception(TEST_MESSAGE));
String message = exceptionContext.getMessage();
@@ -56,6 +64,7 @@
assertTrue(message.indexOf(TEST_MESSAGE)>=0);
}
+ @Test
public void testContextedExceptionStringThrowable() {
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE));
String message = exceptionContext.getMessage();
@@ -66,6 +75,7 @@
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
}
+ @Test
public void testContextedExceptionStringThrowableContext() {
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext());
String message = exceptionContext.getMessage();
@@ -76,6 +86,7 @@
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
}
+ @Test
public void testNullExceptionPassing() {
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), null)
.addContextValue("test1", null)
@@ -88,6 +99,7 @@
assertTrue(message != null);
}
+ @Test
public void testRawMessage() {
assertEquals(Exception.class.getName() + ": " + TEST_MESSAGE, exceptionContext.getRawMessage());
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext());
diff --git a/src/test/java/org/apache/commons/lang3/exception/ContextedRuntimeExceptionTest.java b/src/test/java/org/apache/commons/lang3/exception/ContextedRuntimeExceptionTest.java
index 0843a28..ee3f0b0 100644
--- a/src/test/java/org/apache/commons/lang3/exception/ContextedRuntimeExceptionTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/ContextedRuntimeExceptionTest.java
@@ -16,21 +16,28 @@
*/
package org.apache.commons.lang3.exception;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
+import org.junit.Before;
+import org.junit.Test;
/**
* JUnit tests for ContextedRuntimeException.
*/
public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<ContextedRuntimeException> {
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
exceptionContext = new ContextedRuntimeException(new Exception(TEST_MESSAGE));
super.setUp();
}
+ @Test
public void testContextedException() {
exceptionContext = new ContextedRuntimeException();
String message = exceptionContext.getMessage();
@@ -39,6 +46,7 @@
assertTrue(StringUtils.isEmpty(message));
}
+ @Test
public void testContextedExceptionString() {
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE);
assertEquals(TEST_MESSAGE, exceptionContext.getMessage());
@@ -47,6 +55,7 @@
assertTrue(trace.indexOf(TEST_MESSAGE)>=0);
}
+ @Test
public void testContextedExceptionThrowable() {
exceptionContext = new ContextedRuntimeException(new Exception(TEST_MESSAGE));
String message = exceptionContext.getMessage();
@@ -56,6 +65,7 @@
assertTrue(message.indexOf(TEST_MESSAGE)>=0);
}
+ @Test
public void testContextedExceptionStringThrowable() {
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE));
String message = exceptionContext.getMessage();
@@ -66,6 +76,7 @@
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
}
+ @Test
public void testContextedExceptionStringThrowableContext() {
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext() {});
String message = exceptionContext.getMessage();
@@ -76,6 +87,7 @@
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
}
+ @Test
public void testNullExceptionPassing() {
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), null)
.addContextValue("test1", null)
@@ -88,6 +100,7 @@
assertTrue(message != null);
}
+ @Test
public void testRawMessage() {
assertEquals(Exception.class.getName() + ": " + TEST_MESSAGE, exceptionContext.getRawMessage());
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext());
diff --git a/src/test/java/org/apache/commons/lang3/exception/DefaultExceptionContextTest.java b/src/test/java/org/apache/commons/lang3/exception/DefaultExceptionContextTest.java
index 4caef7a..cfae13c 100644
--- a/src/test/java/org/apache/commons/lang3/exception/DefaultExceptionContextTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/DefaultExceptionContextTest.java
@@ -16,18 +16,22 @@
*/
package org.apache.commons.lang3.exception;
+import org.junit.Before;
+import org.junit.Test;
+
/**
* JUnit tests for DefaultExceptionContext.
*
*/
public class DefaultExceptionContextTest extends AbstractExceptionContextTest<DefaultExceptionContext> {
- @Override
+ @Before
public void setUp() throws Exception {
exceptionContext = new DefaultExceptionContext();
super.setUp();
}
+ @Test
public void testFormattedExceptionMessageNull() {
exceptionContext = new DefaultExceptionContext();
exceptionContext.getFormattedExceptionMessage(null);
diff --git a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
index 370ff58..30af506 100644
--- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
@@ -16,6 +16,10 @@
*/
package org.apache.commons.lang3.exception;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -24,8 +28,6 @@
import java.lang.reflect.Modifier;
import java.util.List;
-import junit.framework.TestCase;
-
/**
* Tests {@link org.apache.commons.lang3.exception.ExceptionUtils}.
*
@@ -47,7 +49,7 @@
*
* @since 1.0
*/
-public class ExceptionUtilsTest extends TestCase {
+public class ExceptionUtilsTest {
private NestableException nested;
private Throwable withCause;
@@ -55,11 +57,8 @@
private Throwable jdkNoCause;
private ExceptionWithCause cyclicCause;
- public ExceptionUtilsTest(String name) {
- super(name);
- }
- @Override
+ @Before
public void setUp() {
withoutCause = createExceptionWithoutCause();
nested = new NestableException(withoutCause);
@@ -71,8 +70,9 @@
cyclicCause = new ExceptionWithCause(a);
}
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
withoutCause = null;
nested = null;
withCause = null;
@@ -103,6 +103,7 @@
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new ExceptionUtils());
Constructor<?>[] cons = ExceptionUtils.class.getDeclaredConstructors();
@@ -114,6 +115,7 @@
//-----------------------------------------------------------------------
@SuppressWarnings("deprecation") // Specifically tests the deprecated methods
+ @Test
public void testGetCause_Throwable() {
assertSame(null, ExceptionUtils.getCause(null));
assertSame(null, ExceptionUtils.getCause(withoutCause));
@@ -126,6 +128,7 @@
}
@SuppressWarnings("deprecation") // Specifically tests the deprecated methods
+ @Test
public void testGetCause_ThrowableArray() {
assertSame(null, ExceptionUtils.getCause(null, null));
assertSame(null, ExceptionUtils.getCause(null, new String[0]));
@@ -144,6 +147,7 @@
assertSame(null, ExceptionUtils.getCause(withoutCause, new String[] {"getTargetException"}));
}
+ @Test
public void testGetRootCause_Throwable() {
assertSame(null, ExceptionUtils.getRootCause(null));
assertSame(null, ExceptionUtils.getRootCause(withoutCause));
@@ -154,6 +158,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetThrowableCount_Throwable() {
assertEquals(0, ExceptionUtils.getThrowableCount(null));
assertEquals(1, ExceptionUtils.getThrowableCount(withoutCause));
@@ -164,16 +169,19 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetThrowables_Throwable_null() {
assertEquals(0, ExceptionUtils.getThrowables(null).length);
}
+ @Test
public void testGetThrowables_Throwable_withoutCause() {
Throwable[] throwables = ExceptionUtils.getThrowables(withoutCause);
assertEquals(1, throwables.length);
assertSame(withoutCause, throwables[0]);
}
+ @Test
public void testGetThrowables_Throwable_nested() {
Throwable[] throwables = ExceptionUtils.getThrowables(nested);
assertEquals(2, throwables.length);
@@ -181,6 +189,7 @@
assertSame(withoutCause, throwables[1]);
}
+ @Test
public void testGetThrowables_Throwable_withCause() {
Throwable[] throwables = ExceptionUtils.getThrowables(withCause);
assertEquals(3, throwables.length);
@@ -189,12 +198,14 @@
assertSame(withoutCause, throwables[2]);
}
+ @Test
public void testGetThrowables_Throwable_jdkNoCause() {
Throwable[] throwables = ExceptionUtils.getThrowables(jdkNoCause);
assertEquals(1, throwables.length);
assertSame(jdkNoCause, throwables[0]);
}
+ @Test
public void testGetThrowables_Throwable_recursiveCause() {
Throwable[] throwables = ExceptionUtils.getThrowables(cyclicCause);
assertEquals(3, throwables.length);
@@ -204,17 +215,20 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetThrowableList_Throwable_null() {
List<?> throwables = ExceptionUtils.getThrowableList(null);
assertEquals(0, throwables.size());
}
+ @Test
public void testGetThrowableList_Throwable_withoutCause() {
List<?> throwables = ExceptionUtils.getThrowableList(withoutCause);
assertEquals(1, throwables.size());
assertSame(withoutCause, throwables.get(0));
}
+ @Test
public void testGetThrowableList_Throwable_nested() {
List<?> throwables = ExceptionUtils.getThrowableList(nested);
assertEquals(2, throwables.size());
@@ -222,6 +236,7 @@
assertSame(withoutCause, throwables.get(1));
}
+ @Test
public void testGetThrowableList_Throwable_withCause() {
List<?> throwables = ExceptionUtils.getThrowableList(withCause);
assertEquals(3, throwables.size());
@@ -230,12 +245,14 @@
assertSame(withoutCause, throwables.get(2));
}
+ @Test
public void testGetThrowableList_Throwable_jdkNoCause() {
List<?> throwables = ExceptionUtils.getThrowableList(jdkNoCause);
assertEquals(1, throwables.size());
assertSame(jdkNoCause, throwables.get(0));
}
+ @Test
public void testGetThrowableList_Throwable_recursiveCause() {
List<?> throwables = ExceptionUtils.getThrowableList(cyclicCause);
assertEquals(3, throwables.size());
@@ -245,6 +262,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOf_ThrowableClass() {
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, null));
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, NestableException.class));
@@ -267,6 +285,7 @@
assertEquals(-1, ExceptionUtils.indexOfThrowable(withCause, Exception.class));
}
+ @Test
public void testIndexOf_ThrowableClassInt() {
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, null, 0));
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, NestableException.class, 0));
@@ -295,6 +314,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIndexOfType_ThrowableClass() {
assertEquals(-1, ExceptionUtils.indexOfType(null, null));
assertEquals(-1, ExceptionUtils.indexOfType(null, NestableException.class));
@@ -317,6 +337,7 @@
assertEquals(0, ExceptionUtils.indexOfType(withCause, Exception.class));
}
+ @Test
public void testIndexOfType_ThrowableClassInt() {
assertEquals(-1, ExceptionUtils.indexOfType(null, null, 0));
assertEquals(-1, ExceptionUtils.indexOfType(null, NestableException.class, 0));
@@ -345,12 +366,14 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testPrintRootCauseStackTrace_Throwable() throws Exception {
ExceptionUtils.printRootCauseStackTrace(null);
// could pipe system.err to a known stream, but not much point as
// internally this method calls stram method anyway
}
+ @Test
public void testPrintRootCauseStackTrace_ThrowableStream() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
ExceptionUtils.printRootCauseStackTrace(null, (PrintStream) null);
@@ -376,6 +399,7 @@
assertTrue(stackTrace.indexOf(ExceptionUtils.WRAPPED_MARKER) == -1);
}
+ @Test
public void testPrintRootCauseStackTrace_ThrowableWriter() throws Exception {
StringWriter writer = new StringWriter(1024);
ExceptionUtils.printRootCauseStackTrace(null, (PrintWriter) null);
@@ -402,6 +426,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetRootCauseStackTrace_Throwable() throws Exception {
assertEquals(0, ExceptionUtils.getRootCauseStackTrace(null).length);
@@ -427,6 +452,7 @@
assertEquals(false, match);
}
+ @Test
public void testRemoveCommonFrames_ListList() throws Exception {
try {
ExceptionUtils.removeCommonFrames(null, null);
@@ -435,6 +461,7 @@
}
}
+ @Test
public void test_getMessage_Throwable() {
Throwable th = null;
assertEquals("", ExceptionUtils.getMessage(th));
@@ -446,6 +473,7 @@
assertEquals("ExceptionUtilsTest.ExceptionWithCause: Wrapper", ExceptionUtils.getMessage(th));
}
+ @Test
public void test_getRootCauseMessage_Throwable() {
Throwable th = null;
assertEquals("", ExceptionUtils.getRootCauseMessage(th));
diff --git a/src/test/java/org/apache/commons/lang3/math/FractionTest.java b/src/test/java/org/apache/commons/lang3/math/FractionTest.java
index 38d7772..64c3adb 100644
--- a/src/test/java/org/apache/commons/lang3/math/FractionTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/FractionTest.java
@@ -18,23 +18,25 @@
*/
package org.apache.commons.lang3.math;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* Test cases for the {@link Fraction} class
*
* @version $Id$
*/
-public class FractionTest extends TestCase {
+public class FractionTest {
private static final int SKIP = 500; //53
- public FractionTest(String name) {
- super(name);
- }
-
//--------------------------------------------------------------------------
-
+ @Test
public void testConstants() {
assertEquals(0, Fraction.ZERO.getNumerator());
assertEquals(1, Fraction.ZERO.getDenominator());
@@ -73,6 +75,7 @@
assertEquals(5, Fraction.FOUR_FIFTHS.getDenominator());
}
+ @Test
public void testFactory_int_int() {
Fraction f = null;
@@ -143,6 +146,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testFactory_int_int_int() {
Fraction f = null;
@@ -245,6 +249,7 @@
fail("expecting ArithmeticException");
} catch (ArithmeticException ex) {}
}
+ @Test
public void testReducedFactory_int_int() {
Fraction f = null;
@@ -335,6 +340,7 @@
assertEquals(1, f.getDenominator());
}
+ @Test
public void testFactory_double() {
Fraction f = null;
@@ -424,6 +430,7 @@
}
}
+ @Test
public void testFactory_String() {
try {
Fraction.getFraction(null);
@@ -432,6 +439,7 @@
}
+ @Test
public void testFactory_String_double() {
Fraction f = null;
@@ -467,6 +475,7 @@
} catch (NumberFormatException ex) {}
}
+ @Test
public void testFactory_String_proper() {
Fraction f = null;
@@ -525,6 +534,7 @@
} catch (NumberFormatException ex) {}
}
+ @Test
public void testFactory_String_improper() {
Fraction f = null;
@@ -573,6 +583,7 @@
} catch (NumberFormatException ex) {}
}
+ @Test
public void testGets() {
Fraction f = null;
@@ -595,6 +606,7 @@
assertEquals(1, f.getDenominator());
}
+ @Test
public void testConversions() {
Fraction f = null;
@@ -605,6 +617,7 @@
assertEquals(3.875d, f.doubleValue(), 0.00001d);
}
+ @Test
public void testReduce() {
Fraction f = null;
@@ -653,6 +666,7 @@
assertEquals(1, result.getDenominator());
}
+ @Test
public void testInvert() {
Fraction f = null;
@@ -690,6 +704,7 @@
assertEquals(Integer.MAX_VALUE, f.getDenominator());
}
+ @Test
public void testNegate() {
Fraction f = null;
@@ -716,6 +731,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testAbs() {
Fraction f = null;
@@ -746,6 +762,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testPow() {
Fraction f = null;
@@ -858,6 +875,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testAdd() {
Fraction f = null;
Fraction f1 = null;
@@ -976,6 +994,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testSubtract() {
Fraction f = null;
Fraction f1 = null;
@@ -1088,6 +1107,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testMultiply() {
Fraction f = null;
Fraction f1 = null;
@@ -1156,6 +1176,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testDivide() {
Fraction f = null;
Fraction f1 = null;
@@ -1213,6 +1234,7 @@
} catch (ArithmeticException ex) {}
}
+ @Test
public void testEquals() {
Fraction f1 = null;
Fraction f2 = null;
@@ -1235,6 +1257,7 @@
assertEquals(false, f1.equals(f2));
}
+ @Test
public void testHashCode() {
Fraction f1 = Fraction.getFraction(3, 5);
Fraction f2 = Fraction.getFraction(3, 5);
@@ -1248,6 +1271,7 @@
assertTrue(f1.hashCode() != f2.hashCode());
}
+ @Test
public void testCompareTo() {
Fraction f1 = null;
Fraction f2 = null;
@@ -1282,6 +1306,7 @@
}
+ @Test
public void testToString() {
Fraction f = null;
@@ -1309,6 +1334,7 @@
assertEquals("-2147483648/2147483647", f.toString());
}
+ @Test
public void testToProperString() {
Fraction f = null;
diff --git a/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java
index 9c5d9e4..8fbccfa 100644
--- a/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/IEEE754rUtilsTest.java
@@ -16,15 +16,20 @@
*/
package org.apache.commons.lang3.math;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* Unit tests {@link org.apache.commons.lang3.math.IEEE754rUtils}.
*
* @version $Id$
*/
-public class IEEE754rUtilsTest extends TestCase {
+public class IEEE754rUtilsTest {
+ @Test
public void testLang381() {
assertEquals(1.2, IEEE754rUtils.min(1.2, 2.5, Double.NaN), 0.01);
assertEquals(2.5, IEEE754rUtils.max(1.2, 2.5, Double.NaN), 0.01);
@@ -50,6 +55,7 @@
assertEquals(42.0f, IEEE754rUtils.max(bF), 0.01);
}
+ @Test
public void testEnforceExceptions() {
try {
IEEE754rUtils.min( (float[]) null);
@@ -93,6 +99,7 @@
}
+ @Test
public void testConstructorExists() {
new IEEE754rUtils();
}
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java
index f1ac8e0..8370512 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java
@@ -17,7 +17,8 @@
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -26,12 +27,9 @@
* @see MutableBoolean
* @version $Id$
*/
-public class MutableBooleanTest extends TestCase {
+public class MutableBooleanTest {
- public MutableBooleanTest(String testName) {
- super(testName);
- }
-
+ @Test
public void testCompareTo() {
final MutableBoolean mutBool = new MutableBoolean(false);
@@ -49,6 +47,7 @@
}
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals(false, new MutableBoolean().booleanValue());
@@ -65,6 +64,7 @@
}
}
+ @Test
public void testEquals() {
final MutableBoolean mutBoolA = new MutableBoolean(false);
final MutableBoolean mutBoolB = new MutableBoolean(false);
@@ -82,6 +82,7 @@
assertEquals(false, mutBoolA.equals("false"));
}
+ @Test
public void testGetSet() {
assertEquals(false, new MutableBoolean().booleanValue());
assertEquals(Boolean.FALSE, new MutableBoolean().getValue());
@@ -111,6 +112,7 @@
}
}
+ @Test
public void testHashCode() {
final MutableBoolean mutBoolA = new MutableBoolean(false);
final MutableBoolean mutBoolB = new MutableBoolean(false);
@@ -123,6 +125,7 @@
assertEquals(true, mutBoolC.hashCode() == Boolean.TRUE.hashCode());
}
+ @Test
public void testToString() {
assertEquals(Boolean.FALSE.toString(), new MutableBoolean(false).toString());
assertEquals(Boolean.TRUE.toString(), new MutableBoolean(true).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java
index ce5d93b..b156d1a 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableByte
*/
-public class MutableByteTest extends TestCase {
-
- public MutableByteTest(String testName) {
- super(testName);
- }
+public class MutableByteTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals((byte) 0, new MutableByte().byteValue());
@@ -47,6 +45,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableByte mutNum = new MutableByte((byte) 0);
assertEquals((byte) 0, new MutableByte().byteValue());
@@ -69,6 +68,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testEquals() {
final MutableByte mutNumA = new MutableByte((byte) 0);
final MutableByte mutNumB = new MutableByte((byte) 0);
@@ -86,6 +86,7 @@
assertEquals(false, mutNumA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableByte mutNumA = new MutableByte((byte) 0);
final MutableByte mutNumB = new MutableByte((byte) 0);
@@ -97,6 +98,7 @@
assertEquals(true, mutNumA.hashCode() == Byte.valueOf((byte) 0).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableByte mutNum = new MutableByte((byte) 0);
@@ -109,6 +111,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableByte mutNum = new MutableByte( (byte) 1 );
@@ -120,11 +123,13 @@
assertEquals( 1L, mutNum.longValue() );
}
+ @Test
public void testToByte() {
assertEquals(Byte.valueOf((byte) 0), new MutableByte((byte) 0).toByte());
assertEquals(Byte.valueOf((byte) 123), new MutableByte((byte) 123).toByte());
}
+ @Test
public void testIncrement() {
MutableByte mutNum = new MutableByte((byte) 1);
mutNum.increment();
@@ -133,6 +138,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableByte mutNum = new MutableByte((byte) 1);
mutNum.decrement();
@@ -141,6 +147,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableByte mutNum = new MutableByte((byte) 1);
mutNum.add((byte)1);
@@ -148,6 +155,7 @@
assertEquals((byte) 2, mutNum.byteValue());
}
+ @Test
public void testAddValueObject() {
MutableByte mutNum = new MutableByte((byte) 1);
mutNum.add(Integer.valueOf(1));
@@ -155,6 +163,7 @@
assertEquals((byte) 2, mutNum.byteValue());
}
+ @Test
public void testSubtractValuePrimitive() {
MutableByte mutNum = new MutableByte((byte) 1);
mutNum.subtract((byte) 1);
@@ -162,6 +171,7 @@
assertEquals((byte) 0, mutNum.byteValue());
}
+ @Test
public void testSubtractValueObject() {
MutableByte mutNum = new MutableByte((byte) 1);
mutNum.subtract(Integer.valueOf(1));
@@ -169,6 +179,7 @@
assertEquals((byte) 0, mutNum.byteValue());
}
+ @Test
public void testToString() {
assertEquals("0", new MutableByte((byte) 0).toString());
assertEquals("10", new MutableByte((byte) 10).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java
index e2cfb11..d685182 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableDouble
*/
-public class MutableDoubleTest extends TestCase {
-
- public MutableDoubleTest(String testName) {
- super(testName);
- }
+public class MutableDoubleTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals(0d, new MutableDouble().doubleValue(), 0.0001d);
@@ -47,6 +45,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableDouble mutNum = new MutableDouble(0d);
assertEquals(0d, new MutableDouble().doubleValue(), 0.0001d);
@@ -69,6 +68,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testNanInfinite() {
MutableDouble mutNum = new MutableDouble(Double.NaN);
assertEquals(true, mutNum.isNaN());
@@ -80,6 +80,7 @@
assertEquals(true, mutNum.isInfinite());
}
+ @Test
public void testEquals() {
final MutableDouble mutNumA = new MutableDouble(0d);
final MutableDouble mutNumB = new MutableDouble(0d);
@@ -97,6 +98,7 @@
assertEquals(false, mutNumA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableDouble mutNumA = new MutableDouble(0d);
final MutableDouble mutNumB = new MutableDouble(0d);
@@ -108,6 +110,7 @@
assertEquals(true, mutNumA.hashCode() == Double.valueOf(0d).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableDouble mutNum = new MutableDouble(0d);
@@ -120,6 +123,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableDouble mutNum = new MutableDouble(1.7);
@@ -131,11 +135,13 @@
assertEquals( 1L, mutNum.longValue() );
}
+ @Test
public void testToDouble() {
assertEquals(Double.valueOf(0d), new MutableDouble(0d).toDouble());
assertEquals(Double.valueOf(12.3d), new MutableDouble(12.3d).toDouble());
}
+ @Test
public void testIncrement() {
MutableDouble mutNum = new MutableDouble(1);
mutNum.increment();
@@ -144,6 +150,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableDouble mutNum = new MutableDouble(1);
mutNum.decrement();
@@ -152,6 +159,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableDouble mutNum = new MutableDouble(1);
mutNum.add(1.1d);
@@ -159,6 +167,7 @@
assertEquals(2.1d, mutNum.doubleValue(), 0.01d);
}
+ @Test
public void testAddValueObject() {
MutableDouble mutNum = new MutableDouble(1);
mutNum.add(Double.valueOf(1.1d));
@@ -166,6 +175,7 @@
assertEquals(2.1d, mutNum.doubleValue(), 0.01d);
}
+ @Test
public void testSubtractValuePrimitive() {
MutableDouble mutNum = new MutableDouble(1);
mutNum.subtract(0.9d);
@@ -173,6 +183,7 @@
assertEquals(0.1d, mutNum.doubleValue(), 0.01d);
}
+ @Test
public void testSubtractValueObject() {
MutableDouble mutNum = new MutableDouble(1);
mutNum.subtract(Double.valueOf(0.9d));
@@ -180,6 +191,7 @@
assertEquals(0.1d, mutNum.doubleValue(), 0.01d);
}
+ @Test
public void testToString() {
assertEquals("0.0", new MutableDouble(0d).toString());
assertEquals("10.0", new MutableDouble(10d).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java
index 000bcf0..2598482 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableFloat
*/
-public class MutableFloatTest extends TestCase {
-
- public MutableFloatTest(String testName) {
- super(testName);
- }
+public class MutableFloatTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals(0f, new MutableFloat().floatValue(), 0.0001f);
@@ -47,6 +45,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableFloat mutNum = new MutableFloat(0f);
assertEquals(0f, new MutableFloat().floatValue(), 0.0001f);
@@ -69,6 +68,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testNanInfinite() {
MutableFloat mutNum = new MutableFloat(Float.NaN);
assertEquals(true, mutNum.isNaN());
@@ -80,6 +80,7 @@
assertEquals(true, mutNum.isInfinite());
}
+ @Test
public void testEquals() {
final MutableFloat mutNumA = new MutableFloat(0f);
final MutableFloat mutNumB = new MutableFloat(0f);
@@ -97,6 +98,7 @@
assertEquals(false, mutNumA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableFloat mutNumA = new MutableFloat(0f);
final MutableFloat mutNumB = new MutableFloat(0f);
@@ -108,6 +110,7 @@
assertEquals(true, mutNumA.hashCode() == Float.valueOf(0f).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableFloat mutNum = new MutableFloat(0f);
@@ -120,6 +123,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableFloat mutNum = new MutableFloat(1.7F);
@@ -131,11 +135,13 @@
assertEquals( 1L, mutNum.longValue() );
}
+ @Test
public void testToFloat() {
assertEquals(Float.valueOf(0f), new MutableFloat(0f).toFloat());
assertEquals(Float.valueOf(12.3f), new MutableFloat(12.3f).toFloat());
}
+ @Test
public void testIncrement() {
MutableFloat mutNum = new MutableFloat(1);
mutNum.increment();
@@ -144,6 +150,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableFloat mutNum = new MutableFloat(1);
mutNum.decrement();
@@ -152,6 +159,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableFloat mutNum = new MutableFloat(1);
mutNum.add(1.1f);
@@ -159,6 +167,7 @@
assertEquals(2.1f, mutNum.floatValue(), 0.01f);
}
+ @Test
public void testAddValueObject() {
MutableFloat mutNum = new MutableFloat(1);
mutNum.add(Float.valueOf(1.1f));
@@ -166,6 +175,7 @@
assertEquals(2.1f, mutNum.floatValue(), 0.01f);
}
+ @Test
public void testSubtractValuePrimitive() {
MutableFloat mutNum = new MutableFloat(1);
mutNum.subtract(0.9f);
@@ -173,6 +183,7 @@
assertEquals(0.1f, mutNum.floatValue(), 0.01f);
}
+ @Test
public void testSubtractValueObject() {
MutableFloat mutNum = new MutableFloat(1);
mutNum.subtract(Float.valueOf(0.9f));
@@ -180,6 +191,7 @@
assertEquals(0.1f, mutNum.floatValue(), 0.01f);
}
+ @Test
public void testToString() {
assertEquals("0.0", new MutableFloat(0f).toString());
assertEquals("10.0", new MutableFloat(10f).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java
index 151e764..93c9f94 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableInt
*/
-public class MutableIntTest extends TestCase {
-
- public MutableIntTest(String testName) {
- super(testName);
- }
+public class MutableIntTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals(0, new MutableInt().intValue());
@@ -47,6 +45,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableInt mutNum = new MutableInt(0);
assertEquals(0, new MutableInt().intValue());
@@ -69,6 +68,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testEquals() {
this.testEquals(new MutableInt(0), new MutableInt(0), new MutableInt(1));
// Should Numbers be supported? GaryG July-21-2005.
@@ -93,6 +93,7 @@
assertEquals(false, numA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableInt mutNumA = new MutableInt(0);
final MutableInt mutNumB = new MutableInt(0);
@@ -104,6 +105,7 @@
assertEquals(true, mutNumA.hashCode() == Integer.valueOf(0).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableInt mutNum = new MutableInt(0);
@@ -116,6 +118,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableInt mutNum = new MutableInt(1);
@@ -126,11 +129,13 @@
assertEquals( 1L, mutNum.longValue() );
}
+ @Test
public void testToInteger() {
assertEquals(Integer.valueOf(0), new MutableInt(0).toInteger());
assertEquals(Integer.valueOf(123), new MutableInt(123).toInteger());
}
+ @Test
public void testIncrement() {
MutableInt mutNum = new MutableInt(1);
mutNum.increment();
@@ -139,6 +144,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableInt mutNum = new MutableInt(1);
mutNum.decrement();
@@ -147,6 +153,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableInt mutNum = new MutableInt(1);
mutNum.add(1);
@@ -155,6 +162,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testAddValueObject() {
MutableInt mutNum = new MutableInt(1);
mutNum.add(Integer.valueOf(1));
@@ -163,6 +171,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testSubtractValuePrimitive() {
MutableInt mutNum = new MutableInt(1);
mutNum.subtract(1);
@@ -171,6 +180,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testSubtractValueObject() {
MutableInt mutNum = new MutableInt(1);
mutNum.subtract(Integer.valueOf(1));
@@ -179,6 +189,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testToString() {
assertEquals("0", new MutableInt(0).toString());
assertEquals("10", new MutableInt(10).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java
index 278f991..eec7e1e 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableLong
*/
-public class MutableLongTest extends TestCase {
-
- public MutableLongTest(String testName) {
- super(testName);
- }
+public class MutableLongTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals(0, new MutableLong().longValue());
@@ -47,6 +45,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableLong mutNum = new MutableLong(0);
assertEquals(0, new MutableLong().longValue());
@@ -69,6 +68,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testEquals() {
final MutableLong mutNumA = new MutableLong(0);
final MutableLong mutNumB = new MutableLong(0);
@@ -86,6 +86,7 @@
assertEquals(false, mutNumA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableLong mutNumA = new MutableLong(0);
final MutableLong mutNumB = new MutableLong(0);
@@ -97,6 +98,7 @@
assertEquals(true, mutNumA.hashCode() == Long.valueOf(0).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableLong mutNum = new MutableLong(0);
@@ -109,6 +111,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableLong mutNum = new MutableLong(1L);
@@ -120,11 +123,13 @@
assertEquals( 1L, mutNum.longValue() );
}
+ @Test
public void testToLong() {
assertEquals(Long.valueOf(0L), new MutableLong(0L).toLong());
assertEquals(Long.valueOf(123L), new MutableLong(123L).toLong());
}
+ @Test
public void testIncrement() {
MutableLong mutNum = new MutableLong(1);
mutNum.increment();
@@ -133,6 +138,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableLong mutNum = new MutableLong(1);
mutNum.decrement();
@@ -141,6 +147,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableLong mutNum = new MutableLong(1);
mutNum.add(1);
@@ -149,6 +156,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testAddValueObject() {
MutableLong mutNum = new MutableLong(1);
mutNum.add(Long.valueOf(1));
@@ -157,6 +165,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testSubtractValuePrimitive() {
MutableLong mutNum = new MutableLong(1);
mutNum.subtract(1);
@@ -165,6 +174,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testSubtractValueObject() {
MutableLong mutNum = new MutableLong(1);
mutNum.subtract(Long.valueOf(1));
@@ -173,6 +183,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testToString() {
assertEquals("0", new MutableLong(0).toString());
assertEquals("10", new MutableLong(10).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java
index d9f2393..a6b4990 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableShort
*/
-public class MutableObjectTest extends TestCase {
-
- public MutableObjectTest(String testName) {
- super(testName);
- }
+public class MutableObjectTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals(null, new MutableObject<String>().getValue());
@@ -40,6 +38,7 @@
assertSame(null, new MutableObject<Object>(null).getValue());
}
+ @Test
public void testGetSet() {
final MutableObject<String> mutNum = new MutableObject<String>();
assertEquals(null, new MutableObject<Object>().getValue());
@@ -51,6 +50,7 @@
assertSame(null, mutNum.getValue());
}
+ @Test
public void testEquals() {
final MutableObject<String> mutNumA = new MutableObject<String>("ALPHA");
final MutableObject<String> mutNumB = new MutableObject<String>("ALPHA");
@@ -72,6 +72,7 @@
assertEquals(false, mutNumA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableObject<String> mutNumA = new MutableObject<String>("ALPHA");
final MutableObject<String> mutNumB = new MutableObject<String>("ALPHA");
@@ -86,6 +87,7 @@
assertEquals(0, mutNumD.hashCode());
}
+ @Test
public void testToString() {
assertEquals("HI", new MutableObject<String>("HI").toString());
assertEquals("10.0", new MutableObject<Double>(Double.valueOf(10)).toString());
diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
index 4470341..7e30e50 100644
--- a/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
+++ b/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.lang3.mutable;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* JUnit tests.
@@ -24,13 +25,10 @@
* @version $Id$
* @see MutableShort
*/
-public class MutableShortTest extends TestCase {
-
- public MutableShortTest(String testName) {
- super(testName);
- }
+public class MutableShortTest {
// ----------------------------------------------------------------
+ @Test
public void testConstructors() {
assertEquals((short) 0, new MutableShort().shortValue());
@@ -47,6 +45,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableShort mutNum = new MutableShort((short) 0);
assertEquals((short) 0, new MutableShort().shortValue());
@@ -69,6 +68,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testEquals() {
final MutableShort mutNumA = new MutableShort((short) 0);
final MutableShort mutNumB = new MutableShort((short) 0);
@@ -86,6 +86,7 @@
assertEquals(false, mutNumA.equals("0"));
}
+ @Test
public void testHashCode() {
final MutableShort mutNumA = new MutableShort((short) 0);
final MutableShort mutNumB = new MutableShort((short) 0);
@@ -97,6 +98,7 @@
assertEquals(true, mutNumA.hashCode() == Short.valueOf((short) 0).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableShort mutNum = new MutableShort((short) 0);
@@ -109,6 +111,7 @@
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableShort mutNum = new MutableShort( (short) 1 );
@@ -120,11 +123,13 @@
assertEquals( 1L, mutNum.longValue() );
}
+ @Test
public void testToShort() {
assertEquals(Short.valueOf((short) 0), new MutableShort((short) 0).toShort());
assertEquals(Short.valueOf((short) 123), new MutableShort((short) 123).toShort());
}
+ @Test
public void testIncrement() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.increment();
@@ -133,6 +138,7 @@
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.decrement();
@@ -141,6 +147,7 @@
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.add((short) 1);
@@ -148,6 +155,7 @@
assertEquals((short) 2, mutNum.shortValue());
}
+ @Test
public void testAddValueObject() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.add(Short.valueOf((short) 1));
@@ -155,6 +163,7 @@
assertEquals((short) 2, mutNum.shortValue());
}
+ @Test
public void testSubtractValuePrimitive() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.subtract((short) 1);
@@ -162,6 +171,7 @@
assertEquals((short) 0, mutNum.shortValue());
}
+ @Test
public void testSubtractValueObject() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.subtract(Short.valueOf((short) 1));
@@ -169,6 +179,7 @@
assertEquals((short) 0, mutNum.shortValue());
}
+ @Test
public void testToString() {
assertEquals("0", new MutableShort((short) 0).toString());
assertEquals("10", new MutableShort((short) 10).toString());
diff --git a/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
index 583c8c0..d61d9a8 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
@@ -16,13 +16,14 @@
*/
package org.apache.commons.lang3.reflect;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.mutable.MutableObject;
@@ -31,7 +32,7 @@
* Unit tests ConstructorUtils
* @version $Id$
*/
-public class ConstructorUtilsTest extends TestCase {
+public class ConstructorUtilsTest {
public static class TestBean {
private String toString;
@@ -73,21 +74,22 @@
private Map<Class<?>, Class<?>[]> classCache;
- public ConstructorUtilsTest(String name) {
- super(name);
+ public ConstructorUtilsTest() {
classCache = new HashMap<Class<?>, Class<?>[]>();
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+
+ @Before
+ public void setUp() throws Exception {
classCache.clear();
}
+ @Test
public void testConstructor() throws Exception {
assertNotNull(MethodUtils.class.newInstance());
}
+ @Test
public void testInvokeConstructor() throws Exception {
assertEquals("()", ConstructorUtils.invokeConstructor(TestBean.class,
(Object[]) ArrayUtils.EMPTY_CLASS_ARRAY).toString());
@@ -110,6 +112,7 @@
TestBean.class, NumberUtils.DOUBLE_ONE).toString());
}
+ @Test
public void testInvokeExactConstructor() throws Exception {
assertEquals("()", ConstructorUtils.invokeExactConstructor(
TestBean.class, (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY).toString());
@@ -145,6 +148,7 @@
}
}
+ @Test
public void testGetAccessibleConstructor() throws Exception {
assertNotNull(ConstructorUtils.getAccessibleConstructor(Object.class
.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY)));
@@ -152,6 +156,7 @@
.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY)));
}
+ @Test
public void testGetAccessibleConstructorFromDescription() throws Exception {
assertNotNull(ConstructorUtils.getAccessibleConstructor(Object.class,
ArrayUtils.EMPTY_CLASS_ARRAY));
@@ -159,6 +164,7 @@
PrivateClass.class, ArrayUtils.EMPTY_CLASS_ARRAY));
}
+ @Test
public void testGetMatchingAccessibleMethod() throws Exception {
expectMatchingAccessibleConstructorParameterTypes(TestBean.class,
ArrayUtils.EMPTY_CLASS_ARRAY, ArrayUtils.EMPTY_CLASS_ARRAY);
@@ -200,6 +206,7 @@
singletonArray(Double.TYPE), singletonArray(Double.TYPE));
}
+ @Test
public void testNullArgument() {
expectMatchingAccessibleConstructorParameterTypes(MutableObject.class,
singletonArray(null), singletonArray(Object.class));
diff --git a/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java b/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java
index a03346e..66698d7 100644
--- a/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java
@@ -17,33 +17,23 @@
package org.apache.commons.lang3.text;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Locale;
-import junit.framework.TestCase;
-
/**
* Unit tests for {@link org.apache.commons.lang3.text.CompositeFormat}.
*/
-public class CompositeFormatTest extends TestCase {
-
- /**
- * Create a new test case with the specified name.
- *
- * @param name
- * name
- */
- public CompositeFormatTest(String name) {
- super(name);
- }
-
+public class CompositeFormatTest {
/**
* Ensures that the parse/format separation is correctly maintained.
*/
+ @Test
public void testCompositeFormat() {
Format parser = new Format() {
@@ -78,6 +68,7 @@
assertEquals( "Formatter get method incorrectly implemented", formatter, composite.getFormatter() );
}
+ @Test
public void testUsage() throws Exception {
Format f1 = new SimpleDateFormat("MMddyyyy", Locale.ENGLISH);
Format f2 = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
diff --git a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
index b7d31af..2e2cd72 100644
--- a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.commons.lang3.text;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
import java.text.ChoiceFormat;
@@ -33,8 +36,6 @@
import java.util.Locale;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.SystemUtils;
/**
@@ -43,22 +44,12 @@
* @since 2.4
* @version $Id$
*/
-public class ExtendedMessageFormatTest extends TestCase {
+public class ExtendedMessageFormatTest {
private final Map<String, FormatFactory> registry = new HashMap<String, FormatFactory>();
- /**
- * Create a new test case.
- *
- * @param name The name of the test
- */
- public ExtendedMessageFormatTest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
registry.put("lower", new LowerCaseFormatFactory());
registry.put("upper", new UpperCaseFormatFactory());
}
@@ -66,6 +57,7 @@
/**
* Test extended formats.
*/
+ @Test
public void testExtendedFormats() {
String pattern = "Lower: {0,lower} Upper: {1,upper}";
ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern, registry);
@@ -80,6 +72,7 @@
/**
* Test Bug LANG-477 - out of memory error with escaped quote
*/
+ @Test
public void testEscapedQuote_LANG_477() {
String pattern = "it''s a {0,lower} 'test'!";
ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern, registry);
@@ -89,6 +82,7 @@
/**
* Test extended and built in formats.
*/
+ @Test
public void testExtendedAndBuiltInFormats() {
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
@@ -187,6 +181,7 @@
/**
* Test the built in choice format.
*/
+ @Test
public void testBuiltInChoiceFormat() {
Object[] values = new Number[] {Integer.valueOf(1), Double.valueOf("2.2"), Double.valueOf("1234.5")};
String choicePattern = null;
@@ -206,6 +201,7 @@
/**
* Test the built in date/time formats
*/
+ @Test
public void testBuiltInDateTimeFormat() {
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
@@ -226,6 +222,7 @@
checkBuiltInFormat("12: {0,time}", args, availableLocales);
}
+ @Test
public void testOverriddenBuiltinFormat() {
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.JANUARY, 23);
@@ -254,6 +251,7 @@
/**
* Test the built in number formats.
*/
+ @Test
public void testBuiltInNumberFormat() {
Object[] args = new Object[] {Double.valueOf("6543.21")};
Locale[] availableLocales = NumberFormat.getAvailableLocales();
@@ -267,6 +265,7 @@
/**
* Test equals() and hashcode.
*/
+ @Test
public void testEqualsHashcode() {
Map<String, ? extends FormatFactory> registry = Collections.singletonMap("testfmt", new LowerCaseFormatFactory());
Map<String, ? extends FormatFactory> otherRegitry = Collections.singletonMap("testfmt", new UpperCaseFormatFactory());
diff --git a/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java b/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java
index 82d71ea..43df4a7 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java
@@ -17,13 +17,13 @@
package org.apache.commons.lang3.text;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.SystemUtils;
/**
@@ -31,7 +31,7 @@
*
* @version $Id$
*/
-public class StrBuilderAppendInsertTest extends TestCase {
+public class StrBuilderAppendInsertTest {
/** The system line separator. */
private static final String SEP = SystemUtils.LINE_SEPARATOR;
@@ -44,16 +44,8 @@
}
};
- /**
- * Create a new test case with the specified name.
- *
- * @param name the name
- */
- public StrBuilderAppendInsertTest(String name) {
- super(name);
- }
-
//-----------------------------------------------------------------------
+ @Test
public void testAppendNewLine() {
StrBuilder sb = new StrBuilder("---");
sb.appendNewLine().append("+++");
@@ -65,6 +57,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithNullText() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL");
@@ -96,6 +89,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_Object() {
StrBuilder sb = new StrBuilder();
sb.appendNull();
@@ -121,6 +115,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_String() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((String) null);
@@ -138,6 +133,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_String_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((String) null, 0, 1);
@@ -200,6 +196,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StringBuffer() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StringBuffer) null);
@@ -217,6 +214,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StringBuffer_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StringBuffer) null, 0, 1);
@@ -276,6 +274,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StrBuilder() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StrBuilder) null);
@@ -293,6 +292,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StrBuilder_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StrBuilder) null, 0, 1);
@@ -352,6 +352,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_CharArray() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((char[]) null);
@@ -366,6 +367,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_CharArray_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((char[]) null, 0, 1);
@@ -425,6 +427,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_Boolean() {
StrBuilder sb = new StrBuilder();
sb.append(true);
@@ -438,6 +441,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_PrimitiveNumber() {
StrBuilder sb = new StrBuilder();
sb.append(0);
@@ -454,6 +458,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_Object() {
StrBuilder sb = new StrBuilder();
sb.appendln((Object) null);
@@ -467,6 +472,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_String() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -488,6 +494,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_String_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -509,6 +516,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StringBuffer() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -530,6 +538,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StringBuffer_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -551,6 +560,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StrBuilder() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -572,6 +582,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StrBuilder_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -593,6 +604,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_CharArray() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -614,6 +626,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_CharArray_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -635,6 +648,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_Boolean() {
StrBuilder sb = new StrBuilder();
sb.appendln(true);
@@ -646,6 +660,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_PrimitiveNumber() {
StrBuilder sb = new StrBuilder();
sb.appendln(0);
@@ -665,6 +680,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendPadding() {
StrBuilder sb = new StrBuilder();
sb.append("foo");
@@ -686,6 +702,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadLeft() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft("foo", -1, '-');
@@ -724,6 +741,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadLeft_int() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft(123, -1, '-');
@@ -757,6 +775,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadRight() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight("foo", -1, '-');
@@ -795,6 +814,7 @@
}
// See: http://issues.apache.org/jira/browse/LANG-299
+ @Test
public void testLang299() {
StrBuilder sb = new StrBuilder(1);
sb.appendFixedWidthPadRight("foo", 1, '-');
@@ -802,6 +822,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadRight_int() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight(123, -1, '-');
@@ -835,6 +856,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendAll_Array() {
StrBuilder sb = new StrBuilder();
sb.appendAll((Object[]) null);
@@ -850,6 +872,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendAll_Collection() {
StrBuilder sb = new StrBuilder();
sb.appendAll((Collection<?>) null);
@@ -865,6 +888,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendAll_Iterator() {
StrBuilder sb = new StrBuilder();
sb.appendAll((Iterator<?>) null);
@@ -880,6 +904,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparators_Array() {
StrBuilder sb = new StrBuilder();
sb.appendWithSeparators((Object[]) null, ",");
@@ -903,6 +928,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparators_Collection() {
StrBuilder sb = new StrBuilder();
sb.appendWithSeparators((Collection<?>) null, ",");
@@ -926,6 +952,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparators_Iterator() {
StrBuilder sb = new StrBuilder();
sb.appendWithSeparators((Iterator<?>) null, ",");
@@ -949,6 +976,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparatorsWithNullText() {
StrBuilder sb = new StrBuilder();
sb.setNullText("null");
@@ -961,6 +989,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_String() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(","); // no effect
@@ -972,6 +1001,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_String_String() {
StrBuilder sb = new StrBuilder();
final String startSeparator = "order by ";
@@ -994,6 +1024,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_char() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(','); // no effect
@@ -1003,6 +1034,7 @@
sb.appendSeparator(',');
assertEquals("foo,", sb.toString());
}
+ @Test
public void testAppendSeparator_char_char() {
StrBuilder sb = new StrBuilder();
final char startSeparator = ':';
@@ -1017,6 +1049,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_String_int() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(",", 0); // no effect
@@ -1031,6 +1064,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_char_int() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(',', 0); // no effect
@@ -1045,6 +1079,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testInsert() {
StrBuilder sb = new StrBuilder();
@@ -1311,6 +1346,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testInsertWithNullText() {
StrBuilder sb = new StrBuilder();
sb.setNullText("null");
diff --git a/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java b/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
index e558c0f..979fb53 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
@@ -17,12 +17,12 @@
package org.apache.commons.lang3.text;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.ArrayUtils;
/**
@@ -30,19 +30,10 @@
*
* @version $Id$
*/
-public class StrBuilderTest extends TestCase {
-
- /**
- * Create a new test case with the specified name.
- *
- * @param name
- * name
- */
- public StrBuilderTest(String name) {
- super(name);
- }
+public class StrBuilderTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructors() {
StrBuilder sb0 = new StrBuilder();
assertEquals(32, sb0.capacity());
@@ -86,6 +77,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testChaining() {
StrBuilder sb = new StrBuilder();
assertSame(sb, sb.setNewLineText(null));
@@ -100,6 +92,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetSetNewLineText() {
StrBuilder sb = new StrBuilder();
assertEquals(null, sb.getNewLineText());
@@ -115,6 +108,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testGetSetNullText() {
StrBuilder sb = new StrBuilder();
assertEquals(null, sb.getNullText());
@@ -133,6 +127,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCapacityAndLength() {
StrBuilder sb = new StrBuilder();
assertEquals(32, sb.capacity());
@@ -217,6 +212,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testLength() {
StrBuilder sb = new StrBuilder();
assertEquals(0, sb.length());
@@ -225,6 +221,7 @@
assertEquals(5, sb.length());
}
+ @Test
public void testSetLength() {
StrBuilder sb = new StrBuilder();
sb.append("Hello");
@@ -244,6 +241,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCapacity() {
StrBuilder sb = new StrBuilder();
assertEquals(sb.buffer.length, sb.capacity());
@@ -252,6 +250,7 @@
assertEquals(sb.buffer.length, sb.capacity());
}
+ @Test
public void testEnsureCapacity() {
StrBuilder sb = new StrBuilder();
sb.ensureCapacity(2);
@@ -265,6 +264,7 @@
assertEquals(true, sb.capacity() >= 40);
}
+ @Test
public void testMinimizeCapacity() {
StrBuilder sb = new StrBuilder();
sb.minimizeCapacity();
@@ -276,6 +276,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSize() {
StrBuilder sb = new StrBuilder();
assertEquals(0, sb.size());
@@ -284,6 +285,7 @@
assertEquals(5, sb.size());
}
+ @Test
public void testIsEmpty() {
StrBuilder sb = new StrBuilder();
assertEquals(true, sb.isEmpty());
@@ -295,6 +297,7 @@
assertEquals(true, sb.isEmpty());
}
+ @Test
public void testClear() {
StrBuilder sb = new StrBuilder();
sb.append("Hello");
@@ -304,6 +307,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCharAt() {
StrBuilder sb = new StrBuilder();
try {
@@ -337,6 +341,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSetCharAt() {
StrBuilder sb = new StrBuilder();
try {
@@ -365,6 +370,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testDeleteCharAt() {
StrBuilder sb = new StrBuilder("abc");
sb.deleteCharAt(0);
@@ -377,6 +383,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testToCharArray() {
StrBuilder sb = new StrBuilder();
assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, sb.toCharArray());
@@ -391,6 +398,7 @@
assertTrue("toCharArray() result does not match", Arrays.equals("junit".toCharArray(), a));
}
+ @Test
public void testToCharArrayIntInt() {
StrBuilder sb = new StrBuilder();
assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, sb.toCharArray(0, 0));
@@ -424,6 +432,7 @@
}
}
+ @Test
public void testGetChars ( ) {
StrBuilder sb = new StrBuilder();
@@ -451,6 +460,7 @@
assertNotSame(input, a);
}
+ @Test
public void testGetCharsIntIntCharArrayInt( ) {
StrBuilder sb = new StrBuilder();
@@ -493,6 +503,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testDeleteIntInt() {
StrBuilder sb = new StrBuilder("abc");
sb.delete(0, 1);
@@ -521,6 +532,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testDeleteAll_char() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.deleteAll('X');
@@ -537,6 +549,7 @@
assertEquals("", sb.toString());
}
+ @Test
public void testDeleteFirst_char() {
StrBuilder sb = new StrBuilder("abcba");
sb.deleteFirst('X');
@@ -554,6 +567,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testDeleteAll_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.deleteAll((String) null);
@@ -579,6 +593,7 @@
assertEquals("", sb.toString());
}
+ @Test
public void testDeleteFirst_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.deleteFirst((String) null);
@@ -605,6 +620,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testDeleteAll_StrMatcher() {
StrBuilder sb = new StrBuilder("A0xA1A2yA3");
sb.deleteAll((StrMatcher) null);
@@ -621,6 +637,7 @@
assertEquals("", sb.toString());
}
+ @Test
public void testDeleteFirst_StrMatcher() {
StrBuilder sb = new StrBuilder("A0xA1A2yA3");
sb.deleteFirst((StrMatcher) null);
@@ -638,6 +655,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testReplace_int_int_String() {
StrBuilder sb = new StrBuilder("abc");
sb.replace(0, 1, "d");
@@ -673,6 +691,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceAll_char_char() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceAll('x', 'y');
@@ -688,6 +707,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceFirst_char_char() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceFirst('x', 'y');
@@ -703,6 +723,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceAll_String_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceAll((String) null, null);
@@ -732,6 +753,7 @@
assertEquals("xbxxbx", sb.toString());
}
+ @Test
public void testReplaceFirst_String_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceFirst((String) null, null);
@@ -762,6 +784,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceAll_StrMatcher_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceAll((StrMatcher) null, null);
@@ -795,6 +818,7 @@
assertEquals("***-******-***", sb.toString());
}
+ @Test
public void testReplaceFirst_StrMatcher_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceFirst((StrMatcher) null, null);
@@ -829,6 +853,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReplace_StrMatcher_String_int_int_int_VaryMatcher() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replace((StrMatcher) null, "x", 0, sb.length(), -1);
@@ -849,6 +874,7 @@
assertEquals("", sb.toString());
}
+ @Test
public void testReplace_StrMatcher_String_int_int_int_VaryReplace() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replace(StrMatcher.stringMatcher("cb"), "cb", 0, sb.length(), -1);
@@ -871,6 +897,7 @@
assertEquals("abca", sb.toString());
}
+ @Test
public void testReplace_StrMatcher_String_int_int_int_VaryStartIndex() {
StrBuilder sb = new StrBuilder("aaxaaaayaa");
sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, sb.length(), -1);
@@ -931,6 +958,7 @@
assertEquals("aaxaaaayaa", sb.toString());
}
+ @Test
public void testReplace_StrMatcher_String_int_int_int_VaryEndIndex() {
StrBuilder sb = new StrBuilder("aaxaaaayaa");
sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, 0, -1);
@@ -984,6 +1012,7 @@
assertEquals("aaxaaaayaa", sb.toString());
}
+ @Test
public void testReplace_StrMatcher_String_int_int_int_VaryCount() {
StrBuilder sb = new StrBuilder("aaxaaaayaa");
sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, 10, -1);
@@ -1015,6 +1044,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReverse() {
StrBuilder sb = new StrBuilder();
assertEquals("", sb.reverse().toString());
@@ -1025,6 +1055,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTrim() {
StrBuilder sb = new StrBuilder();
assertEquals("", sb.reverse().toString());
@@ -1046,6 +1077,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testStartsWith() {
StrBuilder sb = new StrBuilder();
assertFalse(sb.startsWith("a"));
@@ -1058,6 +1090,7 @@
assertFalse(sb.startsWith("cba"));
}
+ @Test
public void testEndsWith() {
StrBuilder sb = new StrBuilder();
assertFalse(sb.endsWith("a"));
@@ -1075,6 +1108,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSubSequenceIntInt() {
StrBuilder sb = new StrBuilder ("hello goodbye");
// Start index is negative
@@ -1108,6 +1142,7 @@
assertEquals ("hello goodbye".subSequence(6,13), sb.subSequence(6, 13));
}
+ @Test
public void testSubstringInt() {
StrBuilder sb = new StrBuilder ("hello goodbye");
assertEquals ("goodbye", sb.substring(6));
@@ -1126,6 +1161,7 @@
}
+ @Test
public void testSubstringIntInt() {
StrBuilder sb = new StrBuilder ("hello goodbye");
assertEquals ("hello", sb.substring(0, 5));
@@ -1148,6 +1184,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testMidString() {
StrBuilder sb = new StrBuilder("hello goodbye hello");
assertEquals("goodbye", sb.midString(6, 7));
@@ -1158,6 +1195,7 @@
assertEquals("hello", sb.midString(14, 22));
}
+ @Test
public void testRightString() {
StrBuilder sb = new StrBuilder("left right");
assertEquals("right", sb.rightString(5));
@@ -1166,6 +1204,7 @@
assertEquals("left right", sb.rightString(15));
}
+ @Test
public void testLeftString() {
StrBuilder sb = new StrBuilder("left right");
assertEquals("left", sb.leftString(4));
@@ -1175,6 +1214,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testContains_char() {
StrBuilder sb = new StrBuilder("abcdefghijklmnopqrstuvwxyz");
assertEquals(true, sb.contains('a'));
@@ -1183,6 +1223,7 @@
assertEquals(false, sb.contains('1'));
}
+ @Test
public void testContains_String() {
StrBuilder sb = new StrBuilder("abcdefghijklmnopqrstuvwxyz");
assertEquals(true, sb.contains("a"));
@@ -1192,6 +1233,7 @@
assertEquals(false, sb.contains((String) null));
}
+ @Test
public void testContains_StrMatcher() {
StrBuilder sb = new StrBuilder("abcdefghijklmnopqrstuvwxyz");
assertEquals(true, sb.contains(StrMatcher.charMatcher('a')));
@@ -1207,6 +1249,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testIndexOf_char() {
StrBuilder sb = new StrBuilder("abab");
assertEquals(0, sb.indexOf('a'));
@@ -1220,6 +1263,7 @@
assertEquals(-1, sb.indexOf('z'));
}
+ @Test
public void testIndexOf_char_int() {
StrBuilder sb = new StrBuilder("abab");
assertEquals(0, sb.indexOf('a', -1));
@@ -1241,6 +1285,7 @@
assertEquals(-1, sb.indexOf('z', 3));
}
+ @Test
public void testLastIndexOf_char() {
StrBuilder sb = new StrBuilder("abab");
@@ -1254,6 +1299,7 @@
assertEquals (-1, sb.lastIndexOf('z'));
}
+ @Test
public void testLastIndexOf_char_int() {
StrBuilder sb = new StrBuilder("abab");
assertEquals(-1, sb.lastIndexOf('a', -1));
@@ -1274,6 +1320,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testIndexOf_String() {
StrBuilder sb = new StrBuilder("abab");
@@ -1296,6 +1343,7 @@
assertEquals(-1, sb.indexOf((String) null));
}
+ @Test
public void testIndexOf_String_int() {
StrBuilder sb = new StrBuilder("abab");
assertEquals(0, sb.indexOf("a", -1));
@@ -1332,6 +1380,7 @@
assertEquals(-1, sb.indexOf((String) null, 2));
}
+ @Test
public void testLastIndexOf_String() {
StrBuilder sb = new StrBuilder("abab");
@@ -1354,6 +1403,7 @@
assertEquals(-1, sb.lastIndexOf((String) null));
}
+ @Test
public void testLastIndexOf_String_int() {
StrBuilder sb = new StrBuilder("abab");
assertEquals(-1, sb.lastIndexOf("a", -1));
@@ -1391,6 +1441,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testIndexOf_StrMatcher() {
StrBuilder sb = new StrBuilder();
assertEquals(-1, sb.indexOf((StrMatcher) null));
@@ -1408,6 +1459,7 @@
assertEquals(6, sb.indexOf(A_NUMBER_MATCHER));
}
+ @Test
public void testIndexOf_StrMatcher_int() {
StrBuilder sb = new StrBuilder();
assertEquals(-1, sb.indexOf((StrMatcher) null, 2));
@@ -1447,6 +1499,7 @@
assertEquals(-1, sb.indexOf(A_NUMBER_MATCHER, 24));
}
+ @Test
public void testLastIndexOf_StrMatcher() {
StrBuilder sb = new StrBuilder();
assertEquals(-1, sb.lastIndexOf((StrMatcher) null));
@@ -1464,6 +1517,7 @@
assertEquals(6, sb.lastIndexOf(A_NUMBER_MATCHER));
}
+ @Test
public void testLastIndexOf_StrMatcher_int() {
StrBuilder sb = new StrBuilder();
assertEquals(-1, sb.lastIndexOf((StrMatcher) null, 2));
@@ -1518,6 +1572,7 @@
};
//-----------------------------------------------------------------------
+ @Test
public void testAsTokenizer() throws Exception {
// from Javadoc
StrBuilder b = new StrBuilder();
@@ -1556,6 +1611,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testAsReader() throws Exception {
StrBuilder sb = new StrBuilder("some text");
Reader reader = sb.asReader();
@@ -1627,6 +1683,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAsWriter() throws Exception {
StrBuilder sb = new StrBuilder("base");
Writer writer = sb.asWriter();
@@ -1661,6 +1718,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testEqualsIgnoreCase() {
StrBuilder sb1 = new StrBuilder();
StrBuilder sb2 = new StrBuilder();
@@ -1684,6 +1742,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testEquals() {
StrBuilder sb1 = new StrBuilder();
StrBuilder sb2 = new StrBuilder();
@@ -1709,6 +1768,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testHashCode() {
StrBuilder sb = new StrBuilder();
int hc1a = sb.hashCode();
@@ -1724,12 +1784,14 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testToString() {
StrBuilder sb = new StrBuilder("abc");
assertEquals("abc", sb.toString());
}
//-----------------------------------------------------------------------
+ @Test
public void testToStringBuffer() {
StrBuilder sb = new StrBuilder();
assertEquals(new StringBuffer().toString(), sb.toStringBuffer().toString());
@@ -1739,12 +1801,14 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testLang294() {
StrBuilder sb = new StrBuilder("\n%BLAH%\nDo more stuff\neven more stuff\n%BLAH%\n");
sb.deleteAll("\n%BLAH%");
assertEquals("\nDo more stuff\neven more stuff\n", sb.toString());
}
+ @Test
public void testIndexOfLang294() {
StrBuilder sb = new StrBuilder("onetwothree");
sb.deleteFirst("three");
@@ -1752,6 +1816,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testLang295() {
StrBuilder sb = new StrBuilder("onetwothree");
sb.deleteFirst("three");
@@ -1760,12 +1825,14 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testLang412Right() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight(null, 10, '*');
assertEquals( "Failed to invoke appendFixedWidthPadRight correctly", "**********", sb.toString());
}
+ @Test
public void testLang412Left() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft(null, 10, '*');
diff --git a/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java b/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
index ecf4af5..592e6a9 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
@@ -17,25 +17,30 @@
package org.apache.commons.lang3.text;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Test class for StrLookup.
*
* @version $Id$
*/
-public class StrLookupTest extends TestCase {
+public class StrLookupTest {
//-----------------------------------------------------------------------
+ @Test
public void testNoneLookup() {
assertEquals(null, StrLookup.noneLookup().lookup(null));
assertEquals(null, StrLookup.noneLookup().lookup(""));
assertEquals(null, StrLookup.noneLookup().lookup("any"));
}
+ @Test
public void testSystemProperiesLookup() {
assertEquals(System.getProperty("os.name"), StrLookup.systemPropertiesLookup().lookup("os.name"));
assertEquals(null, StrLookup.systemPropertiesLookup().lookup(""));
@@ -48,6 +53,7 @@
}
}
+ @Test
public void testMapLookup() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("key", "value");
@@ -59,6 +65,7 @@
assertEquals(null, StrLookup.mapLookup(map).lookup("other"));
}
+ @Test
public void testMapLookup_nullMap() {
Map<String, ?> map = null;
assertEquals(null, StrLookup.mapLookup(map).lookup(null));
diff --git a/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java b/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java
index 657fd29..0d576dc 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java
@@ -17,29 +17,26 @@
package org.apache.commons.lang3.text;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.StrMatcher}.
*
* @version $Id$
*/
-public class StrMatcherTest extends TestCase {
+public class StrMatcherTest {
private static final char[] BUFFER1 = "0,1\t2 3\n\r\f\u0000'\"".toCharArray();
private static final char[] BUFFER2 = "abcdef".toCharArray();
- /**
- * Create a new test case with the specified name.
- *
- * @param name the name
- */
- public StrMatcherTest(String name) {
- super(name);
- }
//-----------------------------------------------------------------------
+ @Test
public void testCommaMatcher() {
StrMatcher matcher = StrMatcher.commaMatcher();
assertSame(matcher, StrMatcher.commaMatcher());
@@ -49,6 +46,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTabMatcher() {
StrMatcher matcher = StrMatcher.tabMatcher();
assertSame(matcher, StrMatcher.tabMatcher());
@@ -58,6 +56,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSpaceMatcher() {
StrMatcher matcher = StrMatcher.spaceMatcher();
assertSame(matcher, StrMatcher.spaceMatcher());
@@ -67,6 +66,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSplitMatcher() {
StrMatcher matcher = StrMatcher.splitMatcher();
assertSame(matcher, StrMatcher.splitMatcher());
@@ -82,6 +82,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTrimMatcher() {
StrMatcher matcher = StrMatcher.trimMatcher();
assertSame(matcher, StrMatcher.trimMatcher());
@@ -97,6 +98,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testSingleQuoteMatcher() {
StrMatcher matcher = StrMatcher.singleQuoteMatcher();
assertSame(matcher, StrMatcher.singleQuoteMatcher());
@@ -106,6 +108,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testDoubleQuoteMatcher() {
StrMatcher matcher = StrMatcher.doubleQuoteMatcher();
assertSame(matcher, StrMatcher.doubleQuoteMatcher());
@@ -114,6 +117,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testQuoteMatcher() {
StrMatcher matcher = StrMatcher.quoteMatcher();
assertSame(matcher, StrMatcher.quoteMatcher());
@@ -123,6 +127,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testNoneMatcher() {
StrMatcher matcher = StrMatcher.noneMatcher();
assertSame(matcher, StrMatcher.noneMatcher());
@@ -142,6 +147,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCharMatcher_char() {
StrMatcher matcher = StrMatcher.charMatcher('c');
assertEquals(0, matcher.isMatch(BUFFER2, 0));
@@ -153,6 +159,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCharSetMatcher_String() {
StrMatcher matcher = StrMatcher.charSetMatcher("ace");
assertEquals(1, matcher.isMatch(BUFFER2, 0));
@@ -167,6 +174,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCharSetMatcher_charArray() {
StrMatcher matcher = StrMatcher.charSetMatcher("ace".toCharArray());
assertEquals(1, matcher.isMatch(BUFFER2, 0));
@@ -181,6 +189,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testStringMatcher_String() {
StrMatcher matcher = StrMatcher.stringMatcher("bc");
assertEquals(0, matcher.isMatch(BUFFER2, 0));
@@ -194,6 +203,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testMatcherIndices() {
// remember that the API contract is tight for the isMatch() method
// all the onus is on the caller, so invalid inputs are not
diff --git a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
index 81d14fe..1939051 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
@@ -17,12 +17,14 @@
package org.apache.commons.lang3.text;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.mutable.MutableObject;
/**
@@ -30,21 +32,19 @@
*
* @version $Id$
*/
-public class StrSubstitutorTest extends TestCase {
+public class StrSubstitutorTest {
private Map<String, String> values;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
values = new HashMap<String, String>();
values.put("animal", "quick brown fox");
values.put("target", "lazy dog");
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
values = null;
}
@@ -52,6 +52,7 @@
/**
* Tests simple key replace.
*/
+ @Test
public void testReplaceSimple() {
doTestReplace("The quick brown fox jumps over the lazy dog.", "The ${animal} jumps over the ${target}.", true);
}
@@ -59,6 +60,7 @@
/**
* Tests simple key replace.
*/
+ @Test
public void testReplaceSolo() {
doTestReplace("quick brown fox", "${animal}", false);
}
@@ -66,6 +68,7 @@
/**
* Tests replace with no variables.
*/
+ @Test
public void testReplaceNoVariables() {
doTestNoReplace("The balloon arrived.");
}
@@ -73,6 +76,7 @@
/**
* Tests replace with null.
*/
+ @Test
public void testReplaceNull() {
doTestNoReplace(null);
}
@@ -80,6 +84,7 @@
/**
* Tests replace with null.
*/
+ @Test
public void testReplaceEmpty() {
doTestNoReplace("");
}
@@ -87,6 +92,7 @@
/**
* Tests key replace changing map after initialization (not recommended).
*/
+ @Test
public void testReplaceChangedMap() {
StrSubstitutor sub = new StrSubstitutor(values);
values.put("target", "moon");
@@ -96,6 +102,7 @@
/**
* Tests unknown key replace.
*/
+ @Test
public void testReplaceUnknownKey() {
doTestReplace("The ${person} jumps over the lazy dog.", "The ${person} jumps over the ${target}.", true);
}
@@ -103,6 +110,7 @@
/**
* Tests adjacent keys.
*/
+ @Test
public void testReplaceAdjacentAtStart() {
values.put("code", "GBP");
values.put("amount", "12.50");
@@ -113,6 +121,7 @@
/**
* Tests adjacent keys.
*/
+ @Test
public void testReplaceAdjacentAtEnd() {
values.put("code", "GBP");
values.put("amount", "12.50");
@@ -123,6 +132,7 @@
/**
* Tests simple recursive replace.
*/
+ @Test
public void testReplaceRecursive() {
values.put("animal", "${critter}");
values.put("target", "${pet}");
@@ -138,6 +148,7 @@
/**
* Tests escaping.
*/
+ @Test
public void testReplaceEscaping() {
doTestReplace("The ${animal} jumps over the lazy dog.", "The $${animal} jumps over the ${target}.", true);
}
@@ -145,6 +156,7 @@
/**
* Tests escaping.
*/
+ @Test
public void testReplaceSoloEscaping() {
doTestReplace("${animal}", "$${animal}", false);
}
@@ -152,6 +164,7 @@
/**
* Tests complex escaping.
*/
+ @Test
public void testReplaceComplexEscaping() {
doTestReplace("The ${quick brown fox} jumps over the lazy dog.", "The $${${animal}} jumps over the ${target}.", true);
}
@@ -159,6 +172,7 @@
/**
* Tests when no prefix or suffix.
*/
+ @Test
public void testReplaceNoPrefixNoSuffix() {
doTestReplace("The animal jumps over the lazy dog.", "The animal jumps over the ${target}.", true);
}
@@ -166,6 +180,7 @@
/**
* Tests when no incomplete prefix.
*/
+ @Test
public void testReplaceIncompletePrefix() {
doTestReplace("The {animal} jumps over the lazy dog.", "The {animal} jumps over the ${target}.", true);
}
@@ -173,6 +188,7 @@
/**
* Tests when prefix but no suffix.
*/
+ @Test
public void testReplacePrefixNoSuffix() {
doTestReplace("The ${animal jumps over the ${target} lazy dog.", "The ${animal jumps over the ${target} ${target}.", true);
}
@@ -180,6 +196,7 @@
/**
* Tests when suffix but no prefix.
*/
+ @Test
public void testReplaceNoPrefixSuffix() {
doTestReplace("The animal} jumps over the lazy dog.", "The animal} jumps over the ${target}.", true);
}
@@ -187,6 +204,7 @@
/**
* Tests when no variable name.
*/
+ @Test
public void testReplaceEmptyKeys() {
doTestReplace("The ${} jumps over the lazy dog.", "The ${} jumps over the ${target}.", true);
}
@@ -194,6 +212,7 @@
/**
* Tests replace creates output same as input.
*/
+ @Test
public void testReplaceToIdentical() {
values.put("animal", "$${${thing}}");
values.put("thing", "animal");
@@ -204,6 +223,7 @@
* Tests a cyclic replace operation.
* The cycle should be detected and cause an exception to be thrown.
*/
+ @Test
public void testCyclicReplacement() {
Map<String, String> map = new HashMap<String, String>();
map.put("animal", "${critter}");
@@ -226,6 +246,7 @@
/**
* Tests interpolation with weird boundary patterns.
*/
+ @Test
public void testReplaceWeirdPattens() {
doTestNoReplace("");
doTestNoReplace("${}");
@@ -249,6 +270,7 @@
/**
* Tests simple key replace.
*/
+ @Test
public void testReplacePartialString_noReplace() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals("${animal} jumps", sub.replace("The ${animal} jumps over the ${target}.", 4, 15));
@@ -257,6 +279,7 @@
/**
* Tests whether a variable can be replaced in a variable name.
*/
+ @Test
public void testReplaceInVariable() {
values.put("animal.1", "fox");
values.put("animal.2", "mouse");
@@ -277,6 +300,7 @@
/**
* Tests whether substitution in variable names is disabled per default.
*/
+ @Test
public void testReplaceInVariableDisabled() {
values.put("animal.1", "fox");
values.put("animal.2", "mouse");
@@ -291,6 +315,7 @@
/**
* Tests complex and recursive substitution in variable names.
*/
+ @Test
public void testReplaceInVariableRecursive() {
values.put("animal.2", "brown fox");
values.put("animal.1", "white mouse");
@@ -309,6 +334,7 @@
/**
* Tests protected.
*/
+ @Test
public void testResolveVariable() {
final StrBuilder builder = new StrBuilder("Hi ${name}!");
Map<String, String> map = new HashMap<String, String>();
@@ -331,6 +357,7 @@
/**
* Tests constructor.
*/
+ @Test
public void testConstructorNoArgs() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals("Hi ${name}", sub.replace("Hi ${name}"));
@@ -339,6 +366,7 @@
/**
* Tests constructor.
*/
+ @Test
public void testConstructorMapPrefixSuffix() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -349,6 +377,7 @@
/**
* Tests constructor.
*/
+ @Test
public void testConstructorMapFull() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -360,6 +389,7 @@
/**
* Tests get set.
*/
+ @Test
public void testGetSetEscape() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals('$', sub.getEscapeChar());
@@ -370,6 +400,7 @@
/**
* Tests get set.
*/
+ @Test
public void testGetSetPrefix() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals(true, sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
@@ -401,6 +432,7 @@
/**
* Tests get set.
*/
+ @Test
public void testGetSetSuffix() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals(true, sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
@@ -433,6 +465,7 @@
/**
* Tests static.
*/
+ @Test
public void testStaticReplace() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -442,6 +475,7 @@
/**
* Tests static.
*/
+ @Test
public void testStaticReplacePrefixSuffix() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -451,6 +485,7 @@
/**
* Tests interpolation with system properties.
*/
+ @Test
public void testStaticReplaceSystemProperties() {
StrBuilder buf = new StrBuilder();
buf.append("Hi ").append(System.getProperty("user.name"));
@@ -466,6 +501,7 @@
/**
* Test the replace of a properties object
*/
+ @Test
public void testSubstituteDefaultProperties(){
String org = "${doesnotwork}";
System.setProperty("doesnotwork", "It works!");
@@ -476,6 +512,7 @@
assertEquals("It works!", StrSubstitutor.replace(org, props));
}
+ @Test
public void testSamePrefixAndSuffix() {
Map<String, String> map = new HashMap<String, String>();
map.put("greeting", "Hello");
diff --git a/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java b/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java
index ca32197..a66b869 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java
@@ -17,13 +17,13 @@
package org.apache.commons.lang3.text;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ObjectUtils;
@@ -31,27 +31,19 @@
* Unit test for Tokenizer.
*
*/
-public class StrTokenizerTest extends TestCase {
+public class StrTokenizerTest {
private static final String CSV_SIMPLE_FIXTURE = "A,b,c";
private static final String TSV_SIMPLE_FIXTURE = "A\tb\tc";
- /**
- * JUnit constructor.
- *
- * @param name
- */
- public StrTokenizerTest(String name) {
- super(name);
- }
-
private void checkClone(StrTokenizer tokenizer) {
assertFalse(StrTokenizer.getCSVInstance() == tokenizer);
assertFalse(StrTokenizer.getTSVInstance() == tokenizer);
}
// -----------------------------------------------------------------------
+ @Test
public void test1() {
String input = "a;b;c;\"d;\"\"e\";f; ; ; ";
@@ -72,6 +64,7 @@
}
+ @Test
public void test2() {
String input = "a;b;c ;\"d;\"\"e\";f; ; ;";
@@ -92,6 +85,7 @@
}
+ @Test
public void test3() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -112,6 +106,7 @@
}
+ @Test
public void test4() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -132,6 +127,7 @@
}
+ @Test
public void test5() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -153,6 +149,7 @@
}
+ @Test
public void test6() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -188,6 +185,7 @@
}
+ @Test
public void test7() {
String input = "a b c \"d e\" f ";
@@ -208,6 +206,7 @@
}
+ @Test
public void test8() {
String input = "a b c \"d e\" f ";
@@ -228,6 +227,7 @@
}
+ @Test
public void testBasic1() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -237,6 +237,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic2() {
String input = "a \nb\fc";
StrTokenizer tok = new StrTokenizer(input);
@@ -246,6 +247,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic3() {
String input = "a \nb\u0001\fc";
StrTokenizer tok = new StrTokenizer(input);
@@ -255,6 +257,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic4() {
String input = "a \"b\" c";
StrTokenizer tok = new StrTokenizer(input);
@@ -264,6 +267,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic5() {
String input = "a:b':c";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -273,6 +277,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicDelim1() {
String input = "a:b:c";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -282,6 +287,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicDelim2() {
String input = "a:b:c";
StrTokenizer tok = new StrTokenizer(input, ',');
@@ -289,6 +295,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicEmpty1() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -300,6 +307,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicEmpty2() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -312,6 +320,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted1() {
String input = "a 'b' c";
StrTokenizer tok = new StrTokenizer(input, ' ', '\'');
@@ -321,6 +330,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted2() {
String input = "a:'b':";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -332,6 +342,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted3() {
String input = "a:'b''c'";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -342,6 +353,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted4() {
String input = "a: 'b' 'c' :d";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -354,6 +366,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted5() {
String input = "a: 'b'x'c' :d";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -366,6 +379,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted6() {
String input = "a:'b'\"c':d";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -375,6 +389,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted7() {
String input = "a:\"There's a reason here\":b";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -385,6 +400,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuotedTrimmed1() {
String input = "a: 'b' :";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -397,6 +413,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicTrimmed1() {
String input = "a: b : ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -409,6 +426,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicTrimmed2() {
String input = "a: b :";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -421,6 +439,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed1() {
String input = "a: bIGNOREc : ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -434,6 +453,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed2() {
String input = "IGNOREaIGNORE: IGNORE bIGNOREc IGNORE : IGNORE ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -447,6 +467,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed3() {
String input = "IGNOREaIGNORE: IGNORE bIGNOREc IGNORE : IGNORE ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -459,6 +480,7 @@
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed4() {
String input = "IGNOREaIGNORE: IGNORE 'bIGNOREc'IGNORE'd' IGNORE : IGNORE ";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -473,6 +495,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testListArray() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -484,20 +507,23 @@
}
//-----------------------------------------------------------------------
- public void testCSV(String data) {
+ private void testCSV(String data) {
this.testXSVAbc(StrTokenizer.getCSVInstance(data));
this.testXSVAbc(StrTokenizer.getCSVInstance(data.toCharArray()));
}
+ @Test
public void testCSVEmpty() {
this.testEmpty(StrTokenizer.getCSVInstance());
this.testEmpty(StrTokenizer.getCSVInstance(""));
}
+ @Test
public void testCSVSimple() {
this.testCSV(CSV_SIMPLE_FIXTURE);
}
+ @Test
public void testCSVSimpleNeedsTrim() {
this.testCSV(" " + CSV_SIMPLE_FIXTURE);
this.testCSV(" \n\t " + CSV_SIMPLE_FIXTURE);
@@ -516,6 +542,7 @@
} catch (NoSuchElementException ex) {}
}
+ @Test
public void testGetContent() {
String input = "a b c \"d e\" f ";
StrTokenizer tok = new StrTokenizer(input);
@@ -529,6 +556,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testChaining() {
StrTokenizer tok = new StrTokenizer();
assertEquals(tok, tok.reset());
@@ -550,6 +578,7 @@
* Tests that the {@link StrTokenizer#clone()} clone method catches {@link CloneNotSupportedException} and returns
* <code>null</code>.
*/
+ @Test
public void testCloneNotSupportedException() {
Object notCloned = new StrTokenizer() {
@Override
@@ -560,6 +589,7 @@
assertNull(notCloned);
}
+ @Test
public void testCloneNull() {
StrTokenizer tokenizer = new StrTokenizer((char[]) null);
// Start sanity check
@@ -573,6 +603,7 @@
assertEquals(null, clonedTokenizer.nextToken());
}
+ @Test
public void testCloneReset() {
char[] input = new char[]{'a'};
StrTokenizer tokenizer = new StrTokenizer(input);
@@ -589,6 +620,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testConstructor_String() {
StrTokenizer tok = new StrTokenizer("a b");
assertEquals("a", tok.next());
@@ -603,6 +635,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_String_char() {
StrTokenizer tok = new StrTokenizer("a b", ' ');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -618,6 +651,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_String_char_char() {
StrTokenizer tok = new StrTokenizer("a b", ' ', '"');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -634,6 +668,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_charArray() {
StrTokenizer tok = new StrTokenizer("a b".toCharArray());
assertEquals("a", tok.next());
@@ -648,6 +683,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_charArray_char() {
StrTokenizer tok = new StrTokenizer("a b".toCharArray(), ' ');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -663,6 +699,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_charArray_char_char() {
StrTokenizer tok = new StrTokenizer("a b".toCharArray(), ' ', '"');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -679,6 +716,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReset() {
StrTokenizer tok = new StrTokenizer("a b c");
assertEquals("a", tok.next());
@@ -694,6 +732,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReset_String() {
StrTokenizer tok = new StrTokenizer("x x x");
tok.reset("d e");
@@ -706,6 +745,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testReset_charArray() {
StrTokenizer tok = new StrTokenizer("x x x");
@@ -719,11 +759,13 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTSV() {
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE));
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE.toCharArray()));
}
+ @Test
public void testTSVEmpty() {
this.testEmpty(StrTokenizer.getCSVInstance());
this.testEmpty(StrTokenizer.getCSVInstance(""));
@@ -754,6 +796,7 @@
assertEquals(3, tokenizer.size());
}
+ @Test
public void testIteration() {
StrTokenizer tkn = new StrTokenizer("a b c");
assertEquals(false, tkn.hasPrevious());
@@ -796,6 +839,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTokenizeSubclassInputChange() {
StrTokenizer tkn = new StrTokenizer("a b c d e") {
@Override
@@ -808,6 +852,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testTokenizeSubclassOutputChange() {
StrTokenizer tkn = new StrTokenizer("a b c") {
@Override
@@ -823,6 +868,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testToString() {
StrTokenizer tkn = new StrTokenizer("a b c d e");
assertEquals("StrTokenizer[not tokenized yet]", tkn.toString());
diff --git a/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java b/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
index d8a3bb0..46172f9 100644
--- a/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
@@ -16,23 +16,23 @@
*/
package org.apache.commons.lang3.text;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests for WordUtils class.
*
* @version $Id$
*/
-public class WordUtilsTest extends TestCase {
-
- public WordUtilsTest(String name) {
- super(name);
- }
+public class WordUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new WordUtils());
Constructor<?>[] cons = WordUtils.class.getDeclaredConstructors();
@@ -43,6 +43,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testWrap_StringInt() {
assertEquals(null, WordUtils.wrap(null, 20));
assertEquals(null, WordUtils.wrap(null, -1));
@@ -70,6 +71,7 @@
assertEquals(expected, WordUtils.wrap(input, 20));
}
+ @Test
public void testWrap_StringIntStringBoolean() {
assertEquals(null, WordUtils.wrap(null, 20, "\n", false));
assertEquals(null, WordUtils.wrap(null, 20, "\n", true));
@@ -149,6 +151,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testCapitalize_String() {
assertEquals(null, WordUtils.capitalize(null));
assertEquals("", WordUtils.capitalize(""));
@@ -162,6 +165,7 @@
assertEquals("I AM HERE 123", WordUtils.capitalize("I AM HERE 123") );
}
+ @Test
public void testCapitalizeWithDelimiters_String() {
assertEquals(null, WordUtils.capitalize(null, null));
assertEquals("", WordUtils.capitalize("", new char[0]));
@@ -179,6 +183,7 @@
assertEquals("I Am.fine", WordUtils.capitalize("i am.fine", null) );
}
+ @Test
public void testCapitalizeFully_String() {
assertEquals(null, WordUtils.capitalizeFully(null));
assertEquals("", WordUtils.capitalizeFully(""));
@@ -192,6 +197,7 @@
assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123") );
}
+ @Test
public void testCapitalizeFullyWithDelimiters_String() {
assertEquals(null, WordUtils.capitalizeFully(null, null));
assertEquals("", WordUtils.capitalizeFully("", new char[0]));
@@ -209,6 +215,7 @@
assertEquals("I Am.fine", WordUtils.capitalizeFully("i am.fine", null) );
}
+ @Test
public void testUncapitalize_String() {
assertEquals(null, WordUtils.uncapitalize(null));
assertEquals("", WordUtils.uncapitalize(""));
@@ -222,6 +229,7 @@
assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123") );
}
+ @Test
public void testUncapitalizeWithDelimiters_String() {
assertEquals(null, WordUtils.uncapitalize(null, null));
assertEquals("", WordUtils.uncapitalize("", new char[0]));
@@ -240,6 +248,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testInitials_String() {
assertEquals(null, WordUtils.initials(null));
assertEquals("", WordUtils.initials(""));
@@ -254,6 +263,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testInitials_String_charArray() {
char[] array = null;
assertEquals(null, WordUtils.initials(null, array));
@@ -335,6 +345,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSwapCase_String() {
assertEquals(null, WordUtils.swapCase(null));
assertEquals("", WordUtils.swapCase(""));
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java b/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java
index 7f7a134..71c3692 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java
@@ -17,22 +17,26 @@
package org.apache.commons.lang3.text.translate;
+import static org.junit.Assert.assertTrue;
+
import java.util.HashSet;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}.
* @version $Id$
*/
-public class EntityArraysTest extends TestCase {
+public class EntityArraysTest {
+ @Test
public void testConstructorExists() {
new EntityArrays();
}
// LANG-659 - check arrays for duplicate entries
+ @Test
public void testHTML40_EXTENDED_ESCAPE(){
Set<String> col0 = new HashSet<String>();
Set<String> col1 = new HashSet<String>();
@@ -44,6 +48,7 @@
}
// LANG-658 - check arrays for duplicate entries
+ @Test
public void testISO8859_1_ESCAPE(){
Set<String> col0 = new HashSet<String>();
Set<String> col1 = new HashSet<String>();
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java b/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java
index 4d08a52..8efb009 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java
@@ -17,17 +17,20 @@
package org.apache.commons.lang3.text.translate;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.io.StringWriter;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.LookupTranslator}.
* @version $Id$
*/
-public class LookupTranslatorTest extends TestCase {
+public class LookupTranslatorTest {
+ @Test
public void testBasicLookup() throws IOException {
LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { "one", "two" } });
StringWriter out = new StringWriter();
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java b/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
index c46badd..f3c6dff 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
@@ -17,14 +17,17 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityEscaper}.
* @version $Id$
*/
-public class NumericEntityEscaperTest extends TestCase {
+public class NumericEntityEscaperTest {
+ @Test
public void testBelow() {
NumericEntityEscaper nee = NumericEntityEscaper.below('F');
@@ -33,6 +36,7 @@
assertEquals("Failed to escape numeric entities via the below method", "ADFGZ", result);
}
+ @Test
public void testBetween() {
NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L');
@@ -41,6 +45,7 @@
assertEquals("Failed to escape numeric entities via the between method", "ADFGZ", result);
}
+ @Test
public void testAbove() {
NumericEntityEscaper nee = NumericEntityEscaper.above('F');
@@ -50,6 +55,7 @@
}
// See LANG-617
+ @Test
public void testSupplementary() {
NumericEntityEscaper nee = new NumericEntityEscaper();
String input = "\uD803\uDC22";
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java b/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
index 2310dcf..cb80ef6 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
@@ -17,14 +17,18 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityUnescaper}.
* @version $Id$
*/
-public class NumericEntityUnescaperTest extends TestCase {
+public class NumericEntityUnescaperTest {
+ @Test
public void testSupplementaryUnescaping() {
NumericEntityUnescaper neu = new NumericEntityUnescaper();
String input = "𐰢";
@@ -34,6 +38,7 @@
assertEquals("Failed to unescape numeric entities supplementary characters", expected, result);
}
+ @Test
public void testOutOfBounds() {
NumericEntityUnescaper neu = new NumericEntityUnescaper();
@@ -43,6 +48,7 @@
assertEquals("Failed to ignore when last character is &", "Test &#X", neu.translate("Test &#X"));
}
+ @Test
public void testUnfinishedEntity() {
// parse it
NumericEntityUnescaper neu = new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.semiColonOptional);
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java b/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java
index 9f8ddd3..91c6479 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java
@@ -17,14 +17,16 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.OctalUnescaper}.
* @version $Id: OctalUnescaperTest.java 979392 2010-07-26 18:09:52Z mbenson $
*/
-public class OctalUnescaperTest extends TestCase {
+public class OctalUnescaperTest {
+ @Test
public void testBetween() {
OctalUnescaper oue = new OctalUnescaper(); //.between("1", "377");
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java b/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
index efa92cc..7dfe322 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
@@ -17,14 +17,17 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
* @version $Id$
*/
-public class UnicodeEscaperTest extends TestCase {
+public class UnicodeEscaperTest {
+ @Test
public void testBelow() {
UnicodeEscaper ue = UnicodeEscaper.below('F');
@@ -33,6 +36,7 @@
assertEquals("Failed to escape Unicode characters via the below method", "\\u0041\\u0044FGZ", result);
}
+ @Test
public void testBetween() {
UnicodeEscaper ue = UnicodeEscaper.between('F', 'L');
@@ -41,6 +45,7 @@
assertEquals("Failed to escape Unicode characters via the between method", "AD\\u0046\\u0047Z", result);
}
+ @Test
public void testAbove() {
UnicodeEscaper ue = UnicodeEscaper.above('F');
diff --git a/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java b/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java
index fb4d6c8..ed882aa 100644
--- a/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java
@@ -17,15 +17,19 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
* @version $Id$
*/
-public class UnicodeUnescaperTest extends TestCase {
+public class UnicodeUnescaperTest {
// Requested in LANG-507
+ @Test
public void testUPlus() {
UnicodeUnescaper uu = new UnicodeUnescaper();
@@ -33,6 +37,7 @@
assertEquals("Failed to unescape Unicode characters with 'u+' notation", "G", uu.translate(input));
}
+ @Test
public void testUuuuu() {
UnicodeUnescaper uu = new UnicodeUnescaper();
@@ -41,6 +46,7 @@
assertEquals("Failed to unescape Unicode characters with many 'u' characters", "G", result);
}
+ @Test
public void testLessThanFour() {
UnicodeUnescaper uu = new UnicodeUnescaper();
diff --git a/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
index 9222ad8..5b7f789 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
@@ -16,25 +16,22 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
-import junit.framework.TestCase;
-
/**
* TestCase for DateFormatUtils.
*
*/
-public class DateFormatUtilsTest extends TestCase {
-
- public DateFormatUtilsTest(String s) {
- super(s);
- }
+public class DateFormatUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new DateFormatUtils());
Constructor<?>[] cons = DateFormatUtils.class.getDeclaredConstructors();
@@ -45,6 +42,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testFormat() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(2005,0,1,12,0,0);
@@ -68,6 +66,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testFormatCalendar() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(2005,0,1,12,0,0);
@@ -90,6 +89,7 @@
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US));
}
+ @Test
public void testFormatUTC() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(2005,0,1,12,0,0);
@@ -102,6 +102,7 @@
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US));
}
+ @Test
public void testDateTimeISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -125,6 +126,7 @@
assertEquals("2002-02-23T09:11:12-03:00", text);
}
+ @Test
public void testDateISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -148,6 +150,7 @@
assertEquals("2002-02-23-03:00", text);
}
+ @Test
public void testTimeISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -171,6 +174,7 @@
assertEquals("T10:11:12-03:00", text);
}
+ @Test
public void testTimeNoTISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -194,6 +198,7 @@
assertEquals("10:11:12-03:00", text);
}
+ @Test
public void testSMTP(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
index 97f4de1..6b05aaf 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
@@ -16,12 +16,13 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.util.Calendar;
import java.util.Date;
-import junit.framework.TestCase;
-
-public class DateUtilsFragmentTest extends TestCase {
+public class DateUtilsFragmentTest {
private static final int months = 7; // second final prime before 12
private static final int days = 23; // second final prime before 31 (and valid)
@@ -33,14 +34,16 @@
private Date aDate;
private Calendar aCalendar;
- @Override
- protected void setUp() {
+
+ @Before
+ public void setUp() {
aCalendar = Calendar.getInstance();
aCalendar.set(2005, months, days, hours, minutes, seconds);
aCalendar.set(Calendar.MILLISECOND, millis);
aDate = aCalendar.getTime();
}
+ @Test
public void testNullDate() {
try {
DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND);
@@ -68,6 +71,7 @@
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testNullCalendar() {
try {
DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND);
@@ -95,6 +99,7 @@
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testInvalidFragmentWithDate() {
try {
DateUtils.getFragmentInMilliseconds(aDate, 0);
@@ -122,6 +127,7 @@
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testInvalidFragmentWithCalendar() {
try {
DateUtils.getFragmentInMilliseconds(aCalendar, 0);
@@ -149,6 +155,7 @@
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testMillisecondFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInMilliseconds(aDate, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.MILLISECOND));
@@ -157,6 +164,7 @@
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MILLISECOND));
}
+ @Test
public void testMillisecondFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.MILLISECOND));
@@ -165,6 +173,7 @@
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MILLISECOND));
}
+ @Test
public void testSecondFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.SECOND));
@@ -172,6 +181,7 @@
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.SECOND));
}
+ @Test
public void testSecondFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.SECOND));
@@ -179,51 +189,61 @@
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.SECOND));
}
+ @Test
public void testMinuteFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MINUTE));
}
+ @Test
public void testMinuteFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MINUTE));
}
+ @Test
public void testHourOfDayFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.HOUR_OF_DAY));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.HOUR_OF_DAY));
}
+ @Test
public void testHourOfDayFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.HOUR_OF_DAY));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.HOUR_OF_DAY));
}
+ @Test
public void testDayOfYearFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DAY_OF_YEAR));
}
+ @Test
public void testDayOfYearFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DAY_OF_YEAR));
}
+ @Test
public void testDateFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DATE));
}
+ @Test
public void testDateFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DATE));
}
//Calendar.SECOND as useful fragment
+ @Test
public void testMillisecondsOfSecondWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.SECOND);
assertEquals(millis, testResult);
}
+ @Test
public void testMillisecondsOfSecondWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.SECOND);
assertEquals(millis, testResult);
@@ -232,21 +252,25 @@
//Calendar.MINUTE as useful fragment
+ @Test
public void testMillisecondsOfMinuteWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
}
+ @Test
public void testMillisecondsOfMinuteWithCalender() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
}
+ @Test
public void testSecondsofMinuteWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MINUTE);
assertEquals(seconds, testResult);
}
+ @Test
public void testSecondsofMinuteWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MINUTE);
assertEquals(seconds, testResult);
@@ -255,16 +279,19 @@
//Calendar.HOUR_OF_DAY as useful fragment
+ @Test
public void testMillisecondsOfHourWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
}
+ @Test
public void testMillisecondsOfHourWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
}
+ @Test
public void testSecondsofHourWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals(
@@ -274,6 +301,7 @@
testResult);
}
+ @Test
public void testSecondsofHourWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(
@@ -283,17 +311,20 @@
testResult);
}
+ @Test
public void testMinutesOfHourWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.HOUR_OF_DAY);
assertEquals(minutes, testResult);
}
+ @Test
public void testMinutesOfHourWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(minutes, testResult);
}
//Calendar.DATE and Calendar.DAY_OF_YEAR as useful fragment
+ @Test
public void testMillisecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE);
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
@@ -302,6 +333,7 @@
assertEquals(expectedValue, testresult);
}
+ @Test
public void testMillisecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE);
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
@@ -310,6 +342,7 @@
assertEquals(expectedValue, testresult);
}
+ @Test
public void testSecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE);
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
@@ -318,6 +351,7 @@
assertEquals(expectedValue, testresult);
}
+ @Test
public void testSecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE);
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
@@ -326,6 +360,7 @@
assertEquals(expectedValue, testresult);
}
+ @Test
public void testMinutesOfDayWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE);
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
@@ -334,6 +369,7 @@
assertEquals(expectedValue,testResult);
}
+ @Test
public void testMinutesOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE);
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
@@ -342,6 +378,7 @@
assertEquals(expectedValue, testResult);
}
+ @Test
public void testHoursOfDayWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.DATE);
long expectedValue = hours;
@@ -350,6 +387,7 @@
assertEquals(expectedValue,testResult);
}
+ @Test
public void testHoursOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DATE);
long expectedValue = hours;
@@ -360,6 +398,7 @@
//Calendar.MONTH as useful fragment
+ @Test
public void testMillisecondsOfMonthWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
@@ -367,6 +406,7 @@
testResult);
}
+ @Test
public void testMillisecondsOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
@@ -374,6 +414,7 @@
testResult);
}
+ @Test
public void testSecondsOfMonthWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH);
assertEquals(
@@ -384,6 +425,7 @@
testResult);
}
+ @Test
public void testSecondsOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH);
assertEquals(
@@ -394,6 +436,7 @@
testResult);
}
+ @Test
public void testMinutesOfMonthWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH);
assertEquals(minutes
@@ -402,6 +445,7 @@
testResult);
}
+ @Test
public void testMinutesOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
@@ -409,6 +453,7 @@
testResult);
}
+ @Test
public void testHoursOfMonthWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY))
@@ -416,6 +461,7 @@
testResult);
}
+ @Test
public void testHoursOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY))
@@ -424,6 +470,7 @@
}
//Calendar.YEAR as useful fragment
+ @Test
public void testMillisecondsOfYearWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -433,6 +480,7 @@
testResult);
}
+ @Test
public void testMillisecondsOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
@@ -440,6 +488,7 @@
testResult);
}
+ @Test
public void testSecondsOfYearWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -452,6 +501,7 @@
testResult);
}
+ @Test
public void testSecondsOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR);
assertEquals(
@@ -462,6 +512,7 @@
testResult);
}
+ @Test
public void testMinutesOfYearWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -472,6 +523,7 @@
testResult);
}
+ @Test
public void testMinutesOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
@@ -479,6 +531,7 @@
testResult);
}
+ @Test
public void testHoursOfYearWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -488,6 +541,7 @@
testResult);
}
+ @Test
public void testHoursOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR);
assertEquals( hours +((aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
index cede226..0c92d2c 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
@@ -16,14 +16,15 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
-
/**
* These Unit-tests will check all possible extremes when using some rounding-methods of DateUtils.
* The extremes are tested at the switch-point in milliseconds
@@ -37,7 +38,7 @@
* @since 3.0
* @version $Id$
*/
-public class DateUtilsRoundingTest extends TestCase {
+public class DateUtilsRoundingTest {
DateFormat dateTimeParser;
@@ -53,9 +54,10 @@
Calendar januaryOneCalendar;
FastDateFormat fdf = DateFormatUtils.ISO_DATETIME_FORMAT;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+
+ @Before
+ public void setUp() throws Exception {
+
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
targetYearDate = dateTimeParser.parse("January 1, 2007 0:00:00.000");
@@ -79,6 +81,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundYear() throws Exception {
final int calendarField = Calendar.YEAR;
Date roundedUpDate = dateTimeParser.parse("January 1, 2008 0:00:00.000");
@@ -95,6 +98,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundMonth() throws Exception {
final int calendarField = Calendar.MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -138,6 +142,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundSemiMonth() throws Exception {
final int calendarField = DateUtils.SEMI_MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -205,6 +210,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundDate() throws Exception {
final int calendarField = Calendar.DATE;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -229,6 +235,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundDayOfMonth() throws Exception {
final int calendarField = Calendar.DAY_OF_MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -253,6 +260,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundAmPm() throws Exception {
final int calendarField = Calendar.AM_PM;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -284,6 +292,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundHourOfDay() throws Exception {
final int calendarField = Calendar.HOUR_OF_DAY;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -308,6 +317,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundHour() throws Exception {
final int calendarField = Calendar.HOUR;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -332,6 +342,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundMinute() throws Exception {
final int calendarField = Calendar.MINUTE;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -356,6 +367,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundSecond() throws Exception {
final int calendarField = Calendar.SECOND;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -380,6 +392,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundMilliSecond() throws Exception {
final int calendarField = Calendar.MILLISECOND;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -400,6 +413,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateYear() throws Exception {
final int calendarField = Calendar.YEAR;
Date lastTruncateDate = dateTimeParser.parse("December 31, 2007 23:59:59.999");
@@ -412,6 +426,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateMonth() throws Exception {
final int calendarField = Calendar.MONTH;
Date truncatedDate = dateTimeParser.parse("March 1, 2008 0:00:00.000");
@@ -426,6 +441,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateSemiMonth() throws Exception {
final int calendarField = DateUtils.SEMI_MONTH;
Date truncatedDate, lastTruncateDate;
@@ -478,6 +494,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateDate() throws Exception {
final int calendarField = Calendar.DATE;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
@@ -490,6 +507,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateDayOfMonth() throws Exception {
final int calendarField = Calendar.DAY_OF_MONTH;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
@@ -503,6 +521,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateAmPm() throws Exception {
final int calendarField = Calendar.AM_PM;
@@ -521,6 +540,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateHour() throws Exception {
final int calendarField = Calendar.HOUR;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:59:59.999");
@@ -533,6 +553,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateHourOfDay() throws Exception {
final int calendarField = Calendar.HOUR_OF_DAY;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:59:59.999");
@@ -545,6 +566,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateMinute() throws Exception {
final int calendarField = Calendar.MINUTE;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:15:59.999");
@@ -557,6 +579,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateSecond() throws Exception {
final int calendarField = Calendar.SECOND;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:15:14.999");
@@ -569,6 +592,7 @@
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateMilliSecond() throws Exception {
final int calendarField = Calendar.MILLISECOND;
baseTruncateTest(targetMilliSecondDate, targetMilliSecondDate, calendarField);
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
index 8828a8b..915ecde 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
import java.lang.reflect.Constructor;
@@ -32,15 +35,13 @@
import java.util.TimeZone;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.SystemUtils;
/**
* Unit tests {@link org.apache.commons.lang3.time.DateUtils}.
*
*/
-public class DateUtilsTest extends TestCase {
+public class DateUtilsTest {
private static final long MILLIS_TEST;
static {
@@ -80,13 +81,10 @@
TimeZone zone = null;
TimeZone defaultZone = null;
- public DateUtilsTest(String name) {
- super(name);
- }
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+
dateParser = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
@@ -139,6 +137,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new DateUtils());
Constructor<?>[] cons = DateUtils.class.getDeclaredConstructors();
@@ -149,6 +148,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameDay_Date() {
Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
@@ -166,6 +166,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameDay_Cal() {
GregorianCalendar cal1 = new GregorianCalendar(2004, 6, 9, 13, 45);
GregorianCalendar cal2 = new GregorianCalendar(2004, 6, 9, 13, 45);
@@ -183,6 +184,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameInstant_Date() {
Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
@@ -200,6 +202,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameInstant_Cal() {
GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT-1"));
@@ -218,6 +221,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameLocalTime_Cal() {
GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT-1"));
@@ -244,6 +248,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testParseDate() throws Exception {
GregorianCalendar cal = new GregorianCalendar(1972, 11, 3);
String dateStr = "1972-12-03";
@@ -281,6 +286,7 @@
} catch (ParseException ex) {}
}
// LANG-486
+ @Test
public void testParseDateWithLeniency() throws Exception {
GregorianCalendar cal = new GregorianCalendar(1998, 6, 30);
String dateStr = "02 942, 1996";
@@ -296,6 +302,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddYears() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addYears(base, 0);
@@ -315,6 +322,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddMonths() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addMonths(base, 0);
@@ -334,6 +342,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddWeeks() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addWeeks(base, 0);
@@ -353,6 +362,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddDays() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addDays(base, 0);
@@ -372,6 +382,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddHours() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addHours(base, 0);
@@ -391,6 +402,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddMinutes() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addMinutes(base, 0);
@@ -410,6 +422,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddSeconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addSeconds(base, 0);
@@ -429,6 +442,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testAddMilliseconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addMilliseconds(base, 0);
@@ -448,6 +462,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetYears() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setYears(base, 2000);
@@ -467,6 +482,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetMonths() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMonths(base, 5);
@@ -488,6 +504,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetDays() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setDays(base, 1);
@@ -509,6 +526,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetHours() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setHours(base, 0);
@@ -530,6 +548,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetMinutes() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMinutes(base, 0);
@@ -551,6 +570,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetSeconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setSeconds(base, 0);
@@ -572,6 +592,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testSetMilliseconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMilliseconds(base, 0);
@@ -606,6 +627,7 @@
}
//-----------------------------------------------------------------------
+ @Test
public void testToCalendar() {
assertEquals("Failed to convert to a Calendar and back", date1, DateUtils.toCalendar(date1).getTime());
try {
@@ -620,6 +642,7 @@
/**
* Tests various values with the round method
*/
+ @Test
public void testRound() throws Exception {
// tests for public static Date round(Date date, int field)
assertEquals("round year-1 failed",
@@ -843,6 +866,7 @@
* Tests the Changes Made by LANG-346 to the DateUtils.modify() private method invoked
* by DateUtils.round().
*/
+ @Test
public void testRoundLang346() throws Exception
{
TimeZone.setDefault(defaultZone);
@@ -905,6 +929,7 @@
/**
* Tests various values with the trunc method
*/
+ @Test
public void testTruncate() throws Exception {
// tests public static Date truncate(Date date, int field)
assertEquals("truncate year-1 failed",
@@ -1098,6 +1123,7 @@
*
* see http://issues.apache.org/jira/browse/LANG-59
*/
+ @Test
public void testTruncateLang59() throws Exception {
if (!SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) {
this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION);
@@ -1173,6 +1199,7 @@
}
// http://issues.apache.org/jira/browse/LANG-530
+ @Test
public void testLang530() throws ParseException {
Date d = new Date();
String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
@@ -1184,6 +1211,7 @@
/**
* Tests various values with the ceiling method
*/
+ @Test
public void testCeil() throws Exception {
// test javadoc
assertEquals("ceiling javadoc-1 failed",
@@ -1433,6 +1461,7 @@
/**
* Tests the iterator exceptions
*/
+ @Test
public void testIteratorEx() throws Exception {
try {
DateUtils.iterator(Calendar.getInstance(), -9999);
@@ -1458,6 +1487,7 @@
/**
* Tests the calendar iterator for week ranges
*/
+ @Test
public void testWeekIterator() throws Exception {
Calendar now = Calendar.getInstance();
for (int i = 0; i< 7; i++) {
@@ -1504,6 +1534,7 @@
/**
* Tests the calendar iterator for month-based ranges
*/
+ @Test
public void testMonthIterator() throws Exception {
Iterator<?> it = DateUtils.iterator(date1, DateUtils.RANGE_MONTH_SUNDAY);
assertWeekIterator(it,
@@ -1556,12 +1587,12 @@
*/
private static void assertWeekIterator(Iterator<?> it, Calendar start, Calendar end) {
Calendar cal = (Calendar) it.next();
- assertEquals("", start, cal, 0);
+ assertCalendarsEquals("", start, cal, 0);
Calendar last = null;
int count = 1;
while (it.hasNext()) {
//Check this is just a date (no time component)
- assertEquals("", cal, DateUtils.truncate(cal, Calendar.DATE), 0);
+ assertCalendarsEquals("", cal, DateUtils.truncate(cal, Calendar.DATE), 0);
last = cal;
cal = (Calendar) it.next();
@@ -1569,19 +1600,19 @@
//Check that this is one day more than the last date
last.add(Calendar.DATE, 1);
- assertEquals("", last, cal, 0);
+ assertCalendarsEquals("", last, cal, 0);
}
if (count % 7 != 0) {
throw new AssertionFailedError("There were " + count + " days in this iterator");
}
- assertEquals("", end, cal, 0);
+ assertCalendarsEquals("", end, cal, 0);
}
/**
* Used to check that Calendar objects are close enough
* delta is in milliseconds
*/
- private static void assertEquals(String message, Calendar cal1, Calendar cal2, long delta) {
+ private static void assertCalendarsEquals(String message, Calendar cal1, Calendar cal2, long delta) {
if (Math.abs(cal1.getTime().getTime() - cal2.getTime().getTime()) > delta) {
throw new AssertionFailedError(
message + " expected " + cal1.getTime() + " but got " + cal2.getTime());
diff --git a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
index 20b65c6..8b31599 100644
--- a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
@@ -17,24 +17,21 @@
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Calendar;
import java.util.TimeZone;
-import junit.framework.TestCase;
-
/**
* TestCase for DurationFormatUtils.
*
*/
-public class DurationFormatUtilsTest extends TestCase {
-
- public DurationFormatUtilsTest(String s) {
- super(s);
- }
+public class DurationFormatUtilsTest {
// -----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new DurationFormatUtils());
Constructor<?>[] cons = DurationFormatUtils.class.getDeclaredConstructors();
@@ -45,6 +42,7 @@
}
// -----------------------------------------------------------------------
+ @Test
public void testFormatDurationWords() {
String text = null;
@@ -132,6 +130,7 @@
/**
* Tests that "1 <unit>s" gets converted to "1 <unit>" but that "11 <unit>s" is left alone.
*/
+ @Test
public void testFormatDurationPluralWords() {
long oneSecond = 1000;
long oneMinute = oneSecond * 60;
@@ -174,6 +173,7 @@
assertEquals("1 day 1 hour 1 minute 1 second", text);
}
+ @Test
public void testFormatDurationHMS() {
long time = 0;
assertEquals("0:00:00.000", DurationFormatUtils.formatDurationHMS(time));
@@ -203,6 +203,7 @@
assertEquals("1:02:12.789", DurationFormatUtils.formatDurationHMS(time));
}
+ @Test
public void testFormatDurationISO() {
assertEquals("P0Y0M0DT0H0M0.000S", DurationFormatUtils.formatDurationISO(0L));
assertEquals("P0Y0M0DT0H0M0.001S", DurationFormatUtils.formatDurationISO(1L));
@@ -211,6 +212,7 @@
assertEquals("P0Y0M0DT0H1M15.321S", DurationFormatUtils.formatDurationISO(75321L));
}
+ @Test
public void testFormatDuration() {
long duration = 0;
assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
@@ -248,6 +250,7 @@
assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
}
+ @Test
public void testFormatPeriodISO() {
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar base = Calendar.getInstance(timeZone);
@@ -275,6 +278,7 @@
// assertEquals("P1Y2M3DT10H30M", text);
}
+ @Test
public void testFormatPeriod() {
Calendar cal1970 = Calendar.getInstance();
cal1970.set(1970, 0, 1, 0, 0, 0);
@@ -328,6 +332,7 @@
assertEquals("048", DurationFormatUtils.formatPeriod(time1970, time, "MMM"));
}
+ @Test
public void testLexx() {
// tests each constant
assertArrayEquals(new DurationFormatUtils.Token[]{
@@ -381,18 +386,21 @@
// http://issues.apache.org/bugzilla/show_bug.cgi?id=38401
+ @Test
public void testBugzilla38401() {
assertEqualDuration( "0000/00/30 16:00:00 000", new int[] { 2006, 0, 26, 18, 47, 34 },
new int[] { 2006, 1, 26, 10, 47, 34 }, "yyyy/MM/dd HH:mm:ss SSS");
}
// https://issues.apache.org/jira/browse/LANG-281
+ @Test
public void testJiraLang281() {
assertEqualDuration( "09", new int[] { 2005, 11, 31, 0, 0, 0 },
new int[] { 2006, 9, 6, 0, 0, 0 }, "MM");
}
// Testing the under a day range in DurationFormatUtils.formatPeriod
+ @Test
public void testLowDurations() {
for(int hr=0; hr < 24; hr++) {
for(int min=0; min < 60; min++) {
@@ -408,6 +416,7 @@
}
// Attempting to test edge cases in DurationFormatUtils.formatPeriod
+ @Test
public void testEdgeDurations() {
assertEqualDuration( "01", new int[] { 2006, 0, 15, 0, 0, 0 },
new int[] { 2006, 2, 10, 0, 0, 0 }, "MM");
@@ -497,6 +506,7 @@
}
+ @Test
public void testDurationsByBruteForce() {
bruteForce(2006, 0, 1, "d", Calendar.DAY_OF_MONTH);
bruteForce(2006, 0, 2, "d", Calendar.DAY_OF_MONTH);
diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
index 07f141e..bec23b9 100644
--- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
@@ -16,21 +16,22 @@
*/
package org.apache.commons.lang3.time;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import junit.framework.Assert;
-import junit.framework.TestCase;
+
+import org.junit.Test;
/**
* TestCase for StopWatch.
*
* @version $Id$
*/
-public class StopWatchTest extends TestCase {
-
- public StopWatchTest(String s) {
- super(s);
- }
+public class StopWatchTest {
//-----------------------------------------------------------------------
+ @Test
public void testStopWatchSimple(){
StopWatch watch = new StopWatch();
watch.start();
@@ -46,6 +47,7 @@
assertEquals(0, watch.getTime());
}
+ @Test
public void testStopWatchSimpleGet(){
StopWatch watch = new StopWatch();
assertEquals(0, watch.getTime());
@@ -56,6 +58,7 @@
assertTrue(watch.getTime() < 2000);
}
+ @Test
public void testStopWatchSplit(){
StopWatch watch = new StopWatch();
watch.start();
@@ -77,6 +80,7 @@
assertTrue(totalTime < 1900);
}
+ @Test
public void testStopWatchSuspend(){
StopWatch watch = new StopWatch();
watch.start();
@@ -95,6 +99,7 @@
assertTrue(totalTime < 1300);
}
+ @Test
public void testLang315() {
StopWatch watch = new StopWatch();
watch.start();
@@ -108,6 +113,7 @@
}
// test bad states
+ @Test
public void testBadStates() {
StopWatch watch = new StopWatch();
try {
@@ -192,6 +198,7 @@
}
}
+ @Test
public void testGetStartTime() {
long beforeStopWatch = System.currentTimeMillis();
StopWatch watch = new StopWatch();