You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2012/09/18 23:07:44 UTC
svn commit: r1387361 [4/5] - in /commons/proper/lang/trunk: ./
src/test/java/org/apache/commons/lang3/
src/test/java/org/apache/commons/lang3/concurrent/
src/test/java/org/apache/commons/lang3/event/
src/test/java/org/apache/commons/lang3/exception/ sr...
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ import junit.framework.TestCase;
* @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 @@ public class MutableObjectTest extends T
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 @@ public class MutableObjectTest extends T
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 @@ public class MutableObjectTest extends T
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 @@ public class MutableObjectTest extends T
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());
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/mutable/MutableShortTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ import junit.framework.TestCase;
* @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 @@ public class MutableShortTest extends Te
} catch (NullPointerException ex) {}
}
+ @Test
public void testGetSet() {
final MutableShort mutNum = new MutableShort((short) 0);
assertEquals((short) 0, new MutableShort().shortValue());
@@ -69,6 +68,7 @@ public class MutableShortTest extends Te
} 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 @@ public class MutableShortTest extends Te
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 @@ public class MutableShortTest extends Te
assertEquals(true, mutNumA.hashCode() == Short.valueOf((short) 0).hashCode());
}
+ @Test
public void testCompareTo() {
final MutableShort mutNum = new MutableShort((short) 0);
@@ -109,6 +111,7 @@ public class MutableShortTest extends Te
} catch (NullPointerException ex) {}
}
+ @Test
public void testPrimitiveValues() {
MutableShort mutNum = new MutableShort( (short) 1 );
@@ -120,11 +123,13 @@ public class MutableShortTest extends Te
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 @@ public class MutableShortTest extends Te
assertEquals(2L, mutNum.longValue());
}
+ @Test
public void testDecrement() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.decrement();
@@ -141,6 +147,7 @@ public class MutableShortTest extends Te
assertEquals(0L, mutNum.longValue());
}
+ @Test
public void testAddValuePrimitive() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.add((short) 1);
@@ -148,6 +155,7 @@ public class MutableShortTest extends Te
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 @@ public class MutableShortTest extends Te
assertEquals((short) 2, mutNum.shortValue());
}
+ @Test
public void testSubtractValuePrimitive() {
MutableShort mutNum = new MutableShort((short) 1);
mutNum.subtract((short) 1);
@@ -162,6 +171,7 @@ public class MutableShortTest extends Te
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 @@ public class MutableShortTest extends Te
assertEquals((short) 0, mutNum.shortValue());
}
+ @Test
public void testToString() {
assertEquals("0", new MutableShort((short) 0).toString());
assertEquals("10", new MutableShort((short) 10).toString());
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ import org.apache.commons.lang3.mutable.
* Unit tests ConstructorUtils
* @version $Id$
*/
-public class ConstructorUtilsTest extends TestCase {
+public class ConstructorUtilsTest {
public static class TestBean {
private String toString;
@@ -73,21 +74,22 @@ public class ConstructorUtilsTest extend
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 @@ public class ConstructorUtilsTest extend
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 @@ public class ConstructorUtilsTest extend
}
}
+ @Test
public void testGetAccessibleConstructor() throws Exception {
assertNotNull(ConstructorUtils.getAccessibleConstructor(Object.class
.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY)));
@@ -152,6 +156,7 @@ public class ConstructorUtilsTest extend
.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY)));
}
+ @Test
public void testGetAccessibleConstructorFromDescription() throws Exception {
assertNotNull(ConstructorUtils.getAccessibleConstructor(Object.class,
ArrayUtils.EMPTY_CLASS_ARRAY));
@@ -159,6 +164,7 @@ public class ConstructorUtilsTest extend
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 @@ public class ConstructorUtilsTest extend
singletonArray(Double.TYPE), singletonArray(Double.TYPE));
}
+ @Test
public void testNullArgument() {
expectMatchingAccessibleConstructorParameterTypes(MutableObject.class,
singletonArray(null), singletonArray(Object.class));
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/CompositeFormatTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ public class CompositeFormatTest extends
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);
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java Tue Sep 18 21:07:42 2012
@@ -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.HashSet;
import java.util.Locale;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.SystemUtils;
/**
@@ -43,22 +44,12 @@ import org.apache.commons.lang3.SystemUt
* @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 @@ public class ExtendedMessageFormatTest e
/**
* 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 @@ public class ExtendedMessageFormatTest e
/**
* 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 @@ public class ExtendedMessageFormatTest e
/**
* 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 @@ public class ExtendedMessageFormatTest e
/**
* 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 @@ public class ExtendedMessageFormatTest e
/**
* 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 @@ public class ExtendedMessageFormatTest e
checkBuiltInFormat("12: {0,time}", args, availableLocales);
}
+ @Test
public void testOverriddenBuiltinFormat() {
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.JANUARY, 23);
@@ -254,6 +251,7 @@ public class ExtendedMessageFormatTest e
/**
* 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 @@ public class ExtendedMessageFormatTest e
/**
* 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());
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderAppendInsertTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ import org.apache.commons.lang3.SystemUt
*
* @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 @@ public class StrBuilderAppendInsertTest
}
};
- /**
- * 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 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithNullText() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL");
@@ -96,6 +89,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_Object() {
StrBuilder sb = new StrBuilder();
sb.appendNull();
@@ -121,6 +115,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_String() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((String) null);
@@ -138,6 +133,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_String_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((String) null, 0, 1);
@@ -200,6 +196,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StringBuffer() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StringBuffer) null);
@@ -217,6 +214,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StringBuffer_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StringBuffer) null, 0, 1);
@@ -276,6 +274,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StrBuilder() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StrBuilder) null);
@@ -293,6 +292,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_StrBuilder_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((StrBuilder) null, 0, 1);
@@ -352,6 +352,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_CharArray() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((char[]) null);
@@ -366,6 +367,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_CharArray_int_int() {
StrBuilder sb = new StrBuilder();
sb.setNullText("NULL").append((char[]) null, 0, 1);
@@ -425,6 +427,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_Boolean() {
StrBuilder sb = new StrBuilder();
sb.append(true);
@@ -438,6 +441,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppend_PrimitiveNumber() {
StrBuilder sb = new StrBuilder();
sb.append(0);
@@ -454,6 +458,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_Object() {
StrBuilder sb = new StrBuilder();
sb.appendln((Object) null);
@@ -467,6 +472,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_String() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -488,6 +494,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_String_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -509,6 +516,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StringBuffer() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -530,6 +538,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StringBuffer_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -551,6 +560,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StrBuilder() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -572,6 +582,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_StrBuilder_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -593,6 +604,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_CharArray() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -614,6 +626,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_CharArray_int_int() {
final int[] count = new int[2];
StrBuilder sb = new StrBuilder() {
@@ -635,6 +648,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_Boolean() {
StrBuilder sb = new StrBuilder();
sb.appendln(true);
@@ -646,6 +660,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendln_PrimitiveNumber() {
StrBuilder sb = new StrBuilder();
sb.appendln(0);
@@ -665,6 +680,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendPadding() {
StrBuilder sb = new StrBuilder();
sb.append("foo");
@@ -686,6 +702,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadLeft() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft("foo", -1, '-');
@@ -724,6 +741,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadLeft_int() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft(123, -1, '-');
@@ -757,6 +775,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadRight() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight("foo", -1, '-');
@@ -795,6 +814,7 @@ public class StrBuilderAppendInsertTest
}
// 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 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendFixedWidthPadRight_int() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight(123, -1, '-');
@@ -835,6 +856,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendAll_Array() {
StrBuilder sb = new StrBuilder();
sb.appendAll((Object[]) null);
@@ -850,6 +872,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendAll_Collection() {
StrBuilder sb = new StrBuilder();
sb.appendAll((Collection<?>) null);
@@ -865,6 +888,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendAll_Iterator() {
StrBuilder sb = new StrBuilder();
sb.appendAll((Iterator<?>) null);
@@ -880,6 +904,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparators_Array() {
StrBuilder sb = new StrBuilder();
sb.appendWithSeparators((Object[]) null, ",");
@@ -903,6 +928,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparators_Collection() {
StrBuilder sb = new StrBuilder();
sb.appendWithSeparators((Collection<?>) null, ",");
@@ -926,6 +952,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparators_Iterator() {
StrBuilder sb = new StrBuilder();
sb.appendWithSeparators((Iterator<?>) null, ",");
@@ -949,6 +976,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendWithSeparatorsWithNullText() {
StrBuilder sb = new StrBuilder();
sb.setNullText("null");
@@ -961,6 +989,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_String() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(","); // no effect
@@ -972,6 +1001,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_String_String() {
StrBuilder sb = new StrBuilder();
final String startSeparator = "order by ";
@@ -994,6 +1024,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_char() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(','); // no effect
@@ -1003,6 +1034,7 @@ public class StrBuilderAppendInsertTest
sb.appendSeparator(',');
assertEquals("foo,", sb.toString());
}
+ @Test
public void testAppendSeparator_char_char() {
StrBuilder sb = new StrBuilder();
final char startSeparator = ':';
@@ -1017,6 +1049,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_String_int() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(",", 0); // no effect
@@ -1031,6 +1064,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testAppendSeparator_char_int() {
StrBuilder sb = new StrBuilder();
sb.appendSeparator(',', 0); // no effect
@@ -1045,6 +1079,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testInsert() {
StrBuilder sb = new StrBuilder();
@@ -1311,6 +1346,7 @@ public class StrBuilderAppendInsertTest
}
//-----------------------------------------------------------------------
+ @Test
public void testInsertWithNullText() {
StrBuilder sb = new StrBuilder();
sb.setNullText("null");
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ import org.apache.commons.lang3.ArrayUti
*
* @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 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testChaining() {
StrBuilder sb = new StrBuilder();
assertSame(sb, sb.setNewLineText(null));
@@ -100,6 +92,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testGetSetNewLineText() {
StrBuilder sb = new StrBuilder();
assertEquals(null, sb.getNewLineText());
@@ -115,6 +108,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testGetSetNullText() {
StrBuilder sb = new StrBuilder();
assertEquals(null, sb.getNullText());
@@ -133,6 +127,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testCapacityAndLength() {
StrBuilder sb = new StrBuilder();
assertEquals(32, sb.capacity());
@@ -217,6 +212,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testLength() {
StrBuilder sb = new StrBuilder();
assertEquals(0, sb.length());
@@ -225,6 +221,7 @@ public class StrBuilderTest extends Test
assertEquals(5, sb.length());
}
+ @Test
public void testSetLength() {
StrBuilder sb = new StrBuilder();
sb.append("Hello");
@@ -244,6 +241,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testCapacity() {
StrBuilder sb = new StrBuilder();
assertEquals(sb.buffer.length, sb.capacity());
@@ -252,6 +250,7 @@ public class StrBuilderTest extends Test
assertEquals(sb.buffer.length, sb.capacity());
}
+ @Test
public void testEnsureCapacity() {
StrBuilder sb = new StrBuilder();
sb.ensureCapacity(2);
@@ -265,6 +264,7 @@ public class StrBuilderTest extends Test
assertEquals(true, sb.capacity() >= 40);
}
+ @Test
public void testMinimizeCapacity() {
StrBuilder sb = new StrBuilder();
sb.minimizeCapacity();
@@ -276,6 +276,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testSize() {
StrBuilder sb = new StrBuilder();
assertEquals(0, sb.size());
@@ -284,6 +285,7 @@ public class StrBuilderTest extends Test
assertEquals(5, sb.size());
}
+ @Test
public void testIsEmpty() {
StrBuilder sb = new StrBuilder();
assertEquals(true, sb.isEmpty());
@@ -295,6 +297,7 @@ public class StrBuilderTest extends Test
assertEquals(true, sb.isEmpty());
}
+ @Test
public void testClear() {
StrBuilder sb = new StrBuilder();
sb.append("Hello");
@@ -304,6 +307,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testCharAt() {
StrBuilder sb = new StrBuilder();
try {
@@ -337,6 +341,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testSetCharAt() {
StrBuilder sb = new StrBuilder();
try {
@@ -365,6 +370,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testDeleteCharAt() {
StrBuilder sb = new StrBuilder("abc");
sb.deleteCharAt(0);
@@ -377,6 +383,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testToCharArray() {
StrBuilder sb = new StrBuilder();
assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, sb.toCharArray());
@@ -391,6 +398,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
}
+ @Test
public void testGetChars ( ) {
StrBuilder sb = new StrBuilder();
@@ -451,6 +460,7 @@ public class StrBuilderTest extends Test
assertNotSame(input, a);
}
+ @Test
public void testGetCharsIntIntCharArrayInt( ) {
StrBuilder sb = new StrBuilder();
@@ -493,6 +503,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testDeleteIntInt() {
StrBuilder sb = new StrBuilder("abc");
sb.delete(0, 1);
@@ -521,6 +532,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testDeleteAll_char() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.deleteAll('X');
@@ -537,6 +549,7 @@ public class StrBuilderTest extends Test
assertEquals("", sb.toString());
}
+ @Test
public void testDeleteFirst_char() {
StrBuilder sb = new StrBuilder("abcba");
sb.deleteFirst('X');
@@ -554,6 +567,7 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testDeleteAll_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.deleteAll((String) null);
@@ -579,6 +593,7 @@ public class StrBuilderTest extends Test
assertEquals("", sb.toString());
}
+ @Test
public void testDeleteFirst_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.deleteFirst((String) null);
@@ -605,6 +620,7 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testDeleteAll_StrMatcher() {
StrBuilder sb = new StrBuilder("A0xA1A2yA3");
sb.deleteAll((StrMatcher) null);
@@ -621,6 +637,7 @@ public class StrBuilderTest extends Test
assertEquals("", sb.toString());
}
+ @Test
public void testDeleteFirst_StrMatcher() {
StrBuilder sb = new StrBuilder("A0xA1A2yA3");
sb.deleteFirst((StrMatcher) null);
@@ -638,6 +655,7 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testReplace_int_int_String() {
StrBuilder sb = new StrBuilder("abc");
sb.replace(0, 1, "d");
@@ -673,6 +691,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceAll_char_char() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceAll('x', 'y');
@@ -688,6 +707,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceFirst_char_char() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceFirst('x', 'y');
@@ -703,6 +723,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceAll_String_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceAll((String) null, null);
@@ -732,6 +753,7 @@ public class StrBuilderTest extends Test
assertEquals("xbxxbx", sb.toString());
}
+ @Test
public void testReplaceFirst_String_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceFirst((String) null, null);
@@ -762,6 +784,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testReplaceAll_StrMatcher_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceAll((StrMatcher) null, null);
@@ -795,6 +818,7 @@ public class StrBuilderTest extends Test
assertEquals("***-******-***", sb.toString());
}
+ @Test
public void testReplaceFirst_StrMatcher_String() {
StrBuilder sb = new StrBuilder("abcbccba");
sb.replaceFirst((StrMatcher) null, null);
@@ -829,6 +853,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testReverse() {
StrBuilder sb = new StrBuilder();
assertEquals("", sb.reverse().toString());
@@ -1025,6 +1055,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testTrim() {
StrBuilder sb = new StrBuilder();
assertEquals("", sb.reverse().toString());
@@ -1046,6 +1077,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testStartsWith() {
StrBuilder sb = new StrBuilder();
assertFalse(sb.startsWith("a"));
@@ -1058,6 +1090,7 @@ public class StrBuilderTest extends Test
assertFalse(sb.startsWith("cba"));
}
+ @Test
public void testEndsWith() {
StrBuilder sb = new StrBuilder();
assertFalse(sb.endsWith("a"));
@@ -1075,6 +1108,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testSubSequenceIntInt() {
StrBuilder sb = new StrBuilder ("hello goodbye");
// Start index is negative
@@ -1108,6 +1142,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
+ @Test
public void testSubstringIntInt() {
StrBuilder sb = new StrBuilder ("hello goodbye");
assertEquals ("hello", sb.substring(0, 5));
@@ -1148,6 +1184,7 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testMidString() {
StrBuilder sb = new StrBuilder("hello goodbye hello");
assertEquals("goodbye", sb.midString(6, 7));
@@ -1158,6 +1195,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testContains_char() {
StrBuilder sb = new StrBuilder("abcdefghijklmnopqrstuvwxyz");
assertEquals(true, sb.contains('a'));
@@ -1183,6 +1223,7 @@ public class StrBuilderTest extends Test
assertEquals(false, sb.contains('1'));
}
+ @Test
public void testContains_String() {
StrBuilder sb = new StrBuilder("abcdefghijklmnopqrstuvwxyz");
assertEquals(true, sb.contains("a"));
@@ -1192,6 +1233,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testIndexOf_char() {
StrBuilder sb = new StrBuilder("abab");
assertEquals(0, sb.indexOf('a'));
@@ -1220,6 +1263,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
assertEquals(-1, sb.indexOf('z', 3));
}
+ @Test
public void testLastIndexOf_char() {
StrBuilder sb = new StrBuilder("abab");
@@ -1254,6 +1299,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testIndexOf_String() {
StrBuilder sb = new StrBuilder("abab");
@@ -1296,6 +1343,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
assertEquals(-1, sb.indexOf((String) null, 2));
}
+ @Test
public void testLastIndexOf_String() {
StrBuilder sb = new StrBuilder("abab");
@@ -1354,6 +1403,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testIndexOf_StrMatcher() {
StrBuilder sb = new StrBuilder();
assertEquals(-1, sb.indexOf((StrMatcher) null));
@@ -1408,6 +1459,7 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
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 @@ public class StrBuilderTest extends Test
};
//-----------------------------------------------------------------------
+ @Test
public void testAsTokenizer() throws Exception {
// from Javadoc
StrBuilder b = new StrBuilder();
@@ -1556,6 +1611,7 @@ public class StrBuilderTest extends Test
}
// -----------------------------------------------------------------------
+ @Test
public void testAsReader() throws Exception {
StrBuilder sb = new StrBuilder("some text");
Reader reader = sb.asReader();
@@ -1627,6 +1683,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testAsWriter() throws Exception {
StrBuilder sb = new StrBuilder("base");
Writer writer = sb.asWriter();
@@ -1661,6 +1718,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testEqualsIgnoreCase() {
StrBuilder sb1 = new StrBuilder();
StrBuilder sb2 = new StrBuilder();
@@ -1684,6 +1742,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testEquals() {
StrBuilder sb1 = new StrBuilder();
StrBuilder sb2 = new StrBuilder();
@@ -1709,6 +1768,7 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testHashCode() {
StrBuilder sb = new StrBuilder();
int hc1a = sb.hashCode();
@@ -1724,12 +1784,14 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @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 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @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 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testLang295() {
StrBuilder sb = new StrBuilder("onetwothree");
sb.deleteFirst("three");
@@ -1760,12 +1825,14 @@ public class StrBuilderTest extends Test
}
//-----------------------------------------------------------------------
+ @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, '*');
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ public class StrLookupTest extends TestC
}
}
+ @Test
public void testMapLookup() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("key", "value");
@@ -59,6 +65,7 @@ public class StrLookupTest extends TestC
assertEquals(null, StrLookup.mapLookup(map).lookup("other"));
}
+ @Test
public void testMapLookup_nullMap() {
Map<String, ?> map = null;
assertEquals(null, StrLookup.mapLookup(map).lookup(null));
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrMatcherTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testTabMatcher() {
StrMatcher matcher = StrMatcher.tabMatcher();
assertSame(matcher, StrMatcher.tabMatcher());
@@ -58,6 +56,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testSpaceMatcher() {
StrMatcher matcher = StrMatcher.spaceMatcher();
assertSame(matcher, StrMatcher.spaceMatcher());
@@ -67,6 +66,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testSplitMatcher() {
StrMatcher matcher = StrMatcher.splitMatcher();
assertSame(matcher, StrMatcher.splitMatcher());
@@ -82,6 +82,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testTrimMatcher() {
StrMatcher matcher = StrMatcher.trimMatcher();
assertSame(matcher, StrMatcher.trimMatcher());
@@ -97,6 +98,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testSingleQuoteMatcher() {
StrMatcher matcher = StrMatcher.singleQuoteMatcher();
assertSame(matcher, StrMatcher.singleQuoteMatcher());
@@ -106,6 +108,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testDoubleQuoteMatcher() {
StrMatcher matcher = StrMatcher.doubleQuoteMatcher();
assertSame(matcher, StrMatcher.doubleQuoteMatcher());
@@ -114,6 +117,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testQuoteMatcher() {
StrMatcher matcher = StrMatcher.quoteMatcher();
assertSame(matcher, StrMatcher.quoteMatcher());
@@ -123,6 +127,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testNoneMatcher() {
StrMatcher matcher = StrMatcher.noneMatcher();
assertSame(matcher, StrMatcher.noneMatcher());
@@ -142,6 +147,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testCharMatcher_char() {
StrMatcher matcher = StrMatcher.charMatcher('c');
assertEquals(0, matcher.isMatch(BUFFER2, 0));
@@ -153,6 +159,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testCharSetMatcher_String() {
StrMatcher matcher = StrMatcher.charSetMatcher("ace");
assertEquals(1, matcher.isMatch(BUFFER2, 0));
@@ -167,6 +174,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testCharSetMatcher_charArray() {
StrMatcher matcher = StrMatcher.charSetMatcher("ace".toCharArray());
assertEquals(1, matcher.isMatch(BUFFER2, 0));
@@ -181,6 +189,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @Test
public void testStringMatcher_String() {
StrMatcher matcher = StrMatcher.stringMatcher("bc");
assertEquals(0, matcher.isMatch(BUFFER2, 0));
@@ -194,6 +203,7 @@ public class StrMatcherTest extends Test
}
//-----------------------------------------------------------------------
+ @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
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java Tue Sep 18 21:07:42 2012
@@ -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 @@ import org.apache.commons.lang3.mutable.
*
* @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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* Tests simple key replace.
*/
+ @Test
public void testReplaceSolo() {
doTestReplace("quick brown fox", "${animal}", false);
}
@@ -66,6 +68,7 @@ public class StrSubstitutorTest extends
/**
* Tests replace with no variables.
*/
+ @Test
public void testReplaceNoVariables() {
doTestNoReplace("The balloon arrived.");
}
@@ -73,6 +76,7 @@ public class StrSubstitutorTest extends
/**
* Tests replace with null.
*/
+ @Test
public void testReplaceNull() {
doTestNoReplace(null);
}
@@ -80,6 +84,7 @@ public class StrSubstitutorTest extends
/**
* Tests replace with null.
*/
+ @Test
public void testReplaceEmpty() {
doTestNoReplace("");
}
@@ -87,6 +92,7 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* Tests adjacent keys.
*/
+ @Test
public void testReplaceAdjacentAtStart() {
values.put("code", "GBP");
values.put("amount", "12.50");
@@ -113,6 +121,7 @@ public class StrSubstitutorTest extends
/**
* Tests adjacent keys.
*/
+ @Test
public void testReplaceAdjacentAtEnd() {
values.put("code", "GBP");
values.put("amount", "12.50");
@@ -123,6 +132,7 @@ public class StrSubstitutorTest extends
/**
* Tests simple recursive replace.
*/
+ @Test
public void testReplaceRecursive() {
values.put("animal", "${critter}");
values.put("target", "${pet}");
@@ -138,6 +148,7 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* Tests escaping.
*/
+ @Test
public void testReplaceSoloEscaping() {
doTestReplace("${animal}", "$${animal}", false);
}
@@ -152,6 +164,7 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* Tests replace creates output same as input.
*/
+ @Test
public void testReplaceToIdentical() {
values.put("animal", "$${${thing}}");
values.put("thing", "animal");
@@ -204,6 +223,7 @@ public class StrSubstitutorTest extends
* 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 @@ public class StrSubstitutorTest extends
/**
* Tests interpolation with weird boundary patterns.
*/
+ @Test
public void testReplaceWeirdPattens() {
doTestNoReplace("");
doTestNoReplace("${}");
@@ -249,6 +270,7 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* Tests constructor.
*/
+ @Test
public void testConstructorNoArgs() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals("Hi ${name}", sub.replace("Hi ${name}"));
@@ -339,6 +366,7 @@ public class StrSubstitutorTest extends
/**
* Tests constructor.
*/
+ @Test
public void testConstructorMapPrefixSuffix() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -349,6 +377,7 @@ public class StrSubstitutorTest extends
/**
* Tests constructor.
*/
+ @Test
public void testConstructorMapFull() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -360,6 +389,7 @@ public class StrSubstitutorTest extends
/**
* Tests get set.
*/
+ @Test
public void testGetSetEscape() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals('$', sub.getEscapeChar());
@@ -370,6 +400,7 @@ public class StrSubstitutorTest extends
/**
* Tests get set.
*/
+ @Test
public void testGetSetPrefix() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals(true, sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
@@ -401,6 +432,7 @@ public class StrSubstitutorTest extends
/**
* Tests get set.
*/
+ @Test
public void testGetSetSuffix() {
StrSubstitutor sub = new StrSubstitutor();
assertEquals(true, sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
@@ -433,6 +465,7 @@ public class StrSubstitutorTest extends
/**
* Tests static.
*/
+ @Test
public void testStaticReplace() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -442,6 +475,7 @@ public class StrSubstitutorTest extends
/**
* Tests static.
*/
+ @Test
public void testStaticReplacePrefixSuffix() {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "commons");
@@ -451,6 +485,7 @@ public class StrSubstitutorTest extends
/**
* 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 @@ public class StrSubstitutorTest extends
/**
* Test the replace of a properties object
*/
+ @Test
public void testSubstituteDefaultProperties(){
String org = "${doesnotwork}";
System.setProperty("doesnotwork", "It works!");
@@ -476,6 +512,7 @@ public class StrSubstitutorTest extends
assertEquals("It works!", StrSubstitutor.replace(org, props));
}
+ @Test
public void testSamePrefixAndSuffix() {
Map<String, String> map = new HashMap<String, String>();
map.put("greeting", "Hello");