Additional tests as suggested by Clover report

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-07-30 22:21:39 +00:00
parent 35b8cc4ce3
commit c7767ea25b
13 changed files with 275 additions and 35 deletions

View File

@ -53,6 +53,8 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Map;
@ -68,7 +70,7 @@ import junit.textui.TestRunner;
* @author Moritz Petersen
* @author Nikolay Metchev
* @author Matthew Hawthorne
* @version $Id: ArrayUtilsTest.java,v 1.9 2003/07/12 10:09:40 scolebourne Exp $
* @version $Id: ArrayUtilsTest.java,v 1.10 2003/07/30 22:21:39 scolebourne Exp $
*/
public class ArrayUtilsTest extends TestCase {
@ -94,6 +96,16 @@ public class ArrayUtilsTest extends TestCase {
super.tearDown();
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new ArrayUtils());
Constructor[] cons = ArrayUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(ArrayUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(ArrayUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void testToString() {
assertEquals("{}", ArrayUtils.toString(null));
@ -195,6 +207,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneBoolean() {
assertEquals(null, ArrayUtils.clone((boolean[]) null));
boolean[] original = new boolean[] {true, false};
boolean[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -202,6 +215,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneLong() {
assertEquals(null, ArrayUtils.clone((long[]) null));
long[] original = new long[] {0L, 1L};
long[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -209,6 +223,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneInt() {
assertEquals(null, ArrayUtils.clone((int[]) null));
int[] original = new int[] {5, 8};
int[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -216,6 +231,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneShort() {
assertEquals(null, ArrayUtils.clone((short[]) null));
short[] original = new short[] {1, 4};
short[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -223,6 +239,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneChar() {
assertEquals(null, ArrayUtils.clone((char[]) null));
char[] original = new char[] {'a', '4'};
char[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -230,6 +247,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneByte() {
assertEquals(null, ArrayUtils.clone((byte[]) null));
byte[] original = new byte[] {1, 6};
byte[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -237,6 +255,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneDouble() {
assertEquals(null, ArrayUtils.clone((double[]) null));
double[] original = new double[] {2.4d, 5.7d};
double[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -244,6 +263,7 @@ public class ArrayUtilsTest extends TestCase {
}
public void testCloneFloat() {
assertEquals(null, ArrayUtils.clone((float[]) null));
float[] original = new float[] {2.6f, 6.4f};
float[] cloned = ArrayUtils.clone(original);
assertTrue(Arrays.equals(original, cloned));
@ -642,6 +662,7 @@ public class ArrayUtilsTest extends TestCase {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(-1, ArrayUtils.indexOf(null, null));
assertEquals(-1, ArrayUtils.indexOf(null, "0"));
assertEquals(-1, ArrayUtils.indexOf(new Object[0], "0"));
assertEquals(0, ArrayUtils.indexOf(array, "0"));
assertEquals(1, ArrayUtils.indexOf(array, "1"));
assertEquals(2, ArrayUtils.indexOf(array, "2"));
@ -653,6 +674,7 @@ public class ArrayUtilsTest extends TestCase {
public void testIndexOfWithStartIndex() {
Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
assertEquals(-1, ArrayUtils.indexOf(null, null, 2));
assertEquals(-1, ArrayUtils.indexOf(new Object[0], "0", 0));
assertEquals(-1, ArrayUtils.indexOf(null, "0", 2));
assertEquals(5, ArrayUtils.indexOf(array, "0", 2));
assertEquals(-1, ArrayUtils.indexOf(array, "1", 2));
@ -685,6 +707,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, "1", 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, "2", 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, "3", 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, "3", -1));
assertEquals(4, ArrayUtils.lastIndexOf(array, null, 5));
assertEquals(-1, ArrayUtils.lastIndexOf(array, null, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, "notInArray", 5));
@ -725,6 +748,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
}
@ -748,7 +772,8 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 99, 4));
assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
}
@ -783,6 +808,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
}
@ -806,6 +832,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
}
@ -841,6 +868,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(-1, ArrayUtils.indexOf(array, (short) 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, (short) 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, (short) 3, 2));
assertEquals(3, ArrayUtils.indexOf(array, (short) 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, (short) 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 6));
}
@ -864,6 +892,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, (short) 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, (short) 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, (short) 0, 88));
}
@ -899,6 +928,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, (byte) 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, (byte) 3, 2));
assertEquals(3, ArrayUtils.indexOf(array, (byte) 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 6));
}
@ -922,6 +952,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, (byte) 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, (byte) 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, (byte) 0, 88));
}
@ -946,6 +977,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.indexOf(array, (double) 1));
assertEquals(2, ArrayUtils.indexOf(array, (double) 2));
assertEquals(3, ArrayUtils.indexOf(array, (double) 3));
assertEquals(3, ArrayUtils.indexOf(array, (double) 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, (double) 99));
}
@ -980,6 +1012,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 88));
}
@ -1015,6 +1048,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(-1, ArrayUtils.indexOf(array, (float) 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, (float) 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, (float) 3, 2));
assertEquals(3, ArrayUtils.indexOf(array, (float) 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, (float) 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 6));
}
@ -1038,6 +1072,7 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0, 88));
}
@ -1070,8 +1105,11 @@ public class ArrayUtilsTest extends TestCase {
array = new boolean[] { true, false, true };
assertEquals(2, ArrayUtils.indexOf(array, true, 1));
assertEquals(-1, ArrayUtils.indexOf(array, false, 2));
assertEquals(1, ArrayUtils.indexOf(array, false, 0));
assertEquals(1, ArrayUtils.indexOf(array, false, -1));
array = new boolean[] { true, true };
assertEquals(-1, ArrayUtils.indexOf(array, false, 0));
assertEquals(-1, ArrayUtils.indexOf(array, false, -1));
}
public void testLastIndexOfBoolean() {
@ -1091,8 +1129,10 @@ public class ArrayUtilsTest extends TestCase {
assertEquals(2, ArrayUtils.lastIndexOf(array, true, 2));
assertEquals(0, ArrayUtils.lastIndexOf(array, true, 1));
assertEquals(1, ArrayUtils.lastIndexOf(array, false, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
array = new boolean[] { true, true };
assertEquals(-1, ArrayUtils.lastIndexOf(array, false, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
}
public void testContainsBoolean() {

View File

@ -53,6 +53,9 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -63,7 +66,7 @@ import junit.textui.TestRunner;
*
* @author Stephen Colebourne
* @author Matthew Hawthorne
* @version $Id: BooleanUtilsTest.java,v 1.4 2003/06/28 18:16:03 scolebourne Exp $
* @version $Id: BooleanUtilsTest.java,v 1.5 2003/07/30 22:21:39 scolebourne Exp $
*/
public class BooleanUtilsTest extends TestCase {
@ -89,6 +92,16 @@ public class BooleanUtilsTest extends TestCase {
super.tearDown();
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new BooleanUtils());
Constructor[] cons = BooleanUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(BooleanUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(BooleanUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void test_negate_Boolean() {
assertSame(null, BooleanUtils.negate(null));
@ -151,6 +164,14 @@ public class BooleanUtilsTest extends TestCase {
public void test_toBoolean_Integer_Integer_Integer() {
Integer six = new Integer(6);
Integer seven = new Integer(7);
assertEquals(true, BooleanUtils.toBoolean((Integer) null, null, seven));
assertEquals(false, BooleanUtils.toBoolean((Integer) null, six, null));
try {
BooleanUtils.toBoolean(null, six, seven);
fail();
} catch (IllegalArgumentException ex) {}
assertEquals(true, BooleanUtils.toBoolean(new Integer(6), six, seven));
assertEquals(false, BooleanUtils.toBoolean(new Integer(7), six, seven));
try {
@ -170,10 +191,19 @@ public class BooleanUtilsTest extends TestCase {
} catch (IllegalArgumentException ex) {}
}
public void test_toBooleanObject_Integer_Integer_Integer() {
public void test_toBooleanObject_Integer_Integer_Integer_Integer() {
Integer six = new Integer(6);
Integer seven = new Integer(7);
Integer eight = new Integer(8);
assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((Integer) null, null, seven, eight));
assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((Integer) null, six, null, eight));
assertSame(null, BooleanUtils.toBooleanObject((Integer) null, six, seven, null));
try {
BooleanUtils.toBooleanObject(null, six, seven, eight);
fail();
} catch (IllegalArgumentException ex) {}
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(new Integer(6), six, seven, eight));
assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(new Integer(7), six, seven, eight));
assertEquals(null, BooleanUtils.toBooleanObject(new Integer(8), six, seven, eight));
@ -251,6 +281,14 @@ public class BooleanUtilsTest extends TestCase {
}
public void test_toBooleanObject_String_String_String_String() {
assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((String) null, null, "N", "U"));
assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((String) null, "Y", null, "U"));
assertSame(null, BooleanUtils.toBooleanObject((String) null, "Y", "N", null));
try {
BooleanUtils.toBooleanObject((String) null, "Y", "N", "U");
fail();
} catch (IllegalArgumentException ex) {}
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("Y", "Y", "N", "U"));
assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("N", "Y", "N", "U"));
assertEquals(null, BooleanUtils.toBooleanObject("U", "Y", "N", "U"));
@ -280,6 +318,13 @@ public class BooleanUtilsTest extends TestCase {
}
public void test_toBoolean_String_String_String() {
assertEquals(true, BooleanUtils.toBoolean((String) null, null, "N"));
assertEquals(false, BooleanUtils.toBoolean((String) null, "Y", null));
try {
BooleanUtils.toBooleanObject((String) null, "Y", "N", "U");
fail();
} catch (IllegalArgumentException ex) {}
assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "N"));
assertEquals(false, BooleanUtils.toBoolean("N", "Y", "N"));
try {

View File

@ -53,6 +53,9 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -64,7 +67,7 @@ import junit.textui.TestRunner;
* @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @author Stephen Colebourne
* @version $Id: CharSetUtilsTest.java,v 1.9 2003/07/30 00:08:38 scolebourne Exp $
* @version $Id: CharSetUtilsTest.java,v 1.10 2003/07/30 22:21:39 scolebourne Exp $
*/
public class CharSetUtilsTest extends TestCase {
@ -91,7 +94,16 @@ public class CharSetUtilsTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new CharSetUtils());
Constructor[] cons = CharSetUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(CharSetUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(CharSetUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void testSqueeze() {
assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
assertEquals(null, CharSetUtils.squeeze(null, (String) null));

View File

@ -53,6 +53,8 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -66,7 +68,7 @@ import junit.textui.TestRunner;
* Unit tests {@link org.apache.commons.lang.ClassUtils}.
*
* @author Stephen Colebourne
* @version $Id: ClassUtilsTest.java,v 1.3 2003/03/23 21:47:30 scolebourne Exp $
* @version $Id: ClassUtilsTest.java,v 1.4 2003/07/30 22:21:39 scolebourne Exp $
*/
public class ClassUtilsTest extends TestCase {
@ -95,6 +97,16 @@ public class ClassUtilsTest extends TestCase {
private static class Inner {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new ClassUtils());
Constructor[] cons = ClassUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(ClassUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(ClassUtils.class.getModifiers()));
}
// -------------------------------------------------------------------------
public void test_getShortClassName_Object() {
assertEquals("ClassUtils", ClassUtils.getShortClassName(new ClassUtils(), "<null>"));
@ -231,11 +243,13 @@ public class ClassUtilsTest extends TestCase {
assertEquals(0, result.size());
list.add(String.class);
list.add(null);
list.add(Object.class);
result = ClassUtils.convertClassesToClassNames(list);
assertEquals(2, result.size());
assertEquals(3, result.size());
assertEquals("java.lang.String", result.get(0));
assertEquals("java.lang.Object", result.get(1));
assertEquals(null, result.get(1));
assertEquals("java.lang.Object", result.get(2));
list.add(new Object());
try {

View File

@ -53,6 +53,9 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -65,7 +68,7 @@ import junit.textui.TestRunner;
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @version $Id: ObjectUtilsTest.java,v 1.7 2003/07/25 22:37:59 scolebourne Exp $
* @version $Id: ObjectUtilsTest.java,v 1.8 2003/07/30 22:21:39 scolebourne Exp $
*/
public class ObjectUtilsTest extends TestCase {
private static final String FOO = "foo";
@ -94,7 +97,16 @@ public class ObjectUtilsTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new ObjectUtils());
Constructor[] cons = ObjectUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(ObjectUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(ObjectUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void testIsNull() {
Object o = FOO;
Object dflt = BAR;

View File

@ -53,6 +53,8 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Random;
import junit.framework.Test;
@ -65,7 +67,7 @@ import junit.textui.TestRunner;
* @author <a href="mailto:steven@caswell.name">Steven Caswell</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @author Phil Steitz
* @version $Id: RandomStringUtilsTest.java,v 1.8 2003/07/20 15:49:58 scolebourne Exp $
* @version $Id: RandomStringUtilsTest.java,v 1.9 2003/07/30 22:21:39 scolebourne Exp $
*/
public class RandomStringUtilsTest extends junit.framework.TestCase {
/**
@ -93,6 +95,17 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
public void tearDown() {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new RandomStringUtils());
Constructor[] cons = RandomStringUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(RandomStringUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(RandomStringUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
/**
* Test the implementation
*/

View File

@ -57,6 +57,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import junit.framework.Test;
@ -69,7 +71,7 @@ import junit.textui.TestRunner;
*
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @version $Id: SerializationUtilsTest.java,v 1.3 2003/07/19 20:22:36 scolebourne Exp $
* @version $Id: SerializationUtilsTest.java,v 1.4 2003/07/30 22:21:39 scolebourne Exp $
*/
public class SerializationUtilsTest extends TestCase {
private String iString;
@ -105,7 +107,37 @@ public class SerializationUtilsTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new SerializationUtils());
Constructor[] cons = SerializationUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(SerializationUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(SerializationUtils.class.getModifiers()));
}
public void testException() {
SerializationException serEx;
Exception ex = new Exception();
serEx = new SerializationException();
assertSame(null, serEx.getMessage());
assertSame(null, serEx.getCause());
serEx = new SerializationException("Message");
assertSame("Message", serEx.getMessage());
assertSame(null, serEx.getCause());
serEx = new SerializationException(ex);
assertEquals("java.lang.Exception", serEx.getMessage());
assertSame(ex, serEx.getCause());
serEx = new SerializationException("Message", ex);
assertSame("Message", serEx.getMessage());
assertSame(ex, serEx.getCause());
}
//-----------------------------------------------------------------------
public void testSerializeStream() throws Exception {
ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
SerializationUtils.serialize(iMap, streamTest);

View File

@ -54,6 +54,8 @@
package org.apache.commons.lang;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestCase;
@ -65,7 +67,7 @@ import junit.textui.TestRunner;
*
* @author of original StringUtilsTest.testEscape = ?
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
* @version $Id: StringEscapeUtilsTest.java,v 1.10 2003/07/30 00:08:38 scolebourne Exp $
* @version $Id: StringEscapeUtilsTest.java,v 1.11 2003/07/30 22:21:39 scolebourne Exp $
*/
public class StringEscapeUtilsTest extends TestCase {
private final static String FOO = "foo";
@ -85,7 +87,16 @@ public class StringEscapeUtilsTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new StringEscapeUtils());
Constructor[] cons = StringEscapeUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(StringEscapeUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(StringEscapeUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void testEscapeJava() throws IOException {
assertEquals(null, StringEscapeUtils.escapeJava(null));
try {

View File

@ -64,7 +64,7 @@ import junit.textui.TestRunner;
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @author Phil Steitz
* @version $Id: StringUtilsEqualsIndexOfTest.java,v 1.5 2003/07/26 14:36:30 scolebourne Exp $
* @version $Id: StringUtilsEqualsIndexOfTest.java,v 1.6 2003/07/30 22:21:39 scolebourne Exp $
*/
public class StringUtilsEqualsIndexOfTest extends TestCase {
private static final String FOO = "foo";
@ -315,6 +315,8 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
//-----------------------------------------------------------------------
public void testIndexOfAnyButChar() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0]));
assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0]));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'}));

View File

@ -64,7 +64,7 @@ import junit.textui.TestRunner;
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @author Phil Steitz
* @version $Id: StringUtilsSubstringTest.java,v 1.9 2003/07/25 22:22:30 scolebourne Exp $
* @version $Id: StringUtilsSubstringTest.java,v 1.10 2003/07/30 22:21:39 scolebourne Exp $
*/
public class StringUtilsSubstringTest extends TestCase {
private static final String FOO = "foo";
@ -98,14 +98,33 @@ public class StringUtilsSubstringTest extends TestCase {
//-----------------------------------------------------------------------
public void testSubstring2() {
public void testSubstring_StringInt() {
assertEquals(null, StringUtils.substring(null, 0));
assertEquals("", StringUtils.substring("", 0));
assertEquals("", StringUtils.substring("", 2));
assertEquals("", StringUtils.substring(SENTENCE, 80));
assertEquals(BAZ, StringUtils.substring(SENTENCE, 8));
assertEquals(BAZ, StringUtils.substring(SENTENCE, -3));
assertEquals(SENTENCE, StringUtils.substring(SENTENCE, 0));
assertEquals("abc", StringUtils.substring("abc", -4));
assertEquals("abc", StringUtils.substring("abc", -3));
assertEquals("bc", StringUtils.substring("abc", -2));
assertEquals("c", StringUtils.substring("abc", -1));
assertEquals("abc", StringUtils.substring("abc", 0));
assertEquals("bc", StringUtils.substring("abc", 1));
assertEquals("c", StringUtils.substring("abc", 2));
assertEquals("", StringUtils.substring("abc", 3));
assertEquals("", StringUtils.substring("abc", 4));
}
public void testSubstring3() {
public void testSubstring_StringIntInt() {
assertEquals(null, StringUtils.substring(null, 0, 0));
assertEquals(null, StringUtils.substring(null, 1, 2));
assertEquals("", StringUtils.substring("", 0, 0));
assertEquals("", StringUtils.substring("", 1, 2));
assertEquals("", StringUtils.substring("", -2, -1));
assertEquals("", StringUtils.substring(SENTENCE, 8, 6));
assertEquals(FOO, StringUtils.substring(SENTENCE, 0, 3));
assertEquals("o", StringUtils.substring(SENTENCE, -9, 3));
@ -115,17 +134,6 @@ public class StringUtilsSubstringTest extends TestCase {
assertEquals("", StringUtils.substring(SENTENCE, 2, 2));
assertEquals("b",StringUtils.substring("abc", -2, -1));
}
public void testSubstring4() {
assertEquals("", StringUtils.substring("",0));
assertEquals("", StringUtils.substring("",2));
assertEquals("", StringUtils.substring("",0,0));
assertEquals("", StringUtils.substring("",1,2));
assertEquals("", StringUtils.substring("",-2,-1));
assertEquals(null, StringUtils.substring(null,0));
assertEquals(null, StringUtils.substring(null,0,0));
assertEquals(null, StringUtils.substring(null,1,2));
}
public void testLeft_String() {
assertSame(null, StringUtils.left(null, -1));

View File

@ -53,6 +53,8 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Iterator;
@ -72,7 +74,7 @@ import junit.textui.TestRunner;
* @author Holger Krauth
* @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
* @author Phil Steitz
* @version $Id: StringUtilsTest.java,v 1.39 2003/07/25 22:22:30 scolebourne Exp $
* @version $Id: StringUtilsTest.java,v 1.40 2003/07/30 22:21:39 scolebourne Exp $
*/
public class StringUtilsTest extends TestCase {
@ -146,7 +148,16 @@ public class StringUtilsTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new StringUtils());
Constructor[] cons = StringUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(StringUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(StringUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
public void testCaseFunctions() {
assertEquals(null, StringUtils.upperCase(null));
assertEquals(null, StringUtils.lowerCase(null));
@ -221,6 +232,7 @@ public class StringUtilsTest extends TestCase {
public void testJoin_IteratorChar() {
assertEquals(null, StringUtils.join((Iterator) null, ','));
assertEquals(TEXT_LIST_CHAR, StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(), SEPARATOR_CHAR));
assertEquals("", StringUtils.join(Arrays.asList(NULL_ARRAY_LIST).iterator(), SEPARATOR_CHAR));
assertEquals("", StringUtils.join(Arrays.asList(EMPTY_ARRAY_LIST).iterator(), SEPARATOR_CHAR));
}
@ -452,6 +464,9 @@ public class StringUtilsTest extends TestCase {
assertEquals("aaa", StringUtils.repeat("a", 3));
assertEquals("ababab", StringUtils.repeat("ab", 3));
assertEquals("abcabcabc", StringUtils.repeat("abc", 3));
String str = StringUtils.repeat("a", 10000); // bigger than pad limit
assertEquals(10000, str.length());
assertEquals(true, StringUtils.containsOnly(str, new char[] {'a'}));
}
public void testDeprecatedChompFunctions() {
@ -509,6 +524,7 @@ public class StringUtilsTest extends TestCase {
{ "foo\n\rfoo", "foo\n\rfoo" },
{ "\n", "" },
{ "\r", "" },
{ "a", "a" },
{ "\r\n", "" },
{ "", "" },
{ null, null },
@ -589,6 +605,9 @@ public class StringUtilsTest extends TestCase {
assertEquals("abc", StringUtils.rightPad("abc", 2, ' '));
assertEquals("abc", StringUtils.rightPad("abc", -1, ' '));
assertEquals("abcxx", StringUtils.rightPad("abc", 5, 'x'));
String str = StringUtils.rightPad("aaa", 10000, 'a'); // bigger than pad length
assertEquals(10000, str.length());
assertEquals(true, StringUtils.containsOnly(str, new char[] {'a'}));
}
public void testRightPad_StringIntString() {
@ -624,6 +643,9 @@ public class StringUtilsTest extends TestCase {
assertEquals(" abc", StringUtils.leftPad("abc", 5, ' '));
assertEquals("xxabc", StringUtils.leftPad("abc", 5, 'x'));
assertEquals("abc", StringUtils.leftPad("abc", 2, ' '));
String str = StringUtils.leftPad("aaa", 10000, 'a'); // bigger than pad length
assertEquals(10000, str.length());
assertEquals(true, StringUtils.containsOnly(str, new char[] {'a'}));
}
public void testLeftPad_StringIntString() {

View File

@ -53,6 +53,9 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -65,7 +68,7 @@ import junit.textui.TestRunner;
*
* @author Stephen Colebourne
* @author Tetsuya Kaneuchi
* @version $Id: SystemUtilsTest.java,v 1.3 2003/07/21 22:57:51 scolebourne Exp $
* @version $Id: SystemUtilsTest.java,v 1.4 2003/07/30 22:21:39 scolebourne Exp $
*/
public class SystemUtilsTest extends TestCase {
@ -91,6 +94,16 @@ public class SystemUtilsTest extends TestCase {
super.tearDown();
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new SystemUtils());
Constructor[] cons = SystemUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(SystemUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(SystemUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
// COPIED FROM SystemUtils
//-----------------------------------------------------------------------

View File

@ -53,6 +53,9 @@
*/
package org.apache.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -61,7 +64,9 @@ import junit.framework.TestSuite;
* Unit tests for the wrap methods of WordWrapUtils.
*
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @version $Id: WordWrapUtilsTest.java,v 1.2 2003/07/19 20:22:36 scolebourne Exp $
* @author Henri Yandell
* @author Stephen Colebourne
* @version $Id: WordWrapUtilsTest.java,v 1.3 2003/07/30 22:21:39 scolebourne Exp $
*/
public class WordWrapUtilsTest extends TestCase {
@ -75,6 +80,17 @@ public class WordWrapUtilsTest extends TestCase {
return suite;
}
//-----------------------------------------------------------------------
public void testConstructor() {
assertNotNull(new WordWrapUtils());
Constructor[] cons = WordWrapUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(WordWrapUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(WordWrapUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
/**
* Wrap text. This is the most general use.
*/