[LANG-824] Conversion of 3.x JUnit tests to 4.x; thanks to Duncan Jones
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1387361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
32b71d0913
commit
77d33a665a
3
pom.xml
3
pom.xml
|
@ -259,6 +259,9 @@
|
|||
<contributor>
|
||||
<name>Marc Johnson</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Duncan Jones</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Shaun Kalley</name>
|
||||
</contributor>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,31 +16,26 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Class to test BitField functionality
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BitFieldTest extends TestCase {
|
||||
public class BitFieldTest {
|
||||
|
||||
private static final BitField bf_multi = new BitField(0x3F80);
|
||||
private static final BitField bf_single = new BitField(0x4000);
|
||||
private static final BitField bf_zero = new BitField(0);
|
||||
|
||||
/**
|
||||
* Constructor BitFieldTest
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public BitFieldTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the getValue() method
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
assertEquals(bf_multi.getValue(-1), 127);
|
||||
assertEquals(bf_multi.getValue(0), 0);
|
||||
|
@ -53,6 +48,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the getShortValue() method
|
||||
*/
|
||||
@Test
|
||||
public void testGetShortValue() {
|
||||
assertEquals(bf_multi.getShortValue((short) - 1), (short) 127);
|
||||
assertEquals(bf_multi.getShortValue((short) 0), (short) 0);
|
||||
|
@ -65,6 +61,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the getRawValue() method
|
||||
*/
|
||||
@Test
|
||||
public void testGetRawValue() {
|
||||
assertEquals(bf_multi.getRawValue(-1), 0x3F80);
|
||||
assertEquals(bf_multi.getRawValue(0), 0);
|
||||
|
@ -77,6 +74,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the getShortRawValue() method
|
||||
*/
|
||||
@Test
|
||||
public void testGetShortRawValue() {
|
||||
assertEquals(bf_multi.getShortRawValue((short) - 1), (short) 0x3F80);
|
||||
assertEquals(bf_multi.getShortRawValue((short) 0), (short) 0);
|
||||
|
@ -89,6 +87,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the isSet() method
|
||||
*/
|
||||
@Test
|
||||
public void testIsSet() {
|
||||
assertTrue(!bf_multi.isSet(0));
|
||||
assertTrue(!bf_zero.isSet(0));
|
||||
|
@ -105,6 +104,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the isAllSet() method
|
||||
*/
|
||||
@Test
|
||||
public void testIsAllSet() {
|
||||
for (int j = 0; j < 0x3F80; j += 0x80) {
|
||||
assertTrue(!bf_multi.isAllSet(j));
|
||||
|
@ -118,6 +118,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the setValue() method
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
for (int j = 0; j < 128; j++) {
|
||||
assertEquals(bf_multi.getValue(bf_multi.setValue(0, j)), j);
|
||||
|
@ -142,6 +143,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the setShortValue() method
|
||||
*/
|
||||
@Test
|
||||
public void testSetShortValue() {
|
||||
for (int j = 0; j < 128; j++) {
|
||||
assertEquals(bf_multi.getShortValue(bf_multi.setShortValue((short) 0, (short) j)), (short) j);
|
||||
|
@ -163,6 +165,7 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_single.setShortValue((short) 0x4000, (short) 2), (short) 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByte() {
|
||||
assertEquals(0, new BitField(0).setByteBoolean((byte) 0, true));
|
||||
assertEquals(1, new BitField(1).setByteBoolean((byte) 0, true));
|
||||
|
@ -191,6 +194,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the clear() method
|
||||
*/
|
||||
@Test
|
||||
public void testClear() {
|
||||
assertEquals(bf_multi.clear(-1), 0xFFFFC07F);
|
||||
assertEquals(bf_single.clear(-1), 0xFFFFBFFF);
|
||||
|
@ -200,6 +204,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the clearShort() method
|
||||
*/
|
||||
@Test
|
||||
public void testClearShort() {
|
||||
assertEquals(bf_multi.clearShort((short) - 1), (short) 0xC07F);
|
||||
assertEquals(bf_single.clearShort((short) - 1), (short) 0xBFFF);
|
||||
|
@ -209,6 +214,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the set() method
|
||||
*/
|
||||
@Test
|
||||
public void testSet() {
|
||||
assertEquals(bf_multi.set(0), 0x3F80);
|
||||
assertEquals(bf_single.set(0), 0x4000);
|
||||
|
@ -218,6 +224,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the setShort() method
|
||||
*/
|
||||
@Test
|
||||
public void testSetShort() {
|
||||
assertEquals(bf_multi.setShort((short) 0), (short) 0x3F80);
|
||||
assertEquals(bf_single.setShort((short) 0), (short) 0x4000);
|
||||
|
@ -227,6 +234,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the setBoolean() method
|
||||
*/
|
||||
@Test
|
||||
public void testSetBoolean() {
|
||||
assertEquals(bf_multi.set(0), bf_multi.setBoolean(0, true));
|
||||
assertEquals(bf_single.set(0), bf_single.setBoolean(0, true));
|
||||
|
@ -239,6 +247,7 @@ public class BitFieldTest extends TestCase {
|
|||
/**
|
||||
* test the setShortBoolean() method
|
||||
*/
|
||||
@Test
|
||||
public void testSetShortBoolean() {
|
||||
assertEquals(bf_multi.setShort((short) 0), bf_multi.setShortBoolean((short) 0, true));
|
||||
assertEquals(bf_single.setShort((short) 0), bf_single.setShortBoolean((short) 0, true));
|
||||
|
|
|
@ -20,7 +20,10 @@ package org.apache.commons.lang3;
|
|||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests CharEncoding.
|
||||
|
@ -28,7 +31,7 @@ import junit.framework.TestCase;
|
|||
* @see CharEncoding
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CharEncodingTest extends TestCase {
|
||||
public class CharEncodingTest {
|
||||
|
||||
private void assertSupportedEncoding(String name) {
|
||||
assertTrue("Encoding should be supported: " + name, CharEncoding.isSupported(name));
|
||||
|
@ -37,10 +40,12 @@ public class CharEncodingTest extends TestCase {
|
|||
/**
|
||||
* The class can be instantiated.
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
new CharEncoding();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMustBeSupportedJava1_3_1() {
|
||||
if (SystemUtils.isJavaVersionAtLeast(JAVA_1_3)) {
|
||||
this.assertSupportedEncoding(CharEncoding.ISO_8859_1);
|
||||
|
@ -54,12 +59,14 @@ public class CharEncodingTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupported() {
|
||||
assertTrue(CharEncoding.isSupported("UTF8"));
|
||||
assertTrue(CharEncoding.isSupported("UTF-8"));
|
||||
assertTrue(CharEncoding.isSupported("ASCII"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotSupported() {
|
||||
assertFalse(CharEncoding.isSupported(null));
|
||||
assertFalse(CharEncoding.isSupported(""));
|
||||
|
@ -69,6 +76,7 @@ public class CharEncodingTest extends TestCase {
|
|||
assertFalse(CharEncoding.isSupported("this is not a valid encoding name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorksOnJava1_1_8() {
|
||||
//
|
||||
// In this test, I simply deleted the encodings from the 1.3.1 list.
|
||||
|
@ -83,6 +91,7 @@ public class CharEncodingTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorksOnJava1_2_2() {
|
||||
//
|
||||
// In this test, I simply deleted the encodings from the 1.3.1 list.
|
||||
|
|
|
@ -18,24 +18,27 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharRange}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CharRangeTest extends TestCase {
|
||||
|
||||
public CharRangeTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class CharRangeTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testClass() {
|
||||
// class changed to non-public in 3.0
|
||||
assertEquals(false, Modifier.isPublic(CharRange.class.getModifiers()));
|
||||
|
@ -43,6 +46,7 @@ public class CharRangeTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructorAccessors_is() {
|
||||
CharRange rangea = CharRange.is('a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -51,6 +55,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("a", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNot() {
|
||||
CharRange rangea = CharRange.isNot('a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -59,6 +64,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("^a", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isIn_Same() {
|
||||
CharRange rangea = CharRange.isIn('a', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -67,6 +73,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("a", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isIn_Normal() {
|
||||
CharRange rangea = CharRange.isIn('a', 'e');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -75,6 +82,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("a-e", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isIn_Reversed() {
|
||||
CharRange rangea = CharRange.isIn('e', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -83,6 +91,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("a-e", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNotIn_Same() {
|
||||
CharRange rangea = CharRange.isNotIn('a', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -91,6 +100,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("^a", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNotIn_Normal() {
|
||||
CharRange rangea = CharRange.isNotIn('a', 'e');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -99,6 +109,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals("^a-e", rangea.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNotIn_Reversed() {
|
||||
CharRange rangea = CharRange.isNotIn('e', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
|
@ -108,6 +119,7 @@ public class CharRangeTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEquals_Object() {
|
||||
CharRange rangea = CharRange.is('a');
|
||||
CharRange rangeae = CharRange.isIn('a', 'e');
|
||||
|
@ -130,6 +142,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals(false, rangenotbf.equals(rangeae));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
CharRange rangea = CharRange.is('a');
|
||||
CharRange rangeae = CharRange.isIn('a', 'e');
|
||||
|
@ -151,6 +164,7 @@ public class CharRangeTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testContains_Char() {
|
||||
CharRange range = CharRange.is('c');
|
||||
assertEquals(false, range.contains('b'));
|
||||
|
@ -180,6 +194,7 @@ public class CharRangeTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testContains_Charrange() {
|
||||
CharRange a = CharRange.is('a');
|
||||
CharRange b = CharRange.is('b');
|
||||
|
@ -294,6 +309,7 @@ public class CharRangeTest extends TestCase {
|
|||
assertEquals(true, notbd.contains(notae));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsNullArg() {
|
||||
CharRange range = CharRange.is('a');
|
||||
try {
|
||||
|
@ -304,6 +320,7 @@ public class CharRangeTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterator() {
|
||||
CharRange a = CharRange.is('a');
|
||||
CharRange ad = CharRange.isIn('a', 'd');
|
||||
|
@ -371,6 +388,7 @@ public class CharRangeTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
CharRange range = CharRange.is('a');
|
||||
assertEquals(range, SerializationUtils.clone(range));
|
||||
|
|
|
@ -16,20 +16,25 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests CharSequenceUtils
|
||||
*
|
||||
* @version $Id: CharSequenceUtilsTest.java 1066341 2011-02-02 06:21:53Z bayard $
|
||||
*/
|
||||
public class CharSequenceUtilsTest extends TestCase {
|
||||
public class CharSequenceUtilsTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new CharSequenceUtils());
|
||||
Constructor<?>[] cons = CharSequenceUtils.class.getDeclaredConstructors();
|
||||
|
@ -40,6 +45,7 @@ public class CharSequenceUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSubSequence() {
|
||||
//
|
||||
// null input
|
||||
|
|
|
@ -18,28 +18,29 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharSet}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CharSetTest extends TestCase {
|
||||
|
||||
public CharSetTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class CharSetTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testClass() {
|
||||
assertEquals(true, Modifier.isPublic(CharSet.class.getModifiers()));
|
||||
assertEquals(false, Modifier.isFinal(CharSet.class.getModifiers()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetInstance() {
|
||||
assertSame(CharSet.EMPTY, CharSet.getInstance( (String) null));
|
||||
assertSame(CharSet.EMPTY, CharSet.getInstance(""));
|
||||
|
@ -51,6 +52,7 @@ public class CharSetTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetInstance_Stringarray() {
|
||||
assertEquals(null, CharSet.getInstance((String[]) null));
|
||||
assertEquals("[]", CharSet.getInstance(new String[0]).toString());
|
||||
|
@ -59,6 +61,7 @@ public class CharSetTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_String_simple() {
|
||||
CharSet set;
|
||||
CharRange[] array;
|
||||
|
@ -98,6 +101,7 @@ public class CharSetTest extends TestCase {
|
|||
assertEquals("^a-e", array[0].toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_String_combo() {
|
||||
CharSet set;
|
||||
CharRange[] array;
|
||||
|
@ -136,6 +140,7 @@ public class CharSetTest extends TestCase {
|
|||
assertEquals(true, ArrayUtils.contains(array, CharRange.is('z')));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_String_comboNegated() {
|
||||
CharSet set;
|
||||
CharRange[] array;
|
||||
|
@ -176,6 +181,7 @@ public class CharSetTest extends TestCase {
|
|||
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_String_oddDash() {
|
||||
CharSet set;
|
||||
CharRange[] array;
|
||||
|
@ -223,6 +229,7 @@ public class CharSetTest extends TestCase {
|
|||
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('-', 'a')));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_String_oddNegate() {
|
||||
CharSet set;
|
||||
CharRange[] array;
|
||||
|
@ -282,6 +289,7 @@ public class CharSetTest extends TestCase {
|
|||
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-'))); // "-"
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_String_oddCombinations() {
|
||||
CharSet set;
|
||||
CharRange[] array = null;
|
||||
|
@ -331,6 +339,7 @@ public class CharSetTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEquals_Object() {
|
||||
CharSet abc = CharSet.getInstance("abc");
|
||||
CharSet abc2 = CharSet.getInstance("abc");
|
||||
|
@ -357,6 +366,7 @@ public class CharSetTest extends TestCase {
|
|||
assertEquals(true, notatoc.equals(notatoc2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
CharSet abc = CharSet.getInstance("abc");
|
||||
CharSet abc2 = CharSet.getInstance("abc");
|
||||
|
@ -374,6 +384,7 @@ public class CharSetTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testContains_Char() {
|
||||
CharSet btod = CharSet.getInstance("b-d");
|
||||
CharSet dtob = CharSet.getInstance("d-b");
|
||||
|
@ -417,6 +428,7 @@ public class CharSetTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
CharSet set = CharSet.getInstance("a");
|
||||
assertEquals(set, SerializationUtils.clone(set));
|
||||
|
@ -427,6 +439,7 @@ public class CharSetTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testStatics() {
|
||||
CharRange[] array;
|
||||
|
||||
|
|
|
@ -16,23 +16,23 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharSetUtils}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CharSetUtilsTest extends TestCase {
|
||||
|
||||
public CharSetUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class CharSetUtilsTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new CharSetUtils());
|
||||
Constructor<?>[] cons = CharSetUtils.class.getDeclaredConstructors();
|
||||
|
@ -43,6 +43,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSqueeze_StringString() {
|
||||
assertEquals(null, CharSetUtils.squeeze(null, (String) null));
|
||||
assertEquals(null, CharSetUtils.squeeze(null, ""));
|
||||
|
@ -59,6 +60,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
assertEquals("hello", CharSetUtils.squeeze("helloo", "^l"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqueeze_StringStringarray() {
|
||||
assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
|
||||
assertEquals(null, CharSetUtils.squeeze(null, new String[0]));
|
||||
|
@ -82,6 +84,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCount_StringString() {
|
||||
assertEquals(0, CharSetUtils.count(null, (String) null));
|
||||
assertEquals(0, CharSetUtils.count(null, ""));
|
||||
|
@ -96,6 +99,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
assertEquals(3, CharSetUtils.count("hello", "l-p"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCount_StringStringarray() {
|
||||
assertEquals(0, CharSetUtils.count(null, (String[]) null));
|
||||
assertEquals(0, CharSetUtils.count(null, new String[0]));
|
||||
|
@ -120,6 +124,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testKeep_StringString() {
|
||||
assertEquals(null, CharSetUtils.keep(null, (String) null));
|
||||
assertEquals(null, CharSetUtils.keep(null, ""));
|
||||
|
@ -136,6 +141,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
assertEquals("ell", CharSetUtils.keep("hello", "el"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeep_StringStringarray() {
|
||||
assertEquals(null, CharSetUtils.keep(null, (String[]) null));
|
||||
assertEquals(null, CharSetUtils.keep(null, new String[0]));
|
||||
|
@ -161,6 +167,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDelete_StringString() {
|
||||
assertEquals(null, CharSetUtils.delete(null, (String) null));
|
||||
assertEquals(null, CharSetUtils.delete(null, ""));
|
||||
|
@ -176,6 +183,7 @@ public class CharSetUtilsTest extends TestCase {
|
|||
assertEquals("hello", CharSetUtils.delete("hello", "z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete_StringStringarray() {
|
||||
assertEquals(null, CharSetUtils.delete(null, (String[]) null));
|
||||
assertEquals(null, CharSetUtils.delete(null, new String[0]));
|
||||
|
|
|
@ -17,6 +17,15 @@
|
|||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_5;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -29,24 +38,21 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.ClassUtils}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ClassUtilsTest extends TestCase {
|
||||
|
||||
public ClassUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class ClassUtilsTest {
|
||||
|
||||
private static class Inner {
|
||||
private class DeeplyNested{}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new ClassUtils());
|
||||
Constructor<?>[] cons = ClassUtils.class.getDeclaredConstructors();
|
||||
|
@ -57,6 +63,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_getShortClassName_Object() {
|
||||
assertEquals("ClassUtils", ClassUtils.getShortClassName(new ClassUtils(), "<null>"));
|
||||
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), "<null>"));
|
||||
|
@ -70,6 +77,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), "<null>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getShortClassName_Class() {
|
||||
assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class));
|
||||
assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class));
|
||||
|
@ -113,6 +121,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
|
||||
|
||||
|
||||
@Test
|
||||
public void test_getShortClassName_String() {
|
||||
assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class.getName()));
|
||||
assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class.getName()));
|
||||
|
@ -120,6 +129,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("", ClassUtils.getShortClassName(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getSimpleName_Class() {
|
||||
assertEquals("ClassUtils", ClassUtils.getSimpleName(ClassUtils.class));
|
||||
assertEquals("Entry", ClassUtils.getSimpleName(Map.Entry.class));
|
||||
|
@ -160,6 +170,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("Named", ClassUtils.getSimpleName(Named.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getSimpleName_Object() {
|
||||
assertEquals("ClassUtils", ClassUtils.getSimpleName(new ClassUtils(), "<null>"));
|
||||
assertEquals("Inner", ClassUtils.getSimpleName(new Inner(), "<null>"));
|
||||
|
@ -168,12 +179,14 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_getPackageName_Object() {
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new ClassUtils(), "<null>"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new Inner(), "<null>"));
|
||||
assertEquals("<null>", ClassUtils.getPackageName(null, "<null>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getPackageName_Class() {
|
||||
assertEquals("java.lang", ClassUtils.getPackageName(String.class));
|
||||
assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class));
|
||||
|
@ -203,6 +216,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(Named.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getPackageName_String() {
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(ClassUtils.class.getName()));
|
||||
assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class.getName()));
|
||||
|
@ -211,6 +225,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_getAllSuperclasses_Class() {
|
||||
List<?> list = ClassUtils.getAllSuperclasses(CY.class);
|
||||
assertEquals(2, list.size());
|
||||
|
@ -220,6 +235,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals(null, ClassUtils.getAllSuperclasses(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getAllInterfaces_Class() {
|
||||
List<?> list = ClassUtils.getAllInterfaces(CY.class);
|
||||
assertEquals(6, list.size());
|
||||
|
@ -251,6 +267,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_convertClassNamesToClasses_List() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<Class<?>> result = ClassUtils.convertClassNamesToClasses(list);
|
||||
|
@ -275,6 +292,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals(null, ClassUtils.convertClassNamesToClasses(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_convertClassesToClassNames_List() {
|
||||
List<Class<?>> list = new ArrayList<Class<?>>();
|
||||
List<String> result = ClassUtils.convertClassesToClassNames(list);
|
||||
|
@ -300,6 +318,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isInnerClass_Class() {
|
||||
assertEquals(true, ClassUtils.isInnerClass(Inner.class));
|
||||
assertEquals(true, ClassUtils.isInnerClass(Map.Entry.class));
|
||||
|
@ -311,6 +330,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isAssignable_ClassArray_ClassArray() throws Exception {
|
||||
Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
Class<?>[] array1 = new Class[] {Object.class};
|
||||
|
@ -341,6 +361,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue(ClassUtils.isAssignable(arrayWrappers, array2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_ClassArray_ClassArray_Autoboxing() throws Exception {
|
||||
Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
Class<?>[] array1 = new Class[] {Object.class};
|
||||
|
@ -368,6 +389,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue(ClassUtils.isAssignable(arrayWrappers, array2, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_ClassArray_ClassArray_NoAutoboxing() throws Exception {
|
||||
Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
Class<?>[] array1 = new Class[] {Object.class};
|
||||
|
@ -395,6 +417,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertFalse(ClassUtils.isAssignable(arrayPrimitives, array2, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable() throws Exception {
|
||||
assertFalse(ClassUtils.isAssignable((Class<?>) null, null));
|
||||
assertFalse(ClassUtils.isAssignable(String.class, null));
|
||||
|
@ -422,6 +445,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_Autoboxing() throws Exception {
|
||||
assertFalse(ClassUtils.isAssignable((Class<?>) null, null, true));
|
||||
assertFalse(ClassUtils.isAssignable(String.class, null, true));
|
||||
|
@ -445,6 +469,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_NoAutoboxing() throws Exception {
|
||||
assertFalse(ClassUtils.isAssignable((Class<?>) null, null, false));
|
||||
assertFalse(ClassUtils.isAssignable(String.class, null, false));
|
||||
|
@ -468,6 +493,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_Widening() throws Exception {
|
||||
// test byte conversions
|
||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.TYPE, Character.TYPE));
|
||||
|
@ -550,6 +576,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
|
||||
boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
|
||||
|
@ -634,6 +661,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("boolean -> boolean", autoboxing, ClassUtils.isAssignable(Boolean.class, Boolean.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_Unboxing_Widening() throws Exception {
|
||||
// test byte conversions
|
||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE, true));
|
||||
|
@ -716,6 +744,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPrimitiveOrWrapper() {
|
||||
|
||||
// test primitive wrapper classes
|
||||
|
@ -746,6 +775,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertFalse("this.getClass()", ClassUtils.isPrimitiveOrWrapper(this.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPrimitiveWrapper() {
|
||||
|
||||
// test primitive wrapper classes
|
||||
|
@ -776,6 +806,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertFalse("this.getClass()", ClassUtils.isPrimitiveWrapper(this.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveToWrapper() {
|
||||
|
||||
// test primitive classes
|
||||
|
@ -810,6 +841,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
ClassUtils.primitiveToWrapper(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitivesToWrappers() {
|
||||
// test null
|
||||
// assertNull("null -> null", ClassUtils.primitivesToWrappers(null)); // generates warning
|
||||
|
@ -820,7 +852,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
||||
// test empty array is returned unchanged
|
||||
// TODO this is not documented
|
||||
assertEquals("empty -> empty",
|
||||
assertArrayEquals("empty -> empty",
|
||||
ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY));
|
||||
|
||||
// test an array of various classes
|
||||
|
@ -847,6 +879,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertNotSame("unmodified", noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperToPrimitive() {
|
||||
// an array with classes to convert
|
||||
final Class<?>[] primitives = {
|
||||
|
@ -861,14 +894,17 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperToPrimitiveNoWrapper() {
|
||||
assertNull("Wrong result for non wrapper class", ClassUtils.wrapperToPrimitive(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperToPrimitiveNull() {
|
||||
assertNull("Wrong result for null class", ClassUtils.wrapperToPrimitive(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappersToPrimitives() {
|
||||
// an array with classes to test
|
||||
final Class<?>[] classes = {
|
||||
|
@ -887,6 +923,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappersToPrimitivesNull() {
|
||||
// assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives(null)); // generates warning
|
||||
assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives((Class<?>[]) null)); // equivalent cast
|
||||
|
@ -896,17 +933,20 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappersToPrimitivesEmpty() {
|
||||
Class<?>[] empty = new Class[0];
|
||||
assertEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
|
||||
assertArrayEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassClassNotFound() throws Exception {
|
||||
assertGetClassThrowsClassNotFound( "bool" );
|
||||
assertGetClassThrowsClassNotFound( "bool[]" );
|
||||
assertGetClassThrowsClassNotFound( "integer[]" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassInvalidArguments() throws Exception {
|
||||
assertGetClassThrowsNullPointerException( null );
|
||||
assertGetClassThrowsClassNotFound( "[][][]" );
|
||||
|
@ -917,6 +957,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertGetClassThrowsClassNotFound( "hello..world" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInterleavingWhitespace() throws ClassNotFoundException {
|
||||
assertEquals( int[].class, ClassUtils.getClass( " int [ ] " ) );
|
||||
assertEquals( long[].class, ClassUtils.getClass( "\rlong\t[\n]\r" ) );
|
||||
|
@ -924,6 +965,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals( byte[].class, ClassUtils.getClass( "byte[\t\t\n\r] " ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInnerClass() throws ClassNotFoundException {
|
||||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner.DeeplyNested" ) );
|
||||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner$DeeplyNested" ) );
|
||||
|
@ -931,6 +973,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest$Inner.DeeplyNested" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassByNormalNameArrays() throws ClassNotFoundException {
|
||||
assertEquals( int[].class, ClassUtils.getClass( "int[]" ) );
|
||||
assertEquals( long[].class, ClassUtils.getClass( "long[]" ) );
|
||||
|
@ -947,6 +990,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "[Ljava.util.Map$Entry;" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassByNormalNameArrays2D() throws ClassNotFoundException {
|
||||
assertEquals( int[][].class, ClassUtils.getClass( "int[][]" ) );
|
||||
assertEquals( long[][].class, ClassUtils.getClass( "long[][]" ) );
|
||||
|
@ -959,6 +1003,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals( String[][].class, ClassUtils.getClass( "java.lang.String[][]" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassWithArrayClasses2D() throws Exception {
|
||||
assertGetClassReturnsClass( String[][].class );
|
||||
assertGetClassReturnsClass( int[][].class );
|
||||
|
@ -971,6 +1016,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertGetClassReturnsClass( boolean[][].class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassWithArrayClasses() throws Exception {
|
||||
assertGetClassReturnsClass( String[].class );
|
||||
assertGetClassReturnsClass( int[].class );
|
||||
|
@ -983,6 +1029,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertGetClassReturnsClass( boolean[].class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassRawPrimitives() throws ClassNotFoundException {
|
||||
assertEquals( int.class, ClassUtils.getClass( "int" ) );
|
||||
assertEquals( long.class, ClassUtils.getClass( "long" ) );
|
||||
|
@ -1018,6 +1065,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
|
||||
// Show the Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957
|
||||
// We may have to delete this if a JDK fixes the bug.
|
||||
@Test
|
||||
public void testShowJavaBug() throws Exception {
|
||||
// Tests with Collections$UnmodifiableSet
|
||||
Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
|
||||
|
@ -1030,6 +1078,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPublicMethod() throws Exception {
|
||||
// Tests with Collections$UnmodifiableSet
|
||||
Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
|
||||
|
@ -1047,6 +1096,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals(Object.class.getMethod("toString", new Class[0]), toStringMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToClass_object() {
|
||||
// assertNull(ClassUtils.toClass(null)); // generates warning
|
||||
assertNull(ClassUtils.toClass((Object[]) null)); // equivalent explicit cast
|
||||
|
@ -1065,6 +1115,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
ClassUtils.toClass(new Object[] { "Test", null, Double.valueOf(99d) })));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getShortCanonicalName_Object() {
|
||||
assertEquals("<null>", ClassUtils.getShortCanonicalName(null, "<null>"));
|
||||
assertEquals("ClassUtils", ClassUtils.getShortCanonicalName(new ClassUtils(), "<null>"));
|
||||
|
@ -1080,6 +1131,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName(new Inner(), "<null>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getShortCanonicalName_Class() {
|
||||
assertEquals("ClassUtils", ClassUtils.getShortCanonicalName(ClassUtils.class));
|
||||
assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName(ClassUtils[].class));
|
||||
|
@ -1094,6 +1146,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName(Inner.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getShortCanonicalName_String() {
|
||||
assertEquals("ClassUtils", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils"));
|
||||
assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
|
||||
|
@ -1111,6 +1164,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getPackageCanonicalName_Object() {
|
||||
assertEquals("<null>", ClassUtils.getPackageCanonicalName(null, "<null>"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new ClassUtils(), "<null>"));
|
||||
|
@ -1126,6 +1180,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new Inner(), "<null>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getPackageCanonicalName_Class() {
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils.class));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils[].class));
|
||||
|
@ -1140,6 +1195,7 @@ public class ClassUtilsTest extends TestCase {
|
|||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(Inner.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getPackageCanonicalName_String() {
|
||||
assertEquals("org.apache.commons.lang3",
|
||||
ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils"));
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||
|
@ -29,15 +31,15 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
|
|||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
|
||||
import static org.apache.commons.lang3.JavaVersion.get;
|
||||
import static org.apache.commons.lang3.JavaVersion.getJavaVersion;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.JavaVersion}.
|
||||
*
|
||||
* @version $Id: JavaVersionTest.java 918366 2010-03-03 08:56:22Z bayard $
|
||||
*/
|
||||
public class JavaVersionTest extends TestCase {
|
||||
public class JavaVersionTest {
|
||||
|
||||
@Test
|
||||
public void testGetJavaVersion() {
|
||||
assertEquals("0.9 failed", JAVA_0_9, get("0.9"));
|
||||
assertEquals("1.1 failed", JAVA_1_1, get("1.1"));
|
||||
|
@ -52,6 +54,7 @@ public class JavaVersionTest extends TestCase {
|
|||
assertEquals("Wrapper method failed", get("1.5"), getJavaVersion("1.5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtLeast() {
|
||||
assertFalse("1.2 at least 1.5 passed", JAVA_1_2.atLeast(JAVA_1_5));
|
||||
assertTrue("1.5 at least 1.2 failed", JAVA_1_5.atLeast(JAVA_1_2));
|
||||
|
@ -61,6 +64,7 @@ public class JavaVersionTest extends TestCase {
|
|||
assertFalse("0.9 at least 1.6 passed", JAVA_0_9.atLeast(JAVA_1_6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("1.2", JAVA_1_2.toString());
|
||||
}
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
@ -28,14 +33,15 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LocaleUtils}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LocaleUtilsTest extends TestCase {
|
||||
public class LocaleUtilsTest {
|
||||
|
||||
private static final Locale LOCALE_EN = new Locale("en", "");
|
||||
private static final Locale LOCALE_EN_US = new Locale("en", "US");
|
||||
|
@ -45,19 +51,10 @@ public class LocaleUtilsTest extends TestCase {
|
|||
private static final Locale LOCALE_QQ = new Locale("qq", "");
|
||||
private static final Locale LOCALE_QQ_ZZ = new Locale("qq", "ZZ");
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public LocaleUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// Testing #LANG-304. Must be called before availableLocaleSet is called.
|
||||
LocaleUtils.isAvailableLocale(Locale.getDefault());
|
||||
}
|
||||
|
@ -66,6 +63,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test that constructors are public, and work, etc.
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new LocaleUtils());
|
||||
Constructor<?>[] cons = LocaleUtils.class.getDeclaredConstructors();
|
||||
|
@ -128,6 +126,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test toLocale() method.
|
||||
*/
|
||||
@Test
|
||||
public void testToLocale_1Part() {
|
||||
assertEquals(null, LocaleUtils.toLocale((String) null));
|
||||
|
||||
|
@ -174,6 +173,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test toLocale() method.
|
||||
*/
|
||||
@Test
|
||||
public void testToLocale_2Part() {
|
||||
assertValidToLocale("us_EN", "us", "EN");
|
||||
//valid though doesnt exist
|
||||
|
@ -208,6 +208,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test toLocale() method.
|
||||
*/
|
||||
@Test
|
||||
public void testToLocale_3Part() {
|
||||
assertValidToLocale("us_EN_A", "us", "EN", "A");
|
||||
// this isn't pretty, but was caused by a jdk bug it seems
|
||||
|
@ -252,6 +253,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test localeLookupList() method.
|
||||
*/
|
||||
@Test
|
||||
public void testLocaleLookupList_Locale() {
|
||||
assertLocaleLookupList(null, null, new Locale[0]);
|
||||
assertLocaleLookupList(LOCALE_QQ, null, new Locale[]{LOCALE_QQ});
|
||||
|
@ -271,6 +273,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test localeLookupList() method.
|
||||
*/
|
||||
@Test
|
||||
public void testLocaleLookupList_LocaleLocale() {
|
||||
assertLocaleLookupList(LOCALE_QQ, LOCALE_QQ,
|
||||
new Locale[]{LOCALE_QQ});
|
||||
|
@ -325,6 +328,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test availableLocaleList() method.
|
||||
*/
|
||||
@Test
|
||||
public void testAvailableLocaleList() {
|
||||
List<Locale> list = LocaleUtils.availableLocaleList();
|
||||
List<Locale> list2 = LocaleUtils.availableLocaleList();
|
||||
|
@ -341,6 +345,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test availableLocaleSet() method.
|
||||
*/
|
||||
@Test
|
||||
public void testAvailableLocaleSet() {
|
||||
Set<Locale> set = LocaleUtils.availableLocaleSet();
|
||||
Set<Locale> set2 = LocaleUtils.availableLocaleSet();
|
||||
|
@ -358,6 +363,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test availableLocaleSet() method.
|
||||
*/
|
||||
@Test
|
||||
public void testIsAvailableLocale() {
|
||||
Set<Locale> set = LocaleUtils.availableLocaleSet();
|
||||
assertEquals(set.contains(LOCALE_EN), LocaleUtils.isAvailableLocale(LOCALE_EN));
|
||||
|
@ -411,6 +417,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test languagesByCountry() method.
|
||||
*/
|
||||
@Test
|
||||
public void testLanguagesByCountry() {
|
||||
assertLanguageByCountry(null, new String[0]);
|
||||
assertLanguageByCountry("GB", new String[]{"en"});
|
||||
|
@ -461,6 +468,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Test countriesByLanguage() method.
|
||||
*/
|
||||
@Test
|
||||
public void testCountriesByLanguage() {
|
||||
assertCountriesByLanguage(null, new String[0]);
|
||||
assertCountriesByLanguage("de", new String[]{"DE", "CH", "AT", "LU"});
|
||||
|
@ -481,6 +489,7 @@ public class LocaleUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests #LANG-328 - only language+variant
|
||||
*/
|
||||
@Test
|
||||
public void testLang328() {
|
||||
assertValidToLocale("fr__POSIX", "fr", "", "POSIX");
|
||||
}
|
||||
|
|
|
@ -16,24 +16,26 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.RandomStringUtils}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RandomStringUtilsTest extends junit.framework.TestCase {
|
||||
/**
|
||||
* Construct a new instance of RandomStringUtilsTest with the specified name
|
||||
*/
|
||||
public RandomStringUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class RandomStringUtilsTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new RandomStringUtils());
|
||||
Constructor<?>[] cons = RandomStringUtils.class.getDeclaredConstructors();
|
||||
|
@ -47,6 +49,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
/**
|
||||
* Test the implementation
|
||||
*/
|
||||
@Test
|
||||
public void testRandomStringUtils() {
|
||||
String r1 = RandomStringUtils.random(50);
|
||||
assertEquals("random(50) length", 50, r1.length());
|
||||
|
@ -125,11 +128,13 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
assertEquals("random(0).equals(\"\")", "", r1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLANG805() {
|
||||
long seed = System.currentTimeMillis();
|
||||
assertEquals("aaa", RandomStringUtils.random(3,0,0,false,false,new char[]{'a'},new Random(seed)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLANG807() {
|
||||
try {
|
||||
RandomStringUtils.random(3,5,5,false,false);
|
||||
|
@ -141,6 +146,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptions() {
|
||||
final char[] DUMMY = new char[]{'a'}; // valid char array
|
||||
try {
|
||||
|
@ -185,6 +191,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
* Make sure boundary alphanumeric characters are generated by randomAlphaNumeric
|
||||
* This test will fail randomly with probability = 6 * (61/62)**1000 ~ 5.2E-7
|
||||
*/
|
||||
@Test
|
||||
public void testRandomAlphaNumeric() {
|
||||
char[] testChars = {'a', 'z', 'A', 'Z', '0', '9'};
|
||||
boolean[] found = {false, false, false, false, false, false};
|
||||
|
@ -208,6 +215,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
* Make sure '0' and '9' are generated by randomNumeric
|
||||
* This test will fail randomly with probability = 2 * (9/10)**1000 ~ 3.5E-46
|
||||
*/
|
||||
@Test
|
||||
public void testRandomNumeric() {
|
||||
char[] testChars = {'0','9'};
|
||||
boolean[] found = {false, false};
|
||||
|
@ -231,6 +239,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
* Make sure boundary alpha characters are generated by randomAlphabetic
|
||||
* This test will fail randomly with probability = 4 * (51/52)**1000 ~ 1.58E-8
|
||||
*/
|
||||
@Test
|
||||
public void testRandomAlphabetic() {
|
||||
char[] testChars = {'a', 'z', 'A', 'Z'};
|
||||
boolean[] found = {false, false, false, false};
|
||||
|
@ -254,6 +263,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
* Make sure 32 and 127 are generated by randomNumeric
|
||||
* This test will fail randomly with probability = 2*(95/96)**1000 ~ 5.7E-5
|
||||
*/
|
||||
@Test
|
||||
public void testRandomAscii() {
|
||||
char[] testChars = {(char) 32, (char) 126};
|
||||
boolean[] found = {false, false};
|
||||
|
@ -280,6 +290,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
* in generated strings. Will fail randomly about 1 in 1000 times.
|
||||
* Repeated failures indicate a problem.
|
||||
*/
|
||||
@Test
|
||||
public void testRandomStringUtilsHomog() {
|
||||
String set = "abc";
|
||||
char[] chars = set.toCharArray();
|
||||
|
@ -325,6 +336,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testLang100() throws Exception {
|
||||
int size = 5000;
|
||||
String encoding = "UTF-8";
|
||||
|
|
|
@ -16,20 +16,22 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.hamcrest.core.IsNot;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StringUtilsEqualsIndexOfTest extends TestCase {
|
||||
public class StringUtilsEqualsIndexOfTest {
|
||||
private static final String BAR = "bar";
|
||||
/**
|
||||
* Supplementary character U+20000
|
||||
|
@ -59,10 +61,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
|
||||
private static final String[] FOOBAR_SUB_ARRAY = new String[] {"ob", "ba"};
|
||||
|
||||
public StringUtilsEqualsIndexOfTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains_Char() {
|
||||
assertEquals(false, StringUtils.contains(null, ' '));
|
||||
assertEquals(false, StringUtils.contains("", ' '));
|
||||
|
@ -74,6 +73,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(false, StringUtils.contains("abc", 'z'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains_String() {
|
||||
assertEquals(false, StringUtils.contains(null, null));
|
||||
assertEquals(false, StringUtils.contains(null, ""));
|
||||
|
@ -91,6 +91,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContains_StringWithBadSupplementaryChars() {
|
||||
// Test edge case: 1/2 of a (broken) supplementary char
|
||||
assertEquals(false, StringUtils.contains(CharUSuppCharHigh, CharU20001));
|
||||
|
@ -105,6 +106,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContains_StringWithSupplementaryChars() {
|
||||
assertEquals(true, StringUtils.contains(CharU20000 + CharU20001, CharU20000));
|
||||
assertEquals(true, StringUtils.contains(CharU20000 + CharU20001, CharU20001));
|
||||
|
@ -112,6 +114,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(false, StringUtils.contains(CharU20000, CharU20001));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsAny_StringCharArray() {
|
||||
assertFalse(StringUtils.containsAny(null, (char[]) null));
|
||||
assertFalse(StringUtils.containsAny(null, new char[0]));
|
||||
|
@ -131,6 +134,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsAny_StringCharArrayWithBadSupplementaryChars() {
|
||||
// Test edge case: 1/2 of a (broken) supplementary char
|
||||
assertEquals(false, StringUtils.containsAny(CharUSuppCharHigh, CharU20001.toCharArray()));
|
||||
|
@ -145,6 +149,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsAny_StringCharArrayWithSupplementaryChars() {
|
||||
assertEquals(true, StringUtils.containsAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
|
||||
assertEquals(true, StringUtils.containsAny("a" + CharU20000 + CharU20001, "a".toCharArray()));
|
||||
|
@ -161,6 +166,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(false, StringUtils.containsAny(CharU20001, CharU20000.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsAny_StringString() {
|
||||
assertFalse(StringUtils.containsAny(null, (String) null));
|
||||
assertFalse(StringUtils.containsAny(null, ""));
|
||||
|
@ -180,6 +186,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsAny_StringWithBadSupplementaryChars() {
|
||||
// Test edge case: 1/2 of a (broken) supplementary char
|
||||
assertEquals(false, StringUtils.containsAny(CharUSuppCharHigh, CharU20001));
|
||||
|
@ -193,6 +200,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsAny_StringWithSupplementaryChars() {
|
||||
assertEquals(true, StringUtils.containsAny(CharU20000 + CharU20001, CharU20000));
|
||||
assertEquals(true, StringUtils.containsAny(CharU20000 + CharU20001, CharU20001));
|
||||
|
@ -206,6 +214,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(false, StringUtils.containsAny(CharU20001, CharU20000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsIgnoreCase_LocaleIndependence() {
|
||||
Locale orig = Locale.getDefault();
|
||||
|
||||
|
@ -240,6 +249,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsIgnoreCase_StringString() {
|
||||
assertFalse(StringUtils.containsIgnoreCase(null, null));
|
||||
|
||||
|
@ -274,6 +284,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertTrue(StringUtils.containsIgnoreCase("xabcz", "ABC"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsNone_CharArray() {
|
||||
String str1 = "a";
|
||||
String str2 = "b";
|
||||
|
@ -302,6 +313,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNone_CharArrayWithBadSupplementaryChars() {
|
||||
// Test edge case: 1/2 of a (broken) supplementary char
|
||||
assertEquals(true, StringUtils.containsNone(CharUSuppCharHigh, CharU20001.toCharArray()));
|
||||
|
@ -316,6 +328,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNone_CharArrayWithSupplementaryChars() {
|
||||
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20000.toCharArray()));
|
||||
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20001.toCharArray()));
|
||||
|
@ -329,6 +342,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(true, StringUtils.containsNone(CharU20001, CharU20000.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsNone_String() {
|
||||
String str1 = "a";
|
||||
String str2 = "b";
|
||||
|
@ -356,6 +370,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNone_StringWithBadSupplementaryChars() {
|
||||
// Test edge case: 1/2 of a (broken) supplementary char
|
||||
assertEquals(true, StringUtils.containsNone(CharUSuppCharHigh, CharU20001));
|
||||
|
@ -370,6 +385,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNone_StringWithSupplementaryChars() {
|
||||
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20000));
|
||||
assertEquals(false, StringUtils.containsNone(CharU20000 + CharU20001, CharU20001));
|
||||
|
@ -383,6 +399,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(true, StringUtils.containsNone(CharU20001, CharU20000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsOnly_CharArray() {
|
||||
String str1 = "a";
|
||||
String str2 = "b";
|
||||
|
@ -408,6 +425,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(true, StringUtils.containsOnly(str3, chars3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsOnly_String() {
|
||||
String str1 = "a";
|
||||
String str2 = "b";
|
||||
|
@ -432,6 +450,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(true, StringUtils.containsOnly(str3, chars3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsWhitespace() {
|
||||
assertFalse( StringUtils.containsWhitespace("") );
|
||||
assertTrue( StringUtils.containsWhitespace(" ") );
|
||||
|
@ -483,12 +502,14 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomCharSequence() {
|
||||
assertThat(new CustomCharSequence(FOO), IsNot.<CharSequence>not(FOO));
|
||||
assertThat(FOO, IsNot.<CharSequence>not(new CustomCharSequence(FOO)));
|
||||
assertEquals(new CustomCharSequence(FOO), new CustomCharSequence(FOO));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final CharSequence fooCs = FOO, barCs = BAR, foobarCs = FOOBAR;
|
||||
assertTrue(StringUtils.equals(null, null));
|
||||
|
@ -505,6 +526,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertFalse(StringUtils.equals(foobarCs, fooCs));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsOnStrings() {
|
||||
assertTrue(StringUtils.equals(null, null));
|
||||
assertTrue(StringUtils.equals(FOO, FOO));
|
||||
|
@ -517,6 +539,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertFalse(StringUtils.equals(FOOBAR, FOO));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsIgnoreCase() {
|
||||
assertEquals(true, StringUtils.equalsIgnoreCase(null, null));
|
||||
assertEquals(true, StringUtils.equalsIgnoreCase(FOO, FOO));
|
||||
|
@ -530,6 +553,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIndexOf_char() {
|
||||
assertEquals(-1, StringUtils.indexOf(null, ' '));
|
||||
assertEquals(-1, StringUtils.indexOf("", ' '));
|
||||
|
@ -539,6 +563,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(2, StringUtils.indexOf(new StringBuilder("aabaabaa"), 'b'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOf_charInt() {
|
||||
assertEquals(-1, StringUtils.indexOf(null, ' ', 0));
|
||||
assertEquals(-1, StringUtils.indexOf(null, ' ', -1));
|
||||
|
@ -553,6 +578,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(5, StringUtils.indexOf(new StringBuilder("aabaabaa"), 'b', 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOf_String() {
|
||||
assertEquals(-1, StringUtils.indexOf(null, null));
|
||||
assertEquals(-1, StringUtils.indexOf("", null));
|
||||
|
@ -565,6 +591,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(2, StringUtils.indexOf(new StringBuilder("aabaabaa"), "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOf_StringInt() {
|
||||
assertEquals(-1, StringUtils.indexOf(null, null, 0));
|
||||
assertEquals(-1, StringUtils.indexOf(null, null, -1));
|
||||
|
@ -590,6 +617,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(5, StringUtils.indexOf(new StringBuilder("aabaabaa"), "b", 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAny_StringCharArray() {
|
||||
assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null));
|
||||
assertEquals(-1, StringUtils.indexOfAny(null, new char[0]));
|
||||
|
@ -609,6 +637,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testIndexOfAny_StringCharArrayWithSupplementaryChars() {
|
||||
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
|
||||
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray()));
|
||||
|
@ -616,6 +645,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAny_StringString() {
|
||||
assertEquals(-1, StringUtils.indexOfAny(null, (String) null));
|
||||
assertEquals(-1, StringUtils.indexOfAny(null, ""));
|
||||
|
@ -632,6 +662,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(-1, StringUtils.indexOfAny("ab", "z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAny_StringStringArray() {
|
||||
assertEquals(-1, StringUtils.indexOfAny(null, (String[]) null));
|
||||
assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY));
|
||||
|
@ -652,6 +683,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
/**
|
||||
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
|
||||
*/
|
||||
@Test
|
||||
public void testIndexOfAny_StringStringWithSupplementaryChars() {
|
||||
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000));
|
||||
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001));
|
||||
|
@ -659,6 +691,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAnyBut_StringCharArray() {
|
||||
assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null));
|
||||
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0]));
|
||||
|
@ -677,6 +710,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAnyBut_StringCharArrayWithSupplementaryChars() {
|
||||
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000.toCharArray()));
|
||||
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001.toCharArray()));
|
||||
|
@ -684,6 +718,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAnyBut_StringString() {
|
||||
assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null));
|
||||
assertEquals(-1, StringUtils.indexOfAnyBut(null, ""));
|
||||
|
@ -700,6 +735,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(0, StringUtils.indexOfAnyBut("ab", "z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfAnyBut_StringStringWithSupplementaryChars() {
|
||||
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000));
|
||||
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001));
|
||||
|
@ -707,6 +743,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfIgnoreCase_String() {
|
||||
assertEquals(-1, StringUtils.indexOfIgnoreCase(null, null));
|
||||
assertEquals(-1, StringUtils.indexOfIgnoreCase(null, ""));
|
||||
|
@ -721,6 +758,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(0, StringUtils.indexOfIgnoreCase("aabaabaa", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfIgnoreCase_StringInt() {
|
||||
assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", -1));
|
||||
assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 0));
|
||||
|
@ -738,6 +776,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(-1, StringUtils.indexOfIgnoreCase("aab", "AAB", 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOf_char() {
|
||||
assertEquals(-1, StringUtils.lastIndexOf(null, ' '));
|
||||
assertEquals(-1, StringUtils.lastIndexOf("", ' '));
|
||||
|
@ -747,6 +786,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(5, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), 'b'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOf_charInt() {
|
||||
assertEquals(-1, StringUtils.lastIndexOf(null, ' ', 0));
|
||||
assertEquals(-1, StringUtils.lastIndexOf(null, ' ', -1));
|
||||
|
@ -762,6 +802,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(2, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), 'b', 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOf_String() {
|
||||
assertEquals(-1, StringUtils.lastIndexOf(null, null));
|
||||
assertEquals(-1, StringUtils.lastIndexOf("", null));
|
||||
|
@ -775,6 +816,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(4, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), "ab"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOf_StringInt() {
|
||||
assertEquals(-1, StringUtils.lastIndexOf(null, null, 0));
|
||||
assertEquals(-1, StringUtils.lastIndexOf(null, null, -1));
|
||||
|
@ -800,6 +842,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(2, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), "b", 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOfAny_StringStringArray() {
|
||||
assertEquals(-1, StringUtils.lastIndexOfAny(null, (CharSequence) null)); // test both types of ...
|
||||
assertEquals(-1, StringUtils.lastIndexOfAny(null, (CharSequence[]) null)); // ... varargs invocation
|
||||
|
@ -821,6 +864,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(-1, StringUtils.lastIndexOfAny(null, new String[] {null}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOfIgnoreCase_String() {
|
||||
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null));
|
||||
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", null));
|
||||
|
@ -838,6 +882,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aab", "AAB"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOfIgnoreCase_StringInt() {
|
||||
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, 0));
|
||||
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, -1));
|
||||
|
@ -862,6 +907,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(1, StringUtils.lastIndexOfIgnoreCase("aab", "AB", 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastOrdinalIndexOf() {
|
||||
assertEquals(-1, StringUtils.lastOrdinalIndexOf(null, "*", 42) );
|
||||
assertEquals(-1, StringUtils.lastOrdinalIndexOf("*", null, 42) );
|
||||
|
@ -876,6 +922,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
|
|||
assertEquals(8, StringUtils.lastOrdinalIndexOf("aabaabaa", "", 2) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrdinalIndexOf() {
|
||||
assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MIN_VALUE));
|
||||
assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MIN_VALUE));
|
||||
|
|
|
@ -16,21 +16,20 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StringUtilsIsTest extends TestCase {
|
||||
|
||||
public StringUtilsIsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class StringUtilsIsTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testIsAlpha() {
|
||||
assertEquals(false, StringUtils.isAlpha(null));
|
||||
assertEquals(false, StringUtils.isAlpha(""));
|
||||
|
@ -45,6 +44,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isAlpha("hkHKHik*khbkuh"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAlphanumeric() {
|
||||
assertEquals(false, StringUtils.isAlphanumeric(null));
|
||||
assertEquals(false, StringUtils.isAlphanumeric(""));
|
||||
|
@ -59,6 +59,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isAlphanumeric("hkHKHik*khbkuh"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsWhitespace() {
|
||||
assertEquals(false, StringUtils.isWhitespace(null));
|
||||
assertEquals(true, StringUtils.isWhitespace(""));
|
||||
|
@ -74,6 +75,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isWhitespace(StringUtilsTest.NON_WHITESPACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAlphaspace() {
|
||||
assertEquals(false, StringUtils.isAlphaSpace(null));
|
||||
assertEquals(true, StringUtils.isAlphaSpace(""));
|
||||
|
@ -88,6 +90,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isAlphaSpace("hkHKHik*khbkuh"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAlphanumericSpace() {
|
||||
assertEquals(false, StringUtils.isAlphanumericSpace(null));
|
||||
assertEquals(true, StringUtils.isAlphanumericSpace(""));
|
||||
|
@ -102,6 +105,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isAlphanumericSpace("hkHKHik*khbkuh"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAsciiPrintable_String() {
|
||||
assertEquals(false, StringUtils.isAsciiPrintable(null));
|
||||
assertEquals(true, StringUtils.isAsciiPrintable(""));
|
||||
|
@ -127,6 +131,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isAsciiPrintable("G\u00fclc\u00fc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNumeric() {
|
||||
assertEquals(false, StringUtils.isNumeric(null));
|
||||
assertEquals(false, StringUtils.isNumeric(""));
|
||||
|
@ -146,6 +151,7 @@ public class StringUtilsIsTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isNumeric("-123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNumericSpace() {
|
||||
assertEquals(false, StringUtils.isNumericSpace(null));
|
||||
assertEquals(true, StringUtils.isNumericSpace(""));
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.apache.commons.lang3.text.StrBuilder;
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ import org.apache.commons.lang3.text.StrBuilder;
|
|||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StringUtilsStartsEndsWithTest extends TestCase {
|
||||
public class StringUtilsStartsEndsWithTest {
|
||||
private static final String foo = "foo";
|
||||
private static final String bar = "bar";
|
||||
private static final String foobar = "foobar";
|
||||
|
@ -33,15 +33,12 @@ public class StringUtilsStartsEndsWithTest extends TestCase {
|
|||
private static final String BAR = "BAR";
|
||||
private static final String FOOBAR = "FOOBAR";
|
||||
|
||||
public StringUtilsStartsEndsWithTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Test StringUtils.startsWith()
|
||||
*/
|
||||
@Test
|
||||
public void testStartsWith() {
|
||||
assertTrue("startsWith(null, null)", StringUtils.startsWith(null, (String)null));
|
||||
assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, (String)null));
|
||||
|
@ -65,6 +62,7 @@ public class StringUtilsStartsEndsWithTest extends TestCase {
|
|||
/**
|
||||
* Test StringUtils.testStartsWithIgnoreCase()
|
||||
*/
|
||||
@Test
|
||||
public void testStartsWithIgnoreCase() {
|
||||
assertTrue("startsWithIgnoreCase(null, null)", StringUtils.startsWithIgnoreCase(null, (String)null));
|
||||
assertFalse("startsWithIgnoreCase(FOOBAR, null)", StringUtils.startsWithIgnoreCase(FOOBAR, (String)null));
|
||||
|
@ -85,6 +83,7 @@ public class StringUtilsStartsEndsWithTest extends TestCase {
|
|||
assertFalse("startsWithIgnoreCase(FOOBAR, bar)", StringUtils.startsWithIgnoreCase(FOOBAR, bar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartsWithAny() {
|
||||
assertFalse(StringUtils.startsWithAny(null, (String[])null));
|
||||
assertFalse(StringUtils.startsWithAny(null, "abc"));
|
||||
|
@ -102,6 +101,7 @@ public class StringUtilsStartsEndsWithTest extends TestCase {
|
|||
/**
|
||||
* Test StringUtils.endsWith()
|
||||
*/
|
||||
@Test
|
||||
public void testEndsWith() {
|
||||
assertTrue("endsWith(null, null)", StringUtils.endsWith(null, (String)null));
|
||||
assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR, (String)null));
|
||||
|
@ -125,6 +125,7 @@ public class StringUtilsStartsEndsWithTest extends TestCase {
|
|||
/**
|
||||
* Test StringUtils.endsWithIgnoreCase()
|
||||
*/
|
||||
@Test
|
||||
public void testEndsWithIgnoreCase() {
|
||||
assertTrue("endsWithIgnoreCase(null, null)", StringUtils.endsWithIgnoreCase(null, (String)null));
|
||||
assertFalse("endsWithIgnoreCase(FOOBAR, null)", StringUtils.endsWithIgnoreCase(FOOBAR, (String)null));
|
||||
|
@ -150,6 +151,7 @@ public class StringUtilsStartsEndsWithTest extends TestCase {
|
|||
assertFalse(StringUtils.endsWithIgnoreCase("ABCDEF", "cde"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndsWithAny() {
|
||||
assertFalse("StringUtils.endsWithAny(null, null)", StringUtils.endsWithAny(null, (String)null));
|
||||
assertFalse("StringUtils.endsWithAny(null, new String[] {abc})", StringUtils.endsWithAny(null, new String[] {"abc"}));
|
||||
|
|
|
@ -16,27 +16,27 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StringUtilsSubstringTest extends TestCase {
|
||||
public class StringUtilsSubstringTest {
|
||||
private static final String FOO = "foo";
|
||||
private static final String BAR = "bar";
|
||||
private static final String BAZ = "baz";
|
||||
private static final String FOOBAR = "foobar";
|
||||
private static final String SENTENCE = "foo bar baz";
|
||||
|
||||
public StringUtilsSubstringTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
@Test
|
||||
public void testSubstring_StringInt() {
|
||||
assertEquals(null, StringUtils.substring(null, 0));
|
||||
assertEquals("", StringUtils.substring("", 0));
|
||||
|
@ -57,6 +57,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertEquals("", StringUtils.substring("abc", 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstring_StringIntInt() {
|
||||
assertEquals(null, StringUtils.substring(null, 0, 0));
|
||||
assertEquals(null, StringUtils.substring(null, 1, 2));
|
||||
|
@ -74,6 +75,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertEquals("b",StringUtils.substring("abc", -2, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeft_String() {
|
||||
assertSame(null, StringUtils.left(null, -1));
|
||||
assertSame(null, StringUtils.left(null, 0));
|
||||
|
@ -89,6 +91,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertSame(FOOBAR, StringUtils.left(FOOBAR, 80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRight_String() {
|
||||
assertSame(null, StringUtils.right(null, -1));
|
||||
assertSame(null, StringUtils.right(null, 0));
|
||||
|
@ -104,6 +107,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertSame(FOOBAR, StringUtils.right(FOOBAR, 80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMid_String() {
|
||||
assertSame(null, StringUtils.mid(null, -1, 0));
|
||||
assertSame(null, StringUtils.mid(null, 0, -1));
|
||||
|
@ -126,6 +130,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSubstringBefore_StringString() {
|
||||
assertEquals("foo", StringUtils.substringBefore("fooXXbarXXbaz", "XX"));
|
||||
|
||||
|
@ -145,6 +150,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertEquals("", StringUtils.substringBefore("abc", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstringAfter_StringString() {
|
||||
assertEquals("barXXbaz", StringUtils.substringAfter("fooXXbarXXbaz", "XX"));
|
||||
|
||||
|
@ -164,6 +170,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertEquals("", StringUtils.substringAfter("abc", "d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstringBeforeLast_StringString() {
|
||||
assertEquals("fooXXbar", StringUtils.substringBeforeLast("fooXXbarXXbaz", "XX"));
|
||||
|
||||
|
@ -187,6 +194,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertEquals("", StringUtils.substringBeforeLast("a", "a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstringAfterLast_StringString() {
|
||||
assertEquals("baz", StringUtils.substringAfterLast("fooXXbarXXbaz", "XX"));
|
||||
|
||||
|
@ -208,6 +216,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSubstringBetween_StringString() {
|
||||
assertEquals(null, StringUtils.substringBetween(null, "tag"));
|
||||
assertEquals("", StringUtils.substringBetween("", ""));
|
||||
|
@ -221,6 +230,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
assertEquals("bar", StringUtils.substringBetween("\nbar\n", "\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstringBetween_StringStringString() {
|
||||
assertEquals(null, StringUtils.substringBetween(null, "", ""));
|
||||
assertEquals(null, StringUtils.substringBetween("", null, ""));
|
||||
|
@ -236,6 +246,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
/**
|
||||
* Tests the substringsBetween method that returns an String Array of substrings.
|
||||
*/
|
||||
@Test
|
||||
public void testSubstringsBetween_StringStringString() {
|
||||
|
||||
String[] results = StringUtils.substringsBetween("[one], [two], [three]", "[", "]");
|
||||
|
@ -294,6 +305,7 @@ public class StringUtilsSubstringTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCountMatches_String() {
|
||||
assertEquals(0, StringUtils.countMatches(null, null));
|
||||
assertEquals(0, StringUtils.countMatches("blah", null));
|
||||
|
|
|
@ -16,21 +16,22 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Trim/Empty methods
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StringUtilsTrimEmptyTest extends TestCase {
|
||||
public class StringUtilsTrimEmptyTest {
|
||||
private static final String FOO = "foo";
|
||||
|
||||
public StringUtilsTrimEmptyTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsEmpty() {
|
||||
assertEquals(true, StringUtils.isEmpty(null));
|
||||
assertEquals(true, StringUtils.isEmpty(""));
|
||||
|
@ -39,6 +40,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isEmpty(" foo "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotEmpty() {
|
||||
assertEquals(false, StringUtils.isNotEmpty(null));
|
||||
assertEquals(false, StringUtils.isNotEmpty(""));
|
||||
|
@ -47,6 +49,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(true, StringUtils.isNotEmpty(" foo "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsBlank() {
|
||||
assertEquals(true, StringUtils.isBlank(null));
|
||||
assertEquals(true, StringUtils.isBlank(""));
|
||||
|
@ -55,6 +58,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(false, StringUtils.isBlank(" foo "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotBlank() {
|
||||
assertEquals(false, StringUtils.isNotBlank(null));
|
||||
assertEquals(false, StringUtils.isNotBlank(""));
|
||||
|
@ -64,6 +68,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTrim() {
|
||||
assertEquals(FOO, StringUtils.trim(FOO + " "));
|
||||
assertEquals(FOO, StringUtils.trim(" " + FOO + " "));
|
||||
|
@ -76,6 +81,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(null, StringUtils.trim(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrimToNull() {
|
||||
assertEquals(FOO, StringUtils.trimToNull(FOO + " "));
|
||||
assertEquals(FOO, StringUtils.trimToNull(" " + FOO + " "));
|
||||
|
@ -88,6 +94,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(null, StringUtils.trimToNull(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrimToEmpty() {
|
||||
assertEquals(FOO, StringUtils.trimToEmpty(FOO + " "));
|
||||
assertEquals(FOO, StringUtils.trimToEmpty(" " + FOO + " "));
|
||||
|
@ -101,6 +108,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testStrip_String() {
|
||||
assertEquals(null, StringUtils.strip(null));
|
||||
assertEquals("", StringUtils.strip(""));
|
||||
|
@ -110,6 +118,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
StringUtils.strip(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripToNull_String() {
|
||||
assertEquals(null, StringUtils.stripToNull(null));
|
||||
assertEquals(null, StringUtils.stripToNull(""));
|
||||
|
@ -120,6 +129,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
StringUtils.stripToNull(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripToEmpty_String() {
|
||||
assertEquals("", StringUtils.stripToEmpty(null));
|
||||
assertEquals("", StringUtils.stripToEmpty(""));
|
||||
|
@ -130,6 +140,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
StringUtils.stripToEmpty(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrip_StringString() {
|
||||
// null strip
|
||||
assertEquals(null, StringUtils.strip(null, null));
|
||||
|
@ -161,6 +172,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(StringUtilsTest.WHITESPACE, StringUtils.strip(StringUtilsTest.WHITESPACE, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripStart_StringString() {
|
||||
// null stripStart
|
||||
assertEquals(null, StringUtils.stripStart(null, null));
|
||||
|
@ -192,6 +204,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(StringUtilsTest.WHITESPACE, StringUtils.stripStart(StringUtilsTest.WHITESPACE, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripEnd_StringString() {
|
||||
// null stripEnd
|
||||
assertEquals(null, StringUtils.stripEnd(null, null));
|
||||
|
@ -223,6 +236,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals(StringUtilsTest.WHITESPACE, StringUtils.stripEnd(StringUtilsTest.WHITESPACE, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripAll() {
|
||||
// test stripAll method, merely an array version of the above strip
|
||||
String[] empty = new String[0];
|
||||
|
@ -230,8 +244,7 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
String[] fooDots = new String[] { ".."+FOO+"..", ".."+FOO, FOO+".." };
|
||||
String[] foo = new String[] { FOO, FOO, FOO };
|
||||
|
||||
// assertEquals(null, StringUtils.stripAll(null)); // generates warning
|
||||
assertEquals(null, StringUtils.stripAll((String[]) null)); // equivalent explicit cast
|
||||
assertNull(StringUtils.stripAll((String[]) null));
|
||||
// Additional varargs tests
|
||||
assertArrayEquals(empty, StringUtils.stripAll()); // empty array
|
||||
assertArrayEquals(new String[]{null}, StringUtils.stripAll((String) null)); // == new String[]{null}
|
||||
|
@ -239,11 +252,12 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertArrayEquals(empty, StringUtils.stripAll(empty));
|
||||
assertArrayEquals(foo, StringUtils.stripAll(fooSpace));
|
||||
|
||||
assertEquals(null, StringUtils.stripAll(null, null));
|
||||
assertNull(StringUtils.stripAll(null, null));
|
||||
assertArrayEquals(foo, StringUtils.stripAll(fooSpace, null));
|
||||
assertArrayEquals(foo, StringUtils.stripAll(fooDots, "."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripAccents() {
|
||||
String cue = "\u00C7\u00FA\u00EA";
|
||||
assertEquals( "Failed to strip accents from " + cue, "Cue", StringUtils.stripAccents(cue));
|
||||
|
@ -260,24 +274,4 @@ public class StringUtilsTrimEmptyTest extends TestCase {
|
|||
assertEquals( "Failed to handle non-accented text", "control", StringUtils.stripAccents("control") );
|
||||
assertEquals( "Failed to handle easy example", "eclair", StringUtils.stripAccents("\u00E9clair") );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
private void assertArrayEquals(Object[] o1, Object[] o2) {
|
||||
if(o1 == null) {
|
||||
assertEquals(o1,o2);
|
||||
return;
|
||||
}
|
||||
assertEquals("Length not equal. ", o1.length, o2.length);
|
||||
int sz = o1.length;
|
||||
for(int i=0; i<sz; i++) {
|
||||
if(o1[i] instanceof Object[]) {
|
||||
// do an assert equals on type....
|
||||
assertArrayEquals( (Object[]) o1[i], (Object[]) o2[i] );
|
||||
} else {
|
||||
assertEquals(o1[i], o2[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -27,7 +29,6 @@ import java.lang.reflect.Modifier;
|
|||
import java.util.Locale;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.SystemUtils}.
|
||||
|
@ -36,12 +37,9 @@ import junit.framework.TestCase;
|
|||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SystemUtilsTest extends TestCase {
|
||||
|
||||
public SystemUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class SystemUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new SystemUtils());
|
||||
Constructor<?>[] cons = SystemUtils.class.getDeclaredConstructors();
|
||||
|
@ -54,6 +52,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
/**
|
||||
* Assums no security manager exists.
|
||||
*/
|
||||
@Test
|
||||
public void testGetJavaHome() {
|
||||
File dir = SystemUtils.getJavaHome();
|
||||
Assert.assertNotNull(dir);
|
||||
|
@ -63,6 +62,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
/**
|
||||
* Assums no security manager exists.
|
||||
*/
|
||||
@Test
|
||||
public void testGetJavaIoTmpDir() {
|
||||
File dir = SystemUtils.getJavaIoTmpDir();
|
||||
Assert.assertNotNull(dir);
|
||||
|
@ -72,6 +72,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
/**
|
||||
* Assums no security manager exists.
|
||||
*/
|
||||
@Test
|
||||
public void testGetUserDir() {
|
||||
File dir = SystemUtils.getUserDir();
|
||||
Assert.assertNotNull(dir);
|
||||
|
@ -81,12 +82,14 @@ public class SystemUtilsTest extends TestCase {
|
|||
/**
|
||||
* Assums no security manager exists.
|
||||
*/
|
||||
@Test
|
||||
public void testGetUserHome() {
|
||||
File dir = SystemUtils.getUserHome();
|
||||
Assert.assertNotNull(dir);
|
||||
Assert.assertTrue(dir.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIS_JAVA() {
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
if (javaVersion == null) {
|
||||
|
@ -150,6 +153,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIS_OS() {
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName == null) {
|
||||
|
@ -186,6 +190,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaVersionMatches() {
|
||||
String javaVersion = null;
|
||||
assertEquals(false, SystemUtils.isJavaVersionMatch(javaVersion, "1.0"));
|
||||
|
@ -306,6 +311,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
assertEquals(true, SystemUtils.isJavaVersionMatch(javaVersion, "1.7"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOSMatchesName() {
|
||||
String osName = null;
|
||||
assertEquals(false, SystemUtils.isOSNameMatch(osName, "Windows"));
|
||||
|
@ -319,6 +325,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
assertEquals(false, SystemUtils.isOSNameMatch(osName, "Windows"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOSMatchesNameAndVersion() {
|
||||
String osName = null;
|
||||
String osVersion = null;
|
||||
|
@ -343,6 +350,7 @@ public class SystemUtilsTest extends TestCase {
|
|||
assertEquals(false, SystemUtils.isOSMatch(osName, osVersion, "Windows 9", "4.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaAwtHeadless() {
|
||||
boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(JAVA_1_4);
|
||||
String expectedStringValue = System.getProperty("java.awt.headless");
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.AbstractList;
|
||||
|
@ -28,20 +33,17 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.Validate}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ValidateTest extends TestCase {
|
||||
|
||||
public ValidateTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class ValidateTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsTrue1() {
|
||||
Validate.isTrue(true);
|
||||
try {
|
||||
|
@ -53,6 +55,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsTrue2() {
|
||||
Validate.isTrue(true, "MSG");
|
||||
try {
|
||||
|
@ -64,6 +67,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsTrue3() {
|
||||
Validate.isTrue(true, "MSG", 6);
|
||||
try {
|
||||
|
@ -75,6 +79,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsTrue4() {
|
||||
Validate.isTrue(true, "MSG", 7);
|
||||
try {
|
||||
|
@ -86,6 +91,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsTrue5() {
|
||||
Validate.isTrue(true, "MSG", 7.4d);
|
||||
try {
|
||||
|
@ -98,6 +104,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotNull1() {
|
||||
Validate.notNull(new Object());
|
||||
try {
|
||||
|
@ -113,6 +120,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotNull2() {
|
||||
Validate.notNull(new Object(), "MSG");
|
||||
try {
|
||||
|
@ -129,6 +137,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyArray1() {
|
||||
Validate.notEmpty(new Object[] {null});
|
||||
try {
|
||||
|
@ -150,6 +159,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyArray2() {
|
||||
Validate.notEmpty(new Object[] {null}, "MSG");
|
||||
try {
|
||||
|
@ -172,6 +182,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyCollection1() {
|
||||
Collection<Integer> coll = new ArrayList<Integer>();
|
||||
try {
|
||||
|
@ -194,6 +205,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyCollection2() {
|
||||
Collection<Integer> coll = new ArrayList<Integer>();
|
||||
try {
|
||||
|
@ -217,6 +229,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyMap1() {
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
try {
|
||||
|
@ -239,6 +252,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyMap2() {
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
try {
|
||||
|
@ -262,6 +276,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyString1() {
|
||||
Validate.notEmpty("hjl");
|
||||
try {
|
||||
|
@ -283,6 +298,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotEmptyString2() {
|
||||
Validate.notEmpty("a", "MSG");
|
||||
try {
|
||||
|
@ -305,6 +321,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankNullStringShouldThrow() {
|
||||
//given
|
||||
String string = null;
|
||||
|
@ -320,6 +337,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgNullStringShouldThrow() {
|
||||
//given
|
||||
String string = null;
|
||||
|
@ -335,6 +353,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankEmptyStringShouldThrow() {
|
||||
//given
|
||||
String string = "";
|
||||
|
@ -350,6 +369,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankBlankStringWithWhitespacesShouldThrow() {
|
||||
//given
|
||||
String string = " ";
|
||||
|
@ -365,6 +385,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankBlankStringWithNewlinesShouldThrow() {
|
||||
//given
|
||||
String string = " \n \t \r \n ";
|
||||
|
@ -380,6 +401,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgBlankStringShouldThrow() {
|
||||
//given
|
||||
String string = " \n \t \r \n ";
|
||||
|
@ -395,6 +417,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgBlankStringWithWhitespacesShouldThrow() {
|
||||
//given
|
||||
String string = " ";
|
||||
|
@ -410,6 +433,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgEmptyStringShouldThrow() {
|
||||
//given
|
||||
String string = "";
|
||||
|
@ -425,6 +449,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankNotBlankStringShouldNotThrow() {
|
||||
//given
|
||||
String string = "abc";
|
||||
|
@ -436,6 +461,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankNotBlankStringWithWhitespacesShouldNotThrow() {
|
||||
//given
|
||||
String string = " abc ";
|
||||
|
@ -447,6 +473,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankNotBlankStringWithNewlinesShouldNotThrow() {
|
||||
//given
|
||||
String string = " \n \t abc \r \n ";
|
||||
|
@ -458,6 +485,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgNotBlankStringShouldNotThrow() {
|
||||
//given
|
||||
String string = "abc";
|
||||
|
@ -469,6 +497,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgNotBlankStringWithWhitespacesShouldNotThrow() {
|
||||
//given
|
||||
String string = " abc ";
|
||||
|
@ -480,6 +509,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankMsgNotBlankStringWithNewlinesShouldNotThrow() {
|
||||
//given
|
||||
String string = " \n \t abc \r \n ";
|
||||
|
@ -491,12 +521,14 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNotBlankReturnValues1() {
|
||||
String str = "Hi";
|
||||
String test = Validate.notBlank(str);
|
||||
assertSame(str, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotBlankReturnValues2() {
|
||||
String str = "Hi";
|
||||
String test = Validate.notBlank(str, "Message");
|
||||
|
@ -505,6 +537,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNoNullElementsArray1() {
|
||||
String[] array = new String[] {"a", "b"};
|
||||
Validate.noNullElements(array);
|
||||
|
@ -528,6 +561,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNoNullElementsArray2() {
|
||||
String[] array = new String[] {"a", "b"};
|
||||
Validate.noNullElements(array, "MSG");
|
||||
|
@ -552,6 +586,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNoNullElementsCollection1() {
|
||||
List<String> coll = new ArrayList<String>();
|
||||
coll.add("a");
|
||||
|
@ -577,6 +612,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNoNullElementsCollection2() {
|
||||
List<String> coll = new ArrayList<String>();
|
||||
coll.add("a");
|
||||
|
@ -603,6 +639,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new Validate());
|
||||
Constructor<?>[] cons = Validate.class.getDeclaredConstructors();
|
||||
|
@ -614,6 +651,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testValidIndex_withMessage_array() {
|
||||
Object[] array = new Object[2];
|
||||
Validate.validIndex(array, 0, "Broken: ");
|
||||
|
@ -636,6 +674,7 @@ public class ValidateTest extends TestCase {
|
|||
assertSame(strArray, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidIndex_array() {
|
||||
Object[] array = new Object[2];
|
||||
Validate.validIndex(array, 0);
|
||||
|
@ -660,6 +699,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testValidIndex_withMessage_collection() {
|
||||
Collection<String> coll = new ArrayList<String>();
|
||||
coll.add(null);
|
||||
|
@ -684,6 +724,7 @@ public class ValidateTest extends TestCase {
|
|||
assertSame(strColl, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidIndex_collection() {
|
||||
Collection<String> coll = new ArrayList<String>();
|
||||
coll.add(null);
|
||||
|
@ -710,6 +751,7 @@ public class ValidateTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testValidIndex_withMessage_charSequence() {
|
||||
CharSequence str = "Hi";
|
||||
Validate.validIndex(str, 0, "Broken: ");
|
||||
|
@ -732,6 +774,7 @@ public class ValidateTest extends TestCase {
|
|||
assertSame(input, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidIndex_charSequence() {
|
||||
CharSequence str = "Hi";
|
||||
Validate.validIndex(str, 0);
|
||||
|
@ -754,6 +797,7 @@ public class ValidateTest extends TestCase {
|
|||
assertSame(input, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchesPattern()
|
||||
{
|
||||
CharSequence str = "hi";
|
||||
|
@ -769,6 +813,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchesPattern_withMessage()
|
||||
{
|
||||
CharSequence str = "hi";
|
||||
|
@ -784,6 +829,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveBetween()
|
||||
{
|
||||
Validate.inclusiveBetween("a", "c", "b");
|
||||
|
@ -797,6 +843,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveBetween_withMessage()
|
||||
{
|
||||
Validate.inclusiveBetween("a", "c", "b", "Error");
|
||||
|
@ -810,6 +857,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExclusiveBetween()
|
||||
{
|
||||
Validate.exclusiveBetween("a", "c", "b");
|
||||
|
@ -828,6 +876,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExclusiveBetween_withMessage()
|
||||
{
|
||||
Validate.exclusiveBetween("a", "c", "b", "Error");
|
||||
|
@ -846,11 +895,13 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsInstanceOf() {
|
||||
Validate.isInstanceOf(String.class, "hi");
|
||||
Validate.isInstanceOf(Integer.class, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsInstanceOfExceptionMessage() {
|
||||
try {
|
||||
Validate.isInstanceOf(List.class, "hi");
|
||||
|
@ -860,6 +911,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsInstanceOf_withMessage() {
|
||||
Validate.isInstanceOf(String.class, "hi", "Error");
|
||||
Validate.isInstanceOf(Integer.class, 1, "Error");
|
||||
|
@ -871,11 +923,13 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAssignable() {
|
||||
Validate.isAssignableFrom(CharSequence.class, String.class);
|
||||
Validate.isAssignableFrom(AbstractList.class, ArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAssignableExceptionMessage() {
|
||||
try {
|
||||
Validate.isAssignableFrom(List.class, String.class);
|
||||
|
@ -885,6 +939,7 @@ public class ValidateTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAssignable_withMessage() {
|
||||
Validate.isAssignableFrom(CharSequence.class, String.class, "Error");
|
||||
Validate.isAssignableFrom(AbstractList.class, ArrayList.class, "Error");
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BackgroundInitializerTest extends TestCase {
|
||||
public class BackgroundInitializerTest {
|
||||
/**
|
||||
* Helper method for checking whether the initialize() method was correctly
|
||||
* called. start() must already have been invoked.
|
||||
|
@ -45,6 +45,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests whether initialize() is invoked.
|
||||
*/
|
||||
@Test
|
||||
public void testInitialize() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
init.start();
|
||||
|
@ -55,6 +56,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
* Tries to obtain the executor before start(). It should not have been
|
||||
* initialized yet.
|
||||
*/
|
||||
@Test
|
||||
public void testGetActiveExecutorBeforeStart() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
assertNull("Got an executor", init.getActiveExecutor());
|
||||
|
@ -63,6 +65,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests whether an external executor is correctly detected.
|
||||
*/
|
||||
@Test
|
||||
public void testGetActiveExecutorExternal() {
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
|
@ -79,6 +82,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests getActiveExecutor() for a temporary executor.
|
||||
*/
|
||||
@Test
|
||||
public void testGetActiveExecutorTemp() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
init.start();
|
||||
|
@ -90,6 +94,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
* Tests the execution of the background task if a temporary executor has to
|
||||
* be created.
|
||||
*/
|
||||
@Test
|
||||
public void testInitializeTempExecutor() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
assertTrue("Wrong result of start()", init.start());
|
||||
|
@ -102,6 +107,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
* Tests whether an external executor can be set using the
|
||||
* setExternalExecutor() method.
|
||||
*/
|
||||
@Test
|
||||
public void testSetExternalExecutor() throws Exception {
|
||||
ExecutorService exec = Executors.newCachedThreadPool();
|
||||
try {
|
||||
|
@ -121,6 +127,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests that setting an executor after start() causes an exception.
|
||||
*/
|
||||
@Test
|
||||
public void testSetExternalExecutorAfterStart() throws ConcurrentException {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
init.start();
|
||||
|
@ -136,6 +143,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
* Tests invoking start() multiple times. Only the first invocation should
|
||||
* have an effect.
|
||||
*/
|
||||
@Test
|
||||
public void testStartMultipleTimes() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
assertTrue("Wrong result for start()", init.start());
|
||||
|
@ -148,6 +156,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests calling get() before start(). This should cause an exception.
|
||||
*/
|
||||
@Test
|
||||
public void testGetBeforeStart() throws ConcurrentException {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
try {
|
||||
|
@ -162,6 +171,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
* Tests the get() method if background processing causes a runtime
|
||||
* exception.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRuntimeException() throws Exception {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
RuntimeException rex = new RuntimeException();
|
||||
|
@ -179,6 +189,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
* Tests the get() method if background processing causes a checked
|
||||
* exception.
|
||||
*/
|
||||
@Test
|
||||
public void testGetCheckedException() throws Exception {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
Exception ex = new Exception();
|
||||
|
@ -195,6 +206,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests the get() method if waiting for the initialization is interrupted.
|
||||
*/
|
||||
@Test
|
||||
public void testGetInterruptedException() throws Exception {
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl(
|
||||
|
@ -229,6 +241,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests isStarted() before start() was called.
|
||||
*/
|
||||
@Test
|
||||
public void testIsStartedFalse() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
assertFalse("Already started", init.isStarted());
|
||||
|
@ -237,6 +250,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests isStarted() after start().
|
||||
*/
|
||||
@Test
|
||||
public void testIsStartedTrue() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
init.start();
|
||||
|
@ -246,6 +260,7 @@ public class BackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests isStarted() after the background task has finished.
|
||||
*/
|
||||
@Test
|
||||
public void testIsStartedAfterGet() {
|
||||
BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
init.start();
|
||||
|
|
|
@ -16,18 +16,21 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test class for {@code CallableBackgroundInitializer}
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CallableBackgroundInitializerTest extends TestCase {
|
||||
public class CallableBackgroundInitializerTest {
|
||||
/** Constant for the result of the call() invocation. */
|
||||
private static final Integer RESULT = Integer.valueOf(42);
|
||||
|
||||
|
@ -35,6 +38,7 @@ public class CallableBackgroundInitializerTest extends TestCase {
|
|||
* Tries to create an instance without a Callable. This should cause an
|
||||
* exception.
|
||||
*/
|
||||
@Test
|
||||
public void testInitNullCallable() {
|
||||
try {
|
||||
new CallableBackgroundInitializer<Object>(null);
|
||||
|
@ -48,6 +52,7 @@ public class CallableBackgroundInitializerTest extends TestCase {
|
|||
* Tests whether the executor service is correctly passed to the super
|
||||
* class.
|
||||
*/
|
||||
@Test
|
||||
public void testInitExecutor() {
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<Integer>(
|
||||
|
@ -59,6 +64,7 @@ public class CallableBackgroundInitializerTest extends TestCase {
|
|||
* Tries to pass a null Callable to the constructor that takes an executor.
|
||||
* This should cause an exception.
|
||||
*/
|
||||
@Test
|
||||
public void testInitExecutorNullCallable() {
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
|
@ -72,6 +78,7 @@ public class CallableBackgroundInitializerTest extends TestCase {
|
|||
/**
|
||||
* Tests the implementation of initialize().
|
||||
*/
|
||||
@Test
|
||||
public void testInitialize() throws Exception {
|
||||
TestCallable call = new TestCallable();
|
||||
CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<Integer>(
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
package org.apache.commons.lang3.event;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.beans.VetoableChangeListener;
|
||||
|
@ -30,16 +34,16 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @since 3.0
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EventListenerSupportTest extends TestCase
|
||||
public class EventListenerSupportTest
|
||||
{
|
||||
@Test
|
||||
public void testAddNullListener()
|
||||
{
|
||||
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
|
||||
|
@ -54,6 +58,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNullListener()
|
||||
{
|
||||
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
|
||||
|
@ -68,6 +73,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventDispatchOrder() throws PropertyVetoException
|
||||
{
|
||||
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
|
||||
|
@ -83,6 +89,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
assertSame(calledListeners.get(1), listener2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithNonInterfaceParameter()
|
||||
{
|
||||
try
|
||||
|
@ -96,6 +103,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithNullParameter()
|
||||
{
|
||||
try
|
||||
|
@ -109,6 +117,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveListenerDuringEvent() throws PropertyVetoException
|
||||
{
|
||||
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
|
||||
|
@ -121,6 +130,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
assertEquals(listenerSupport.getListenerCount(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetListeners() {
|
||||
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
|
||||
|
||||
|
@ -143,6 +153,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
assertSame(empty, listenerSupport.getListeners());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
|
||||
EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
|
||||
listenerSupport.addListener(new VetoableChangeListener() {
|
||||
|
@ -183,6 +194,7 @@ public class EventListenerSupportTest extends TestCase
|
|||
assertEquals(0, deserializedListenerSupport.getListeners().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubclassInvocationHandling() throws PropertyVetoException {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.event;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.VetoableChangeListener;
|
||||
|
@ -30,15 +34,16 @@ import java.util.TreeMap;
|
|||
|
||||
import javax.naming.event.ObjectChangeListener;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @since 3.0
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EventUtilsTest extends TestCase
|
||||
public class EventUtilsTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new EventUtils());
|
||||
Constructor<?>[] cons = EventUtils.class.getDeclaredConstructors();
|
||||
|
@ -48,6 +53,7 @@ public class EventUtilsTest extends TestCase
|
|||
assertEquals(false, Modifier.isFinal(EventUtils.class.getModifiers()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddEventListener()
|
||||
{
|
||||
final PropertyChangeSource src = new PropertyChangeSource();
|
||||
|
@ -60,6 +66,7 @@ public class EventUtilsTest extends TestCase
|
|||
assertEquals(1, handler.getEventCount("propertyChange"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddEventListenerWithNoAddMethod()
|
||||
{
|
||||
final PropertyChangeSource src = new PropertyChangeSource();
|
||||
|
@ -76,6 +83,7 @@ public class EventUtilsTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddEventListenerThrowsException()
|
||||
{
|
||||
final ExceptionEventSource src = new ExceptionEventSource();
|
||||
|
@ -97,6 +105,7 @@ public class EventUtilsTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddEventListenerWithPrivateAddMethod()
|
||||
{
|
||||
final PropertyChangeSource src = new PropertyChangeSource();
|
||||
|
@ -113,6 +122,7 @@ public class EventUtilsTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindEventsToMethod()
|
||||
{
|
||||
final PropertyChangeSource src = new PropertyChangeSource();
|
||||
|
@ -124,6 +134,7 @@ public class EventUtilsTest extends TestCase
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBindEventsToMethodWithEvent()
|
||||
{
|
||||
final PropertyChangeSource src = new PropertyChangeSource();
|
||||
|
@ -135,6 +146,7 @@ public class EventUtilsTest extends TestCase
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBindFilteredEventsToMethod()
|
||||
{
|
||||
final MultipleEventSource src = new MultipleEventSource();
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -23,8 +26,6 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
@ -32,7 +33,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
/**
|
||||
* Abstract test of an ExceptionContext implementation.
|
||||
*/
|
||||
public abstract class AbstractExceptionContextTest<T extends ExceptionContext & Serializable> extends TestCase {
|
||||
public abstract class AbstractExceptionContextTest<T extends ExceptionContext & Serializable> {
|
||||
|
||||
protected static final String TEST_MESSAGE_2 = "This is monotonous";
|
||||
protected static final String TEST_MESSAGE = "Test Message";
|
||||
|
@ -45,8 +46,9 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
exceptionContext
|
||||
.addContextValue("test1", null)
|
||||
.addContextValue("test2", "some value")
|
||||
|
@ -55,6 +57,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
.addContextValue("test Poorly written obj", new ObjectWithFaultyToString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddContextValue() {
|
||||
String message = exceptionContext.getFormattedExceptionMessage(TEST_MESSAGE);
|
||||
assertTrue(message.indexOf(TEST_MESSAGE) >= 0);
|
||||
|
@ -82,6 +85,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
assertTrue(contextMessage.indexOf(TEST_MESSAGE) == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetContextValue() {
|
||||
exceptionContext.addContextValue("test2", "different value");
|
||||
exceptionContext.setContextValue("test3", "3");
|
||||
|
@ -114,6 +118,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
assertTrue(contextMessage.indexOf(TEST_MESSAGE) == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirstContextValue() {
|
||||
exceptionContext.addContextValue("test2", "different value");
|
||||
|
||||
|
@ -126,6 +131,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
assertTrue(exceptionContext.getFirstContextValue("test2").equals("another"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContextValues() {
|
||||
exceptionContext.addContextValue("test2", "different value");
|
||||
|
||||
|
@ -137,6 +143,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
assertTrue(exceptionContext.getFirstContextValue("test2").equals("another"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContextLabels() {
|
||||
assertEquals(5, exceptionContext.getContextEntries().size());
|
||||
|
||||
|
@ -151,6 +158,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
assertTrue(labels.contains("test Nbr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContextEntries() {
|
||||
assertEquals(5, exceptionContext.getContextEntries().size());
|
||||
|
||||
|
@ -166,6 +174,7 @@ public abstract class AbstractExceptionContextTest<T extends ExceptionContext &
|
|||
assertEquals("test2", entries.get(5).getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaSerialization() {
|
||||
exceptionContext.setContextValue("test Poorly written obj", "serializable replacement");
|
||||
|
||||
|
|
|
@ -16,9 +16,14 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests for ContextedException.
|
||||
|
@ -31,6 +36,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedException() {
|
||||
exceptionContext = new ContextedException();
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -39,6 +45,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
assertTrue(StringUtils.isEmpty(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionString() {
|
||||
exceptionContext = new ContextedException(TEST_MESSAGE);
|
||||
assertEquals(TEST_MESSAGE, exceptionContext.getMessage());
|
||||
|
@ -47,6 +54,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
assertTrue(trace.indexOf(TEST_MESSAGE)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionThrowable() {
|
||||
exceptionContext = new ContextedException(new Exception(TEST_MESSAGE));
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -56,6 +64,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
assertTrue(message.indexOf(TEST_MESSAGE)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionStringThrowable() {
|
||||
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE));
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -66,6 +75,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionStringThrowableContext() {
|
||||
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext());
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -76,6 +86,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullExceptionPassing() {
|
||||
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), null)
|
||||
.addContextValue("test1", null)
|
||||
|
@ -88,6 +99,7 @@ public class ContextedExceptionTest extends AbstractExceptionContextTest<Context
|
|||
assertTrue(message != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawMessage() {
|
||||
assertEquals(Exception.class.getName() + ": " + TEST_MESSAGE, exceptionContext.getRawMessage());
|
||||
exceptionContext = new ContextedException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext());
|
||||
|
|
|
@ -16,21 +16,28 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests for ContextedRuntimeException.
|
||||
*/
|
||||
public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<ContextedRuntimeException> {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
exceptionContext = new ContextedRuntimeException(new Exception(TEST_MESSAGE));
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedException() {
|
||||
exceptionContext = new ContextedRuntimeException();
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -39,6 +46,7 @@ public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<
|
|||
assertTrue(StringUtils.isEmpty(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionString() {
|
||||
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE);
|
||||
assertEquals(TEST_MESSAGE, exceptionContext.getMessage());
|
||||
|
@ -47,6 +55,7 @@ public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<
|
|||
assertTrue(trace.indexOf(TEST_MESSAGE)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionThrowable() {
|
||||
exceptionContext = new ContextedRuntimeException(new Exception(TEST_MESSAGE));
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -56,6 +65,7 @@ public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<
|
|||
assertTrue(message.indexOf(TEST_MESSAGE)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionStringThrowable() {
|
||||
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE));
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -66,6 +76,7 @@ public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<
|
|||
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextedExceptionStringThrowableContext() {
|
||||
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext() {});
|
||||
String message = exceptionContext.getMessage();
|
||||
|
@ -76,6 +87,7 @@ public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<
|
|||
assertTrue(message.indexOf(TEST_MESSAGE_2)>=0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullExceptionPassing() {
|
||||
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), null)
|
||||
.addContextValue("test1", null)
|
||||
|
@ -88,6 +100,7 @@ public class ContextedRuntimeExceptionTest extends AbstractExceptionContextTest<
|
|||
assertTrue(message != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawMessage() {
|
||||
assertEquals(Exception.class.getName() + ": " + TEST_MESSAGE, exceptionContext.getRawMessage());
|
||||
exceptionContext = new ContextedRuntimeException(TEST_MESSAGE_2, new Exception(TEST_MESSAGE), new DefaultExceptionContext());
|
||||
|
|
|
@ -16,18 +16,22 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* JUnit tests for DefaultExceptionContext.
|
||||
*
|
||||
*/
|
||||
public class DefaultExceptionContextTest extends AbstractExceptionContextTest<DefaultExceptionContext> {
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
exceptionContext = new DefaultExceptionContext();
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattedExceptionMessageNull() {
|
||||
exceptionContext = new DefaultExceptionContext();
|
||||
exceptionContext.getFormattedExceptionMessage(null);
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.exception;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
@ -24,8 +28,6 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests {@link org.apache.commons.lang3.exception.ExceptionUtils}.
|
||||
*
|
||||
|
@ -47,7 +49,7 @@ import junit.framework.TestCase;
|
|||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ExceptionUtilsTest extends TestCase {
|
||||
public class ExceptionUtilsTest {
|
||||
|
||||
private NestableException nested;
|
||||
private Throwable withCause;
|
||||
|
@ -55,11 +57,8 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
private Throwable jdkNoCause;
|
||||
private ExceptionWithCause cyclicCause;
|
||||
|
||||
public ExceptionUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
withoutCause = createExceptionWithoutCause();
|
||||
nested = new NestableException(withoutCause);
|
||||
|
@ -71,8 +70,9 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
cyclicCause = new ExceptionWithCause(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
withoutCause = null;
|
||||
nested = null;
|
||||
withCause = null;
|
||||
|
@ -103,6 +103,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new ExceptionUtils());
|
||||
Constructor<?>[] cons = ExceptionUtils.class.getDeclaredConstructors();
|
||||
|
@ -114,6 +115,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
@SuppressWarnings("deprecation") // Specifically tests the deprecated methods
|
||||
@Test
|
||||
public void testGetCause_Throwable() {
|
||||
assertSame(null, ExceptionUtils.getCause(null));
|
||||
assertSame(null, ExceptionUtils.getCause(withoutCause));
|
||||
|
@ -126,6 +128,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // Specifically tests the deprecated methods
|
||||
@Test
|
||||
public void testGetCause_ThrowableArray() {
|
||||
assertSame(null, ExceptionUtils.getCause(null, null));
|
||||
assertSame(null, ExceptionUtils.getCause(null, new String[0]));
|
||||
|
@ -144,6 +147,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertSame(null, ExceptionUtils.getCause(withoutCause, new String[] {"getTargetException"}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRootCause_Throwable() {
|
||||
assertSame(null, ExceptionUtils.getRootCause(null));
|
||||
assertSame(null, ExceptionUtils.getRootCause(withoutCause));
|
||||
|
@ -154,6 +158,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetThrowableCount_Throwable() {
|
||||
assertEquals(0, ExceptionUtils.getThrowableCount(null));
|
||||
assertEquals(1, ExceptionUtils.getThrowableCount(withoutCause));
|
||||
|
@ -164,16 +169,19 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetThrowables_Throwable_null() {
|
||||
assertEquals(0, ExceptionUtils.getThrowables(null).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowables_Throwable_withoutCause() {
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(withoutCause);
|
||||
assertEquals(1, throwables.length);
|
||||
assertSame(withoutCause, throwables[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowables_Throwable_nested() {
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(nested);
|
||||
assertEquals(2, throwables.length);
|
||||
|
@ -181,6 +189,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertSame(withoutCause, throwables[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowables_Throwable_withCause() {
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(withCause);
|
||||
assertEquals(3, throwables.length);
|
||||
|
@ -189,12 +198,14 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertSame(withoutCause, throwables[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowables_Throwable_jdkNoCause() {
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(jdkNoCause);
|
||||
assertEquals(1, throwables.length);
|
||||
assertSame(jdkNoCause, throwables[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowables_Throwable_recursiveCause() {
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(cyclicCause);
|
||||
assertEquals(3, throwables.length);
|
||||
|
@ -204,17 +215,20 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetThrowableList_Throwable_null() {
|
||||
List<?> throwables = ExceptionUtils.getThrowableList(null);
|
||||
assertEquals(0, throwables.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowableList_Throwable_withoutCause() {
|
||||
List<?> throwables = ExceptionUtils.getThrowableList(withoutCause);
|
||||
assertEquals(1, throwables.size());
|
||||
assertSame(withoutCause, throwables.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowableList_Throwable_nested() {
|
||||
List<?> throwables = ExceptionUtils.getThrowableList(nested);
|
||||
assertEquals(2, throwables.size());
|
||||
|
@ -222,6 +236,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertSame(withoutCause, throwables.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowableList_Throwable_withCause() {
|
||||
List<?> throwables = ExceptionUtils.getThrowableList(withCause);
|
||||
assertEquals(3, throwables.size());
|
||||
|
@ -230,12 +245,14 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertSame(withoutCause, throwables.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowableList_Throwable_jdkNoCause() {
|
||||
List<?> throwables = ExceptionUtils.getThrowableList(jdkNoCause);
|
||||
assertEquals(1, throwables.size());
|
||||
assertSame(jdkNoCause, throwables.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThrowableList_Throwable_recursiveCause() {
|
||||
List<?> throwables = ExceptionUtils.getThrowableList(cyclicCause);
|
||||
assertEquals(3, throwables.size());
|
||||
|
@ -245,6 +262,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIndexOf_ThrowableClass() {
|
||||
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, null));
|
||||
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, NestableException.class));
|
||||
|
@ -267,6 +285,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertEquals(-1, ExceptionUtils.indexOfThrowable(withCause, Exception.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOf_ThrowableClassInt() {
|
||||
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, null, 0));
|
||||
assertEquals(-1, ExceptionUtils.indexOfThrowable(null, NestableException.class, 0));
|
||||
|
@ -295,6 +314,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIndexOfType_ThrowableClass() {
|
||||
assertEquals(-1, ExceptionUtils.indexOfType(null, null));
|
||||
assertEquals(-1, ExceptionUtils.indexOfType(null, NestableException.class));
|
||||
|
@ -317,6 +337,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertEquals(0, ExceptionUtils.indexOfType(withCause, Exception.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfType_ThrowableClassInt() {
|
||||
assertEquals(-1, ExceptionUtils.indexOfType(null, null, 0));
|
||||
assertEquals(-1, ExceptionUtils.indexOfType(null, NestableException.class, 0));
|
||||
|
@ -345,12 +366,14 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testPrintRootCauseStackTrace_Throwable() throws Exception {
|
||||
ExceptionUtils.printRootCauseStackTrace(null);
|
||||
// could pipe system.err to a known stream, but not much point as
|
||||
// internally this method calls stram method anyway
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrintRootCauseStackTrace_ThrowableStream() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
||||
ExceptionUtils.printRootCauseStackTrace(null, (PrintStream) null);
|
||||
|
@ -376,6 +399,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertTrue(stackTrace.indexOf(ExceptionUtils.WRAPPED_MARKER) == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrintRootCauseStackTrace_ThrowableWriter() throws Exception {
|
||||
StringWriter writer = new StringWriter(1024);
|
||||
ExceptionUtils.printRootCauseStackTrace(null, (PrintWriter) null);
|
||||
|
@ -402,6 +426,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetRootCauseStackTrace_Throwable() throws Exception {
|
||||
assertEquals(0, ExceptionUtils.getRootCauseStackTrace(null).length);
|
||||
|
||||
|
@ -427,6 +452,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertEquals(false, match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveCommonFrames_ListList() throws Exception {
|
||||
try {
|
||||
ExceptionUtils.removeCommonFrames(null, null);
|
||||
|
@ -435,6 +461,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getMessage_Throwable() {
|
||||
Throwable th = null;
|
||||
assertEquals("", ExceptionUtils.getMessage(th));
|
||||
|
@ -446,6 +473,7 @@ public class ExceptionUtilsTest extends TestCase {
|
|||
assertEquals("ExceptionUtilsTest.ExceptionWithCause: Wrapper", ExceptionUtils.getMessage(th));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getRootCauseMessage_Throwable() {
|
||||
Throwable th = null;
|
||||
assertEquals("", ExceptionUtils.getRootCauseMessage(th));
|
||||
|
|
|
@ -18,23 +18,25 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.math;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test cases for the {@link Fraction} class
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class FractionTest extends TestCase {
|
||||
public class FractionTest {
|
||||
|
||||
private static final int SKIP = 500; //53
|
||||
|
||||
public FractionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testConstants() {
|
||||
assertEquals(0, Fraction.ZERO.getNumerator());
|
||||
assertEquals(1, Fraction.ZERO.getDenominator());
|
||||
|
@ -73,6 +75,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(5, Fraction.FOUR_FIFTHS.getDenominator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory_int_int() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -143,6 +146,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory_int_int_int() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -245,6 +249,7 @@ public class FractionTest extends TestCase {
|
|||
fail("expecting ArithmeticException");
|
||||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
@Test
|
||||
public void testReducedFactory_int_int() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -335,6 +340,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(1, f.getDenominator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory_double() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -424,6 +430,7 @@ public class FractionTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory_String() {
|
||||
try {
|
||||
Fraction.getFraction(null);
|
||||
|
@ -432,6 +439,7 @@ public class FractionTest extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFactory_String_double() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -467,6 +475,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (NumberFormatException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory_String_proper() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -525,6 +534,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (NumberFormatException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory_String_improper() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -573,6 +583,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (NumberFormatException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGets() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -595,6 +606,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(1, f.getDenominator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConversions() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -605,6 +617,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(3.875d, f.doubleValue(), 0.00001d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduce() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -653,6 +666,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(1, result.getDenominator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvert() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -690,6 +704,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(Integer.MAX_VALUE, f.getDenominator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegate() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -716,6 +731,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbs() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -746,6 +762,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPow() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -858,6 +875,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
Fraction f = null;
|
||||
Fraction f1 = null;
|
||||
|
@ -976,6 +994,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtract() {
|
||||
Fraction f = null;
|
||||
Fraction f1 = null;
|
||||
|
@ -1088,6 +1107,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiply() {
|
||||
Fraction f = null;
|
||||
Fraction f1 = null;
|
||||
|
@ -1156,6 +1176,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivide() {
|
||||
Fraction f = null;
|
||||
Fraction f1 = null;
|
||||
|
@ -1213,6 +1234,7 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Fraction f1 = null;
|
||||
Fraction f2 = null;
|
||||
|
@ -1235,6 +1257,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals(false, f1.equals(f2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
Fraction f1 = Fraction.getFraction(3, 5);
|
||||
Fraction f2 = Fraction.getFraction(3, 5);
|
||||
|
@ -1248,6 +1271,7 @@ public class FractionTest extends TestCase {
|
|||
assertTrue(f1.hashCode() != f2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
Fraction f1 = null;
|
||||
Fraction f2 = null;
|
||||
|
@ -1282,6 +1306,7 @@ public class FractionTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Fraction f = null;
|
||||
|
||||
|
@ -1309,6 +1334,7 @@ public class FractionTest extends TestCase {
|
|||
assertEquals("-2147483648/2147483647", f.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToProperString() {
|
||||
Fraction f = null;
|
||||
|
||||
|
|
|
@ -16,15 +16,20 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.math;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.math.IEEE754rUtils}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class IEEE754rUtilsTest extends TestCase {
|
||||
public class IEEE754rUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testLang381() {
|
||||
assertEquals(1.2, IEEE754rUtils.min(1.2, 2.5, Double.NaN), 0.01);
|
||||
assertEquals(2.5, IEEE754rUtils.max(1.2, 2.5, Double.NaN), 0.01);
|
||||
|
@ -50,6 +55,7 @@ public class IEEE754rUtilsTest extends TestCase {
|
|||
assertEquals(42.0f, IEEE754rUtils.max(bF), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnforceExceptions() {
|
||||
try {
|
||||
IEEE754rUtils.min( (float[]) null);
|
||||
|
@ -93,6 +99,7 @@ public class IEEE754rUtilsTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorExists() {
|
||||
new IEEE754rUtils();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
package org.apache.commons.lang3.mutable;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* JUnit tests.
|
||||
|
@ -26,12 +27,9 @@ import junit.framework.TestCase;
|
|||
* @see MutableBoolean
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MutableBooleanTest extends TestCase {
|
||||
|
||||
public MutableBooleanTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public class MutableBooleanTest {
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
final MutableBoolean mutBool = new MutableBoolean(false);
|
||||
|
||||
|
@ -49,6 +47,7 @@ public class MutableBooleanTest extends TestCase {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals(false, new MutableBoolean().booleanValue());
|
||||
|
||||
|
@ -65,6 +64,7 @@ public class MutableBooleanTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final MutableBoolean mutBoolA = new MutableBoolean(false);
|
||||
final MutableBoolean mutBoolB = new MutableBoolean(false);
|
||||
|
@ -82,6 +82,7 @@ public class MutableBooleanTest extends TestCase {
|
|||
assertEquals(false, mutBoolA.equals("false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
assertEquals(false, new MutableBoolean().booleanValue());
|
||||
assertEquals(Boolean.FALSE, new MutableBoolean().getValue());
|
||||
|
@ -111,6 +112,7 @@ public class MutableBooleanTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final MutableBoolean mutBoolA = new MutableBoolean(false);
|
||||
final MutableBoolean mutBoolB = new MutableBoolean(false);
|
||||
|
@ -123,6 +125,7 @@ public class MutableBooleanTest extends TestCase {
|
|||
assertEquals(true, mutBoolC.hashCode() == Boolean.TRUE.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals(Boolean.FALSE.toString(), new MutableBoolean(false).toString());
|
||||
assertEquals(Boolean.TRUE.toString(), new MutableBoolean(true).toString());
|
||||
|
|
|
@ -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 MutableByte
|
||||
*/
|
||||
public class MutableByteTest extends TestCase {
|
||||
|
||||
public MutableByteTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public class MutableByteTest {
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals((byte) 0, new MutableByte().byteValue());
|
||||
|
||||
|
@ -47,6 +45,7 @@ public class MutableByteTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
final MutableByte mutNum = new MutableByte((byte) 0);
|
||||
assertEquals((byte) 0, new MutableByte().byteValue());
|
||||
|
@ -69,6 +68,7 @@ public class MutableByteTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final MutableByte mutNumA = new MutableByte((byte) 0);
|
||||
final MutableByte mutNumB = new MutableByte((byte) 0);
|
||||
|
@ -86,6 +86,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals(false, mutNumA.equals("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final MutableByte mutNumA = new MutableByte((byte) 0);
|
||||
final MutableByte mutNumB = new MutableByte((byte) 0);
|
||||
|
@ -97,6 +98,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals(true, mutNumA.hashCode() == Byte.valueOf((byte) 0).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
final MutableByte mutNum = new MutableByte((byte) 0);
|
||||
|
||||
|
@ -109,6 +111,7 @@ public class MutableByteTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveValues() {
|
||||
MutableByte mutNum = new MutableByte( (byte) 1 );
|
||||
|
||||
|
@ -120,11 +123,13 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals( 1L, mutNum.longValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToByte() {
|
||||
assertEquals(Byte.valueOf((byte) 0), new MutableByte((byte) 0).toByte());
|
||||
assertEquals(Byte.valueOf((byte) 123), new MutableByte((byte) 123).toByte());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
MutableByte mutNum = new MutableByte((byte) 1);
|
||||
mutNum.increment();
|
||||
|
@ -133,6 +138,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrement() {
|
||||
MutableByte mutNum = new MutableByte((byte) 1);
|
||||
mutNum.decrement();
|
||||
|
@ -141,6 +147,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValuePrimitive() {
|
||||
MutableByte mutNum = new MutableByte((byte) 1);
|
||||
mutNum.add((byte)1);
|
||||
|
@ -148,6 +155,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals((byte) 2, mutNum.byteValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValueObject() {
|
||||
MutableByte mutNum = new MutableByte((byte) 1);
|
||||
mutNum.add(Integer.valueOf(1));
|
||||
|
@ -155,6 +163,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals((byte) 2, mutNum.byteValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValuePrimitive() {
|
||||
MutableByte mutNum = new MutableByte((byte) 1);
|
||||
mutNum.subtract((byte) 1);
|
||||
|
@ -162,6 +171,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals((byte) 0, mutNum.byteValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValueObject() {
|
||||
MutableByte mutNum = new MutableByte((byte) 1);
|
||||
mutNum.subtract(Integer.valueOf(1));
|
||||
|
@ -169,6 +179,7 @@ public class MutableByteTest extends TestCase {
|
|||
assertEquals((byte) 0, mutNum.byteValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("0", new MutableByte((byte) 0).toString());
|
||||
assertEquals("10", new MutableByte((byte) 10).toString());
|
||||
|
|
|
@ -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 MutableDouble
|
||||
*/
|
||||
public class MutableDoubleTest extends TestCase {
|
||||
|
||||
public MutableDoubleTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public class MutableDoubleTest {
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals(0d, new MutableDouble().doubleValue(), 0.0001d);
|
||||
|
||||
|
@ -47,6 +45,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
final MutableDouble mutNum = new MutableDouble(0d);
|
||||
assertEquals(0d, new MutableDouble().doubleValue(), 0.0001d);
|
||||
|
@ -69,6 +68,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNanInfinite() {
|
||||
MutableDouble mutNum = new MutableDouble(Double.NaN);
|
||||
assertEquals(true, mutNum.isNaN());
|
||||
|
@ -80,6 +80,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(true, mutNum.isInfinite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final MutableDouble mutNumA = new MutableDouble(0d);
|
||||
final MutableDouble mutNumB = new MutableDouble(0d);
|
||||
|
@ -97,6 +98,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(false, mutNumA.equals("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final MutableDouble mutNumA = new MutableDouble(0d);
|
||||
final MutableDouble mutNumB = new MutableDouble(0d);
|
||||
|
@ -108,6 +110,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(true, mutNumA.hashCode() == Double.valueOf(0d).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
final MutableDouble mutNum = new MutableDouble(0d);
|
||||
|
||||
|
@ -120,6 +123,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveValues() {
|
||||
MutableDouble mutNum = new MutableDouble(1.7);
|
||||
|
||||
|
@ -131,11 +135,13 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals( 1L, mutNum.longValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToDouble() {
|
||||
assertEquals(Double.valueOf(0d), new MutableDouble(0d).toDouble());
|
||||
assertEquals(Double.valueOf(12.3d), new MutableDouble(12.3d).toDouble());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
MutableDouble mutNum = new MutableDouble(1);
|
||||
mutNum.increment();
|
||||
|
@ -144,6 +150,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrement() {
|
||||
MutableDouble mutNum = new MutableDouble(1);
|
||||
mutNum.decrement();
|
||||
|
@ -152,6 +159,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValuePrimitive() {
|
||||
MutableDouble mutNum = new MutableDouble(1);
|
||||
mutNum.add(1.1d);
|
||||
|
@ -159,6 +167,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(2.1d, mutNum.doubleValue(), 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValueObject() {
|
||||
MutableDouble mutNum = new MutableDouble(1);
|
||||
mutNum.add(Double.valueOf(1.1d));
|
||||
|
@ -166,6 +175,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(2.1d, mutNum.doubleValue(), 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValuePrimitive() {
|
||||
MutableDouble mutNum = new MutableDouble(1);
|
||||
mutNum.subtract(0.9d);
|
||||
|
@ -173,6 +183,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(0.1d, mutNum.doubleValue(), 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValueObject() {
|
||||
MutableDouble mutNum = new MutableDouble(1);
|
||||
mutNum.subtract(Double.valueOf(0.9d));
|
||||
|
@ -180,6 +191,7 @@ public class MutableDoubleTest extends TestCase {
|
|||
assertEquals(0.1d, mutNum.doubleValue(), 0.01d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("0.0", new MutableDouble(0d).toString());
|
||||
assertEquals("10.0", new MutableDouble(10d).toString());
|
||||
|
|
|
@ -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 MutableFloat
|
||||
*/
|
||||
public class MutableFloatTest extends TestCase {
|
||||
|
||||
public MutableFloatTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public class MutableFloatTest {
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals(0f, new MutableFloat().floatValue(), 0.0001f);
|
||||
|
||||
|
@ -47,6 +45,7 @@ public class MutableFloatTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
final MutableFloat mutNum = new MutableFloat(0f);
|
||||
assertEquals(0f, new MutableFloat().floatValue(), 0.0001f);
|
||||
|
@ -69,6 +68,7 @@ public class MutableFloatTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNanInfinite() {
|
||||
MutableFloat mutNum = new MutableFloat(Float.NaN);
|
||||
assertEquals(true, mutNum.isNaN());
|
||||
|
@ -80,6 +80,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(true, mutNum.isInfinite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final MutableFloat mutNumA = new MutableFloat(0f);
|
||||
final MutableFloat mutNumB = new MutableFloat(0f);
|
||||
|
@ -97,6 +98,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(false, mutNumA.equals("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final MutableFloat mutNumA = new MutableFloat(0f);
|
||||
final MutableFloat mutNumB = new MutableFloat(0f);
|
||||
|
@ -108,6 +110,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(true, mutNumA.hashCode() == Float.valueOf(0f).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
final MutableFloat mutNum = new MutableFloat(0f);
|
||||
|
||||
|
@ -120,6 +123,7 @@ public class MutableFloatTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveValues() {
|
||||
MutableFloat mutNum = new MutableFloat(1.7F);
|
||||
|
||||
|
@ -131,11 +135,13 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals( 1L, mutNum.longValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToFloat() {
|
||||
assertEquals(Float.valueOf(0f), new MutableFloat(0f).toFloat());
|
||||
assertEquals(Float.valueOf(12.3f), new MutableFloat(12.3f).toFloat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
MutableFloat mutNum = new MutableFloat(1);
|
||||
mutNum.increment();
|
||||
|
@ -144,6 +150,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrement() {
|
||||
MutableFloat mutNum = new MutableFloat(1);
|
||||
mutNum.decrement();
|
||||
|
@ -152,6 +159,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValuePrimitive() {
|
||||
MutableFloat mutNum = new MutableFloat(1);
|
||||
mutNum.add(1.1f);
|
||||
|
@ -159,6 +167,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(2.1f, mutNum.floatValue(), 0.01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValueObject() {
|
||||
MutableFloat mutNum = new MutableFloat(1);
|
||||
mutNum.add(Float.valueOf(1.1f));
|
||||
|
@ -166,6 +175,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(2.1f, mutNum.floatValue(), 0.01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValuePrimitive() {
|
||||
MutableFloat mutNum = new MutableFloat(1);
|
||||
mutNum.subtract(0.9f);
|
||||
|
@ -173,6 +183,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(0.1f, mutNum.floatValue(), 0.01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValueObject() {
|
||||
MutableFloat mutNum = new MutableFloat(1);
|
||||
mutNum.subtract(Float.valueOf(0.9f));
|
||||
|
@ -180,6 +191,7 @@ public class MutableFloatTest extends TestCase {
|
|||
assertEquals(0.1f, mutNum.floatValue(), 0.01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("0.0", new MutableFloat(0f).toString());
|
||||
assertEquals("10.0", new MutableFloat(10f).toString());
|
||||
|
|
|
@ -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 MutableInt
|
||||
*/
|
||||
public class MutableIntTest extends TestCase {
|
||||
|
||||
public MutableIntTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public class MutableIntTest {
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals(0, new MutableInt().intValue());
|
||||
|
||||
|
@ -47,6 +45,7 @@ public class MutableIntTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
final MutableInt mutNum = new MutableInt(0);
|
||||
assertEquals(0, new MutableInt().intValue());
|
||||
|
@ -69,6 +68,7 @@ public class MutableIntTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
this.testEquals(new MutableInt(0), new MutableInt(0), new MutableInt(1));
|
||||
// Should Numbers be supported? GaryG July-21-2005.
|
||||
|
@ -93,6 +93,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(false, numA.equals("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final MutableInt mutNumA = new MutableInt(0);
|
||||
final MutableInt mutNumB = new MutableInt(0);
|
||||
|
@ -104,6 +105,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(true, mutNumA.hashCode() == Integer.valueOf(0).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
final MutableInt mutNum = new MutableInt(0);
|
||||
|
||||
|
@ -116,6 +118,7 @@ public class MutableIntTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveValues() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
|
||||
|
@ -126,11 +129,13 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals( 1L, mutNum.longValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToInteger() {
|
||||
assertEquals(Integer.valueOf(0), new MutableInt(0).toInteger());
|
||||
assertEquals(Integer.valueOf(123), new MutableInt(123).toInteger());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
mutNum.increment();
|
||||
|
@ -139,6 +144,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrement() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
mutNum.decrement();
|
||||
|
@ -147,6 +153,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValuePrimitive() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
mutNum.add(1);
|
||||
|
@ -155,6 +162,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValueObject() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
mutNum.add(Integer.valueOf(1));
|
||||
|
@ -163,6 +171,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValuePrimitive() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
mutNum.subtract(1);
|
||||
|
@ -171,6 +180,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValueObject() {
|
||||
MutableInt mutNum = new MutableInt(1);
|
||||
mutNum.subtract(Integer.valueOf(1));
|
||||
|
@ -179,6 +189,7 @@ public class MutableIntTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("0", new MutableInt(0).toString());
|
||||
assertEquals("10", new MutableInt(10).toString());
|
||||
|
|
|
@ -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 MutableLong
|
||||
*/
|
||||
public class MutableLongTest extends TestCase {
|
||||
|
||||
public MutableLongTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public class MutableLongTest {
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals(0, new MutableLong().longValue());
|
||||
|
||||
|
@ -47,6 +45,7 @@ public class MutableLongTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
final MutableLong mutNum = new MutableLong(0);
|
||||
assertEquals(0, new MutableLong().longValue());
|
||||
|
@ -69,6 +68,7 @@ public class MutableLongTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final MutableLong mutNumA = new MutableLong(0);
|
||||
final MutableLong mutNumB = new MutableLong(0);
|
||||
|
@ -86,6 +86,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(false, mutNumA.equals("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final MutableLong mutNumA = new MutableLong(0);
|
||||
final MutableLong mutNumB = new MutableLong(0);
|
||||
|
@ -97,6 +98,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(true, mutNumA.hashCode() == Long.valueOf(0).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
final MutableLong mutNum = new MutableLong(0);
|
||||
|
||||
|
@ -109,6 +111,7 @@ public class MutableLongTest extends TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveValues() {
|
||||
MutableLong mutNum = new MutableLong(1L);
|
||||
|
||||
|
@ -120,11 +123,13 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals( 1L, mutNum.longValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToLong() {
|
||||
assertEquals(Long.valueOf(0L), new MutableLong(0L).toLong());
|
||||
assertEquals(Long.valueOf(123L), new MutableLong(123L).toLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
MutableLong mutNum = new MutableLong(1);
|
||||
mutNum.increment();
|
||||
|
@ -133,6 +138,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrement() {
|
||||
MutableLong mutNum = new MutableLong(1);
|
||||
mutNum.decrement();
|
||||
|
@ -141,6 +147,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValuePrimitive() {
|
||||
MutableLong mutNum = new MutableLong(1);
|
||||
mutNum.add(1);
|
||||
|
@ -149,6 +156,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddValueObject() {
|
||||
MutableLong mutNum = new MutableLong(1);
|
||||
mutNum.add(Long.valueOf(1));
|
||||
|
@ -157,6 +165,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValuePrimitive() {
|
||||
MutableLong mutNum = new MutableLong(1);
|
||||
mutNum.subtract(1);
|
||||
|
@ -165,6 +174,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtractValueObject() {
|
||||
MutableLong mutNum = new MutableLong(1);
|
||||
mutNum.subtract(Long.valueOf(1));
|
||||
|
@ -173,6 +183,7 @@ public class MutableLongTest extends TestCase {
|
|||
assertEquals(0L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("0", new MutableLong(0).toString());
|
||||
assertEquals("10", new MutableLong(10).toString());
|
||||
|
|
|
@ -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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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());
|
||||
|
|
|
@ -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 TestCase {
|
|||
} 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 TestCase {
|
|||
} 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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveValues() {
|
||||
MutableShort mutNum = new MutableShort( (short) 1 );
|
||||
|
||||
|
@ -120,11 +123,13 @@ public class MutableShortTest extends TestCase {
|
|||
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 TestCase {
|
|||
assertEquals(2L, mutNum.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrement() {
|
||||
MutableShort mutNum = new MutableShort((short) 1);
|
||||
mutNum.decrement();
|
||||
|
@ -141,6 +147,7 @@ public class MutableShortTest extends TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
assertEquals((short) 0, mutNum.shortValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("0", new MutableShort((short) 0).toString());
|
||||
assertEquals("10", new MutableShort((short) 10).toString());
|
||||
|
|
|
@ -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.MutableObject;
|
|||
* 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 extends TestCase {
|
|||
|
||||
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 extends TestCase {
|
|||
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 extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccessibleConstructor() throws Exception {
|
||||
assertNotNull(ConstructorUtils.getAccessibleConstructor(Object.class
|
||||
.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY)));
|
||||
|
@ -152,6 +156,7 @@ public class ConstructorUtilsTest extends TestCase {
|
|||
.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 extends TestCase {
|
|||
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 extends TestCase {
|
|||
singletonArray(Double.TYPE), singletonArray(Double.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullArgument() {
|
||||
expectMatchingAccessibleConstructorParameterTypes(MutableObject.class,
|
||||
singletonArray(null), singletonArray(Object.class));
|
||||
|
|
|
@ -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 TestCase {
|
|||
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);
|
||||
|
|
|
@ -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.SystemUtils;
|
|||
* @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 extends TestCase {
|
|||
/**
|
||||
* 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 extends TestCase {
|
|||
/**
|
||||
* 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 extends TestCase {
|
|||
/**
|
||||
* 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 extends TestCase {
|
|||
/**
|
||||
* 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 extends TestCase {
|
|||
/**
|
||||
* 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 extends TestCase {
|
|||
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 extends TestCase {
|
|||
/**
|
||||
* 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 extends TestCase {
|
|||
/**
|
||||
* 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());
|
||||
|
|
|
@ -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.SystemUtils;
|
|||
*
|
||||
* @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 extends TestCase {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendWithNullText() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("NULL");
|
||||
|
@ -96,6 +89,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_Object() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendNull();
|
||||
|
@ -121,6 +115,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_String() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("NULL").append((String) null);
|
||||
|
@ -138,6 +133,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_StringBuffer() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("NULL").append((StringBuffer) null);
|
||||
|
@ -217,6 +214,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_StrBuilder() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("NULL").append((StrBuilder) null);
|
||||
|
@ -293,6 +292,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_CharArray() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("NULL").append((char[]) null);
|
||||
|
@ -366,6 +367,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_Boolean() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.append(true);
|
||||
|
@ -438,6 +441,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppend_PrimitiveNumber() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.append(0);
|
||||
|
@ -454,6 +458,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_Object() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendln((Object) null);
|
||||
|
@ -467,6 +472,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_String() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -488,6 +494,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_String_int_int() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -509,6 +516,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_StringBuffer() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -530,6 +538,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_StringBuffer_int_int() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -551,6 +560,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_StrBuilder() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -572,6 +582,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_StrBuilder_int_int() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -593,6 +604,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_CharArray() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -614,6 +626,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_CharArray_int_int() {
|
||||
final int[] count = new int[2];
|
||||
StrBuilder sb = new StrBuilder() {
|
||||
|
@ -635,6 +648,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_Boolean() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendln(true);
|
||||
|
@ -646,6 +660,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendln_PrimitiveNumber() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendln(0);
|
||||
|
@ -665,6 +680,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendPadding() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.append("foo");
|
||||
|
@ -686,6 +702,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendFixedWidthPadLeft() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendFixedWidthPadLeft("foo", -1, '-');
|
||||
|
@ -724,6 +741,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendFixedWidthPadLeft_int() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendFixedWidthPadLeft(123, -1, '-');
|
||||
|
@ -757,6 +775,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendFixedWidthPadRight() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendFixedWidthPadRight("foo", -1, '-');
|
||||
|
@ -795,6 +814,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
// 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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendFixedWidthPadRight_int() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendFixedWidthPadRight(123, -1, '-');
|
||||
|
@ -835,6 +856,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendAll_Array() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendAll((Object[]) null);
|
||||
|
@ -850,6 +872,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendAll_Collection() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendAll((Collection<?>) null);
|
||||
|
@ -865,6 +888,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendAll_Iterator() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendAll((Iterator<?>) null);
|
||||
|
@ -880,6 +904,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendWithSeparators_Array() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendWithSeparators((Object[]) null, ",");
|
||||
|
@ -903,6 +928,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendWithSeparators_Collection() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendWithSeparators((Collection<?>) null, ",");
|
||||
|
@ -926,6 +952,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendWithSeparators_Iterator() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendWithSeparators((Iterator<?>) null, ",");
|
||||
|
@ -949,6 +976,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendWithSeparatorsWithNullText() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("null");
|
||||
|
@ -961,6 +989,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendSeparator_String() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendSeparator(","); // no effect
|
||||
|
@ -972,6 +1001,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendSeparator_String_String() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
final String startSeparator = "order by ";
|
||||
|
@ -994,6 +1024,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendSeparator_char() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendSeparator(','); // no effect
|
||||
|
@ -1003,6 +1034,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
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 extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendSeparator_String_int() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendSeparator(",", 0); // no effect
|
||||
|
@ -1031,6 +1064,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAppendSeparator_char_int() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.appendSeparator(',', 0); // no effect
|
||||
|
@ -1045,6 +1079,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testInsert() {
|
||||
|
||||
StrBuilder sb = new StrBuilder();
|
||||
|
@ -1311,6 +1346,7 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testInsertWithNullText() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.setNullText("null");
|
||||
|
|
|
@ -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.ArrayUtils;
|
|||
*
|
||||
* @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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testChaining() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertSame(sb, sb.setNewLineText(null));
|
||||
|
@ -100,6 +92,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetSetNewLineText() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(null, sb.getNewLineText());
|
||||
|
@ -115,6 +108,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testGetSetNullText() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(null, sb.getNullText());
|
||||
|
@ -133,6 +127,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCapacityAndLength() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(32, sb.capacity());
|
||||
|
@ -217,6 +212,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testLength() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(0, sb.length());
|
||||
|
@ -225,6 +221,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals(5, sb.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetLength() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.append("Hello");
|
||||
|
@ -244,6 +241,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCapacity() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(sb.buffer.length, sb.capacity());
|
||||
|
@ -252,6 +250,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
assertEquals(true, sb.capacity() >= 40);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimizeCapacity() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.minimizeCapacity();
|
||||
|
@ -276,6 +276,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSize() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(0, sb.size());
|
||||
|
@ -284,6 +285,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals(5, sb.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmpty() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(true, sb.isEmpty());
|
||||
|
@ -295,6 +297,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals(true, sb.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.append("Hello");
|
||||
|
@ -304,6 +307,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCharAt() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
try {
|
||||
|
@ -337,6 +341,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetCharAt() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
try {
|
||||
|
@ -365,6 +370,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDeleteCharAt() {
|
||||
StrBuilder sb = new StrBuilder("abc");
|
||||
sb.deleteCharAt(0);
|
||||
|
@ -377,6 +383,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testToCharArray() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, sb.toCharArray());
|
||||
|
@ -391,6 +398,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetChars ( ) {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
|
||||
|
@ -451,6 +460,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertNotSame(input, a);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCharsIntIntCharArrayInt( ) {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
|
||||
|
@ -493,6 +503,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDeleteIntInt() {
|
||||
StrBuilder sb = new StrBuilder("abc");
|
||||
sb.delete(0, 1);
|
||||
|
@ -521,6 +532,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDeleteAll_char() {
|
||||
StrBuilder sb = new StrBuilder("abcbccba");
|
||||
sb.deleteAll('X');
|
||||
|
@ -537,6 +549,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals("", sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFirst_char() {
|
||||
StrBuilder sb = new StrBuilder("abcba");
|
||||
sb.deleteFirst('X');
|
||||
|
@ -554,6 +567,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDeleteAll_String() {
|
||||
StrBuilder sb = new StrBuilder("abcbccba");
|
||||
sb.deleteAll((String) null);
|
||||
|
@ -579,6 +593,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDeleteAll_StrMatcher() {
|
||||
StrBuilder sb = new StrBuilder("A0xA1A2yA3");
|
||||
sb.deleteAll((StrMatcher) null);
|
||||
|
@ -621,6 +637,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReplaceAll_char_char() {
|
||||
StrBuilder sb = new StrBuilder("abcbccba");
|
||||
sb.replaceAll('x', 'y');
|
||||
|
@ -688,6 +707,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReplaceFirst_char_char() {
|
||||
StrBuilder sb = new StrBuilder("abcbccba");
|
||||
sb.replaceFirst('x', 'y');
|
||||
|
@ -703,6 +723,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReplaceAll_String_String() {
|
||||
StrBuilder sb = new StrBuilder("abcbccba");
|
||||
sb.replaceAll((String) null, null);
|
||||
|
@ -732,6 +753,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReplaceAll_StrMatcher_String() {
|
||||
StrBuilder sb = new StrBuilder("abcbccba");
|
||||
sb.replaceAll((StrMatcher) null, null);
|
||||
|
@ -795,6 +818,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReverse() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals("", sb.reverse().toString());
|
||||
|
@ -1025,6 +1055,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTrim() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals("", sb.reverse().toString());
|
||||
|
@ -1046,6 +1077,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testStartsWith() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertFalse(sb.startsWith("a"));
|
||||
|
@ -1058,6 +1090,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertFalse(sb.startsWith("cba"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndsWith() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertFalse(sb.endsWith("a"));
|
||||
|
@ -1075,6 +1108,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSubSequenceIntInt() {
|
||||
StrBuilder sb = new StrBuilder ("hello goodbye");
|
||||
// Start index is negative
|
||||
|
@ -1108,6 +1142,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstringIntInt() {
|
||||
StrBuilder sb = new StrBuilder ("hello goodbye");
|
||||
assertEquals ("hello", sb.substring(0, 5));
|
||||
|
@ -1148,6 +1184,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testContains_char() {
|
||||
StrBuilder sb = new StrBuilder("abcdefghijklmnopqrstuvwxyz");
|
||||
assertEquals(true, sb.contains('a'));
|
||||
|
@ -1183,6 +1223,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIndexOf_char() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
assertEquals(0, sb.indexOf('a'));
|
||||
|
@ -1220,6 +1263,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
assertEquals(-1, sb.indexOf('z', 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastIndexOf_char() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
|
@ -1254,6 +1299,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIndexOf_String() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
|
@ -1296,6 +1343,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIndexOf_StrMatcher() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(-1, sb.indexOf((StrMatcher) null));
|
||||
|
@ -1408,6 +1459,7 @@ public class StrBuilderTest extends TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
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 TestCase {
|
|||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAsTokenizer() throws Exception {
|
||||
// from Javadoc
|
||||
StrBuilder b = new StrBuilder();
|
||||
|
@ -1556,6 +1611,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAsReader() throws Exception {
|
||||
StrBuilder sb = new StrBuilder("some text");
|
||||
Reader reader = sb.asReader();
|
||||
|
@ -1627,6 +1683,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAsWriter() throws Exception {
|
||||
StrBuilder sb = new StrBuilder("base");
|
||||
Writer writer = sb.asWriter();
|
||||
|
@ -1661,6 +1718,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEqualsIgnoreCase() {
|
||||
StrBuilder sb1 = new StrBuilder();
|
||||
StrBuilder sb2 = new StrBuilder();
|
||||
|
@ -1684,6 +1742,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEquals() {
|
||||
StrBuilder sb1 = new StrBuilder();
|
||||
StrBuilder sb2 = new StrBuilder();
|
||||
|
@ -1709,6 +1768,7 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
int hc1a = sb.hashCode();
|
||||
|
@ -1724,12 +1784,14 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testLang295() {
|
||||
StrBuilder sb = new StrBuilder("onetwothree");
|
||||
sb.deleteFirst("three");
|
||||
|
@ -1760,12 +1825,14 @@ public class StrBuilderTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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, '*');
|
||||
|
|
|
@ -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 TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapLookup() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("key", "value");
|
||||
|
@ -59,6 +65,7 @@ public class StrLookupTest extends TestCase {
|
|||
assertEquals(null, StrLookup.mapLookup(map).lookup("other"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapLookup_nullMap() {
|
||||
Map<String, ?> map = null;
|
||||
assertEquals(null, StrLookup.mapLookup(map).lookup(null));
|
||||
|
|
|
@ -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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTabMatcher() {
|
||||
StrMatcher matcher = StrMatcher.tabMatcher();
|
||||
assertSame(matcher, StrMatcher.tabMatcher());
|
||||
|
@ -58,6 +56,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSpaceMatcher() {
|
||||
StrMatcher matcher = StrMatcher.spaceMatcher();
|
||||
assertSame(matcher, StrMatcher.spaceMatcher());
|
||||
|
@ -67,6 +66,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSplitMatcher() {
|
||||
StrMatcher matcher = StrMatcher.splitMatcher();
|
||||
assertSame(matcher, StrMatcher.splitMatcher());
|
||||
|
@ -82,6 +82,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTrimMatcher() {
|
||||
StrMatcher matcher = StrMatcher.trimMatcher();
|
||||
assertSame(matcher, StrMatcher.trimMatcher());
|
||||
|
@ -97,6 +98,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSingleQuoteMatcher() {
|
||||
StrMatcher matcher = StrMatcher.singleQuoteMatcher();
|
||||
assertSame(matcher, StrMatcher.singleQuoteMatcher());
|
||||
|
@ -106,6 +108,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testDoubleQuoteMatcher() {
|
||||
StrMatcher matcher = StrMatcher.doubleQuoteMatcher();
|
||||
assertSame(matcher, StrMatcher.doubleQuoteMatcher());
|
||||
|
@ -114,6 +117,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testQuoteMatcher() {
|
||||
StrMatcher matcher = StrMatcher.quoteMatcher();
|
||||
assertSame(matcher, StrMatcher.quoteMatcher());
|
||||
|
@ -123,6 +127,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testNoneMatcher() {
|
||||
StrMatcher matcher = StrMatcher.noneMatcher();
|
||||
assertSame(matcher, StrMatcher.noneMatcher());
|
||||
|
@ -142,6 +147,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCharMatcher_char() {
|
||||
StrMatcher matcher = StrMatcher.charMatcher('c');
|
||||
assertEquals(0, matcher.isMatch(BUFFER2, 0));
|
||||
|
@ -153,6 +159,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCharSetMatcher_String() {
|
||||
StrMatcher matcher = StrMatcher.charSetMatcher("ace");
|
||||
assertEquals(1, matcher.isMatch(BUFFER2, 0));
|
||||
|
@ -167,6 +174,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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 TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testStringMatcher_String() {
|
||||
StrMatcher matcher = StrMatcher.stringMatcher("bc");
|
||||
assertEquals(0, matcher.isMatch(BUFFER2, 0));
|
||||
|
@ -194,6 +203,7 @@ public class StrMatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@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
|
||||
|
|
|
@ -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.MutableObject;
|
|||
*
|
||||
* @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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* Tests simple key replace.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceSolo() {
|
||||
doTestReplace("quick brown fox", "${animal}", false);
|
||||
}
|
||||
|
@ -66,6 +68,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* Tests replace with no variables.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceNoVariables() {
|
||||
doTestNoReplace("The balloon arrived.");
|
||||
}
|
||||
|
@ -73,6 +76,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* Tests replace with null.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceNull() {
|
||||
doTestNoReplace(null);
|
||||
}
|
||||
|
@ -80,6 +84,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* Tests replace with null.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceEmpty() {
|
||||
doTestNoReplace("");
|
||||
}
|
||||
|
@ -87,6 +92,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* Tests adjacent keys.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceAdjacentAtStart() {
|
||||
values.put("code", "GBP");
|
||||
values.put("amount", "12.50");
|
||||
|
@ -113,6 +121,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* Tests adjacent keys.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceAdjacentAtEnd() {
|
||||
values.put("code", "GBP");
|
||||
values.put("amount", "12.50");
|
||||
|
@ -123,6 +132,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* Tests simple recursive replace.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceRecursive() {
|
||||
values.put("animal", "${critter}");
|
||||
values.put("target", "${pet}");
|
||||
|
@ -138,6 +148,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* Tests escaping.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceSoloEscaping() {
|
||||
doTestReplace("${animal}", "$${animal}", false);
|
||||
}
|
||||
|
@ -152,6 +164,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
* 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 TestCase {
|
|||
/**
|
||||
* Tests interpolation with weird boundary patterns.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceWeirdPattens() {
|
||||
doTestNoReplace("");
|
||||
doTestNoReplace("${}");
|
||||
|
@ -249,6 +270,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* Tests get set.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSetEscape() {
|
||||
StrSubstitutor sub = new StrSubstitutor();
|
||||
assertEquals('$', sub.getEscapeChar());
|
||||
|
@ -370,6 +400,7 @@ public class StrSubstitutorTest extends TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
/**
|
||||
* 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 TestCase {
|
|||
assertEquals("It works!", StrSubstitutor.replace(org, props));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSamePrefixAndSuffix() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("greeting", "Hello");
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
|
||||
package org.apache.commons.lang3.text;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
|
@ -31,27 +31,19 @@ import org.apache.commons.lang3.ObjectUtils;
|
|||
* Unit test for Tokenizer.
|
||||
*
|
||||
*/
|
||||
public class StrTokenizerTest extends TestCase {
|
||||
public class StrTokenizerTest {
|
||||
|
||||
private static final String CSV_SIMPLE_FIXTURE = "A,b,c";
|
||||
|
||||
private static final String TSV_SIMPLE_FIXTURE = "A\tb\tc";
|
||||
|
||||
/**
|
||||
* JUnit constructor.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public StrTokenizerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
private void checkClone(StrTokenizer tokenizer) {
|
||||
assertFalse(StrTokenizer.getCSVInstance() == tokenizer);
|
||||
assertFalse(StrTokenizer.getTSVInstance() == tokenizer);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test1() {
|
||||
|
||||
String input = "a;b;c;\"d;\"\"e\";f; ; ; ";
|
||||
|
@ -72,6 +64,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
|
||||
String input = "a;b;c ;\"d;\"\"e\";f; ; ;";
|
||||
|
@ -92,6 +85,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
|
||||
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
|
||||
|
@ -112,6 +106,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4() {
|
||||
|
||||
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
|
||||
|
@ -132,6 +127,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5() {
|
||||
|
||||
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
|
||||
|
@ -153,6 +149,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6() {
|
||||
|
||||
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
|
||||
|
@ -188,6 +185,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7() {
|
||||
|
||||
String input = "a b c \"d e\" f ";
|
||||
|
@ -208,6 +206,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test8() {
|
||||
|
||||
String input = "a b c \"d e\" f ";
|
||||
|
@ -228,6 +227,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic1() {
|
||||
String input = "a b c";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -237,6 +237,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic2() {
|
||||
String input = "a \nb\fc";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -246,6 +247,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic3() {
|
||||
String input = "a \nb\u0001\fc";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -255,6 +257,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic4() {
|
||||
String input = "a \"b\" c";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -264,6 +267,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic5() {
|
||||
String input = "a:b':c";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -273,6 +277,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicDelim1() {
|
||||
String input = "a:b:c";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -282,6 +287,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicDelim2() {
|
||||
String input = "a:b:c";
|
||||
StrTokenizer tok = new StrTokenizer(input, ',');
|
||||
|
@ -289,6 +295,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicEmpty1() {
|
||||
String input = "a b c";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -300,6 +307,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicEmpty2() {
|
||||
String input = "a b c";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -312,6 +320,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted1() {
|
||||
String input = "a 'b' c";
|
||||
StrTokenizer tok = new StrTokenizer(input, ' ', '\'');
|
||||
|
@ -321,6 +330,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted2() {
|
||||
String input = "a:'b':";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -332,6 +342,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted3() {
|
||||
String input = "a:'b''c'";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -342,6 +353,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted4() {
|
||||
String input = "a: 'b' 'c' :d";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -354,6 +366,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted5() {
|
||||
String input = "a: 'b'x'c' :d";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -366,6 +379,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted6() {
|
||||
String input = "a:'b'\"c':d";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -375,6 +389,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuoted7() {
|
||||
String input = "a:\"There's a reason here\":b";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -385,6 +400,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuotedTrimmed1() {
|
||||
String input = "a: 'b' :";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -397,6 +413,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicTrimmed1() {
|
||||
String input = "a: b : ";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -409,6 +426,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicTrimmed2() {
|
||||
String input = "a: b :";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -421,6 +439,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicIgnoreTrimmed1() {
|
||||
String input = "a: bIGNOREc : ";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -434,6 +453,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicIgnoreTrimmed2() {
|
||||
String input = "IGNOREaIGNORE: IGNORE bIGNOREc IGNORE : IGNORE ";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -447,6 +467,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicIgnoreTrimmed3() {
|
||||
String input = "IGNOREaIGNORE: IGNORE bIGNOREc IGNORE : IGNORE ";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':');
|
||||
|
@ -459,6 +480,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(false, tok.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicIgnoreTrimmed4() {
|
||||
String input = "IGNOREaIGNORE: IGNORE 'bIGNOREc'IGNORE'd' IGNORE : IGNORE ";
|
||||
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
|
||||
|
@ -473,6 +495,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testListArray() {
|
||||
String input = "a b c";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -484,20 +507,23 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testCSV(String data) {
|
||||
private void testCSV(String data) {
|
||||
this.testXSVAbc(StrTokenizer.getCSVInstance(data));
|
||||
this.testXSVAbc(StrTokenizer.getCSVInstance(data.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSVEmpty() {
|
||||
this.testEmpty(StrTokenizer.getCSVInstance());
|
||||
this.testEmpty(StrTokenizer.getCSVInstance(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSVSimple() {
|
||||
this.testCSV(CSV_SIMPLE_FIXTURE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSVSimpleNeedsTrim() {
|
||||
this.testCSV(" " + CSV_SIMPLE_FIXTURE);
|
||||
this.testCSV(" \n\t " + CSV_SIMPLE_FIXTURE);
|
||||
|
@ -516,6 +542,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
} catch (NoSuchElementException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContent() {
|
||||
String input = "a b c \"d e\" f ";
|
||||
StrTokenizer tok = new StrTokenizer(input);
|
||||
|
@ -529,6 +556,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testChaining() {
|
||||
StrTokenizer tok = new StrTokenizer();
|
||||
assertEquals(tok, tok.reset());
|
||||
|
@ -550,6 +578,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
* Tests that the {@link StrTokenizer#clone()} clone method catches {@link CloneNotSupportedException} and returns
|
||||
* <code>null</code>.
|
||||
*/
|
||||
@Test
|
||||
public void testCloneNotSupportedException() {
|
||||
Object notCloned = new StrTokenizer() {
|
||||
@Override
|
||||
|
@ -560,6 +589,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertNull(notCloned);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneNull() {
|
||||
StrTokenizer tokenizer = new StrTokenizer((char[]) null);
|
||||
// Start sanity check
|
||||
|
@ -573,6 +603,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(null, clonedTokenizer.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneReset() {
|
||||
char[] input = new char[]{'a'};
|
||||
StrTokenizer tokenizer = new StrTokenizer(input);
|
||||
|
@ -589,6 +620,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_String() {
|
||||
StrTokenizer tok = new StrTokenizer("a b");
|
||||
assertEquals("a", tok.next());
|
||||
|
@ -603,6 +635,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_String_char() {
|
||||
StrTokenizer tok = new StrTokenizer("a b", ' ');
|
||||
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
|
||||
|
@ -618,6 +651,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_String_char_char() {
|
||||
StrTokenizer tok = new StrTokenizer("a b", ' ', '"');
|
||||
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
|
||||
|
@ -634,6 +668,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_charArray() {
|
||||
StrTokenizer tok = new StrTokenizer("a b".toCharArray());
|
||||
assertEquals("a", tok.next());
|
||||
|
@ -648,6 +683,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_charArray_char() {
|
||||
StrTokenizer tok = new StrTokenizer("a b".toCharArray(), ' ');
|
||||
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
|
||||
|
@ -663,6 +699,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor_charArray_char_char() {
|
||||
StrTokenizer tok = new StrTokenizer("a b".toCharArray(), ' ', '"');
|
||||
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
|
||||
|
@ -679,6 +716,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReset() {
|
||||
StrTokenizer tok = new StrTokenizer("a b c");
|
||||
assertEquals("a", tok.next());
|
||||
|
@ -694,6 +732,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReset_String() {
|
||||
StrTokenizer tok = new StrTokenizer("x x x");
|
||||
tok.reset("d e");
|
||||
|
@ -706,6 +745,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testReset_charArray() {
|
||||
StrTokenizer tok = new StrTokenizer("x x x");
|
||||
|
||||
|
@ -719,11 +759,13 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTSV() {
|
||||
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE));
|
||||
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTSVEmpty() {
|
||||
this.testEmpty(StrTokenizer.getCSVInstance());
|
||||
this.testEmpty(StrTokenizer.getCSVInstance(""));
|
||||
|
@ -754,6 +796,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(3, tokenizer.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIteration() {
|
||||
StrTokenizer tkn = new StrTokenizer("a b c");
|
||||
assertEquals(false, tkn.hasPrevious());
|
||||
|
@ -796,6 +839,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTokenizeSubclassInputChange() {
|
||||
StrTokenizer tkn = new StrTokenizer("a b c d e") {
|
||||
@Override
|
||||
|
@ -808,6 +852,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testTokenizeSubclassOutputChange() {
|
||||
StrTokenizer tkn = new StrTokenizer("a b c") {
|
||||
@Override
|
||||
|
@ -823,6 +868,7 @@ public class StrTokenizerTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testToString() {
|
||||
StrTokenizer tkn = new StrTokenizer("a b c d e");
|
||||
assertEquals("StrTokenizer[not tokenized yet]", tkn.toString());
|
||||
|
|
|
@ -16,23 +16,23 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.text;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for WordUtils class.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class WordUtilsTest extends TestCase {
|
||||
|
||||
public WordUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class WordUtilsTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new WordUtils());
|
||||
Constructor<?>[] cons = WordUtils.class.getDeclaredConstructors();
|
||||
|
@ -43,6 +43,7 @@ public class WordUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testWrap_StringInt() {
|
||||
assertEquals(null, WordUtils.wrap(null, 20));
|
||||
assertEquals(null, WordUtils.wrap(null, -1));
|
||||
|
@ -70,6 +71,7 @@ public class WordUtilsTest extends TestCase {
|
|||
assertEquals(expected, WordUtils.wrap(input, 20));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrap_StringIntStringBoolean() {
|
||||
assertEquals(null, WordUtils.wrap(null, 20, "\n", false));
|
||||
assertEquals(null, WordUtils.wrap(null, 20, "\n", true));
|
||||
|
@ -149,6 +151,7 @@ public class WordUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testCapitalize_String() {
|
||||
assertEquals(null, WordUtils.capitalize(null));
|
||||
assertEquals("", WordUtils.capitalize(""));
|
||||
|
@ -162,6 +165,7 @@ public class WordUtilsTest extends TestCase {
|
|||
assertEquals("I AM HERE 123", WordUtils.capitalize("I AM HERE 123") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCapitalizeWithDelimiters_String() {
|
||||
assertEquals(null, WordUtils.capitalize(null, null));
|
||||
assertEquals("", WordUtils.capitalize("", new char[0]));
|
||||
|
@ -179,6 +183,7 @@ public class WordUtilsTest extends TestCase {
|
|||
assertEquals("I Am.fine", WordUtils.capitalize("i am.fine", null) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCapitalizeFully_String() {
|
||||
assertEquals(null, WordUtils.capitalizeFully(null));
|
||||
assertEquals("", WordUtils.capitalizeFully(""));
|
||||
|
@ -192,6 +197,7 @@ public class WordUtilsTest extends TestCase {
|
|||
assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCapitalizeFullyWithDelimiters_String() {
|
||||
assertEquals(null, WordUtils.capitalizeFully(null, null));
|
||||
assertEquals("", WordUtils.capitalizeFully("", new char[0]));
|
||||
|
@ -209,6 +215,7 @@ public class WordUtilsTest extends TestCase {
|
|||
assertEquals("I Am.fine", WordUtils.capitalizeFully("i am.fine", null) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUncapitalize_String() {
|
||||
assertEquals(null, WordUtils.uncapitalize(null));
|
||||
assertEquals("", WordUtils.uncapitalize(""));
|
||||
|
@ -222,6 +229,7 @@ public class WordUtilsTest extends TestCase {
|
|||
assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUncapitalizeWithDelimiters_String() {
|
||||
assertEquals(null, WordUtils.uncapitalize(null, null));
|
||||
assertEquals("", WordUtils.uncapitalize("", new char[0]));
|
||||
|
@ -240,6 +248,7 @@ public class WordUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testInitials_String() {
|
||||
assertEquals(null, WordUtils.initials(null));
|
||||
assertEquals("", WordUtils.initials(""));
|
||||
|
@ -254,6 +263,7 @@ public class WordUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testInitials_String_charArray() {
|
||||
char[] array = null;
|
||||
assertEquals(null, WordUtils.initials(null, array));
|
||||
|
@ -335,6 +345,7 @@ public class WordUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSwapCase_String() {
|
||||
assertEquals(null, WordUtils.swapCase(null));
|
||||
assertEquals("", WordUtils.swapCase(""));
|
||||
|
|
|
@ -17,22 +17,26 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}.
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EntityArraysTest extends TestCase {
|
||||
public class EntityArraysTest {
|
||||
|
||||
@Test
|
||||
public void testConstructorExists() {
|
||||
new EntityArrays();
|
||||
}
|
||||
|
||||
// LANG-659 - check arrays for duplicate entries
|
||||
@Test
|
||||
public void testHTML40_EXTENDED_ESCAPE(){
|
||||
Set<String> col0 = new HashSet<String>();
|
||||
Set<String> col1 = new HashSet<String>();
|
||||
|
@ -44,6 +48,7 @@ public class EntityArraysTest extends TestCase {
|
|||
}
|
||||
|
||||
// LANG-658 - check arrays for duplicate entries
|
||||
@Test
|
||||
public void testISO8859_1_ESCAPE(){
|
||||
Set<String> col0 = new HashSet<String>();
|
||||
Set<String> col1 = new HashSet<String>();
|
||||
|
|
|
@ -17,17 +17,20 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.LookupTranslator}.
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LookupTranslatorTest extends TestCase {
|
||||
public class LookupTranslatorTest {
|
||||
|
||||
@Test
|
||||
public void testBasicLookup() throws IOException {
|
||||
LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { "one", "two" } });
|
||||
StringWriter out = new StringWriter();
|
||||
|
|
|
@ -17,14 +17,17 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityEscaper}.
|
||||
* @version $Id$
|
||||
*/
|
||||
public class NumericEntityEscaperTest extends TestCase {
|
||||
public class NumericEntityEscaperTest {
|
||||
|
||||
@Test
|
||||
public void testBelow() {
|
||||
NumericEntityEscaper nee = NumericEntityEscaper.below('F');
|
||||
|
||||
|
@ -33,6 +36,7 @@ public class NumericEntityEscaperTest extends TestCase {
|
|||
assertEquals("Failed to escape numeric entities via the below method", "ADFGZ", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBetween() {
|
||||
NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L');
|
||||
|
||||
|
@ -41,6 +45,7 @@ public class NumericEntityEscaperTest extends TestCase {
|
|||
assertEquals("Failed to escape numeric entities via the between method", "ADFGZ", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbove() {
|
||||
NumericEntityEscaper nee = NumericEntityEscaper.above('F');
|
||||
|
||||
|
@ -50,6 +55,7 @@ public class NumericEntityEscaperTest extends TestCase {
|
|||
}
|
||||
|
||||
// See LANG-617
|
||||
@Test
|
||||
public void testSupplementary() {
|
||||
NumericEntityEscaper nee = new NumericEntityEscaper();
|
||||
String input = "\uD803\uDC22";
|
||||
|
|
|
@ -17,14 +17,18 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityUnescaper}.
|
||||
* @version $Id$
|
||||
*/
|
||||
public class NumericEntityUnescaperTest extends TestCase {
|
||||
public class NumericEntityUnescaperTest {
|
||||
|
||||
@Test
|
||||
public void testSupplementaryUnescaping() {
|
||||
NumericEntityUnescaper neu = new NumericEntityUnescaper();
|
||||
String input = "𐰢";
|
||||
|
@ -34,6 +38,7 @@ public class NumericEntityUnescaperTest extends TestCase {
|
|||
assertEquals("Failed to unescape numeric entities supplementary characters", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutOfBounds() {
|
||||
NumericEntityUnescaper neu = new NumericEntityUnescaper();
|
||||
|
||||
|
@ -43,6 +48,7 @@ public class NumericEntityUnescaperTest extends TestCase {
|
|||
assertEquals("Failed to ignore when last character is &", "Test &#X", neu.translate("Test &#X"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnfinishedEntity() {
|
||||
// parse it
|
||||
NumericEntityUnescaper neu = new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.semiColonOptional);
|
||||
|
|
|
@ -17,14 +17,16 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.OctalUnescaper}.
|
||||
* @version $Id: OctalUnescaperTest.java 979392 2010-07-26 18:09:52Z mbenson $
|
||||
*/
|
||||
public class OctalUnescaperTest extends TestCase {
|
||||
public class OctalUnescaperTest {
|
||||
|
||||
@Test
|
||||
public void testBetween() {
|
||||
OctalUnescaper oue = new OctalUnescaper(); //.between("1", "377");
|
||||
|
||||
|
|
|
@ -17,14 +17,17 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UnicodeEscaperTest extends TestCase {
|
||||
public class UnicodeEscaperTest {
|
||||
|
||||
@Test
|
||||
public void testBelow() {
|
||||
UnicodeEscaper ue = UnicodeEscaper.below('F');
|
||||
|
||||
|
@ -33,6 +36,7 @@ public class UnicodeEscaperTest extends TestCase {
|
|||
assertEquals("Failed to escape Unicode characters via the below method", "\\u0041\\u0044FGZ", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBetween() {
|
||||
UnicodeEscaper ue = UnicodeEscaper.between('F', 'L');
|
||||
|
||||
|
@ -41,6 +45,7 @@ public class UnicodeEscaperTest extends TestCase {
|
|||
assertEquals("Failed to escape Unicode characters via the between method", "AD\\u0046\\u0047Z", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbove() {
|
||||
UnicodeEscaper ue = UnicodeEscaper.above('F');
|
||||
|
||||
|
|
|
@ -17,15 +17,19 @@
|
|||
|
||||
package org.apache.commons.lang3.text.translate;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UnicodeUnescaperTest extends TestCase {
|
||||
public class UnicodeUnescaperTest {
|
||||
|
||||
// Requested in LANG-507
|
||||
@Test
|
||||
public void testUPlus() {
|
||||
UnicodeUnescaper uu = new UnicodeUnescaper();
|
||||
|
||||
|
@ -33,6 +37,7 @@ public class UnicodeUnescaperTest extends TestCase {
|
|||
assertEquals("Failed to unescape Unicode characters with 'u+' notation", "G", uu.translate(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUuuuu() {
|
||||
UnicodeUnescaper uu = new UnicodeUnescaper();
|
||||
|
||||
|
@ -41,6 +46,7 @@ public class UnicodeUnescaperTest extends TestCase {
|
|||
assertEquals("Failed to unescape Unicode characters with many 'u' characters", "G", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanFour() {
|
||||
UnicodeUnescaper uu = new UnicodeUnescaper();
|
||||
|
||||
|
|
|
@ -16,25 +16,22 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* TestCase for DateFormatUtils.
|
||||
*
|
||||
*/
|
||||
public class DateFormatUtilsTest extends TestCase {
|
||||
|
||||
public DateFormatUtilsTest(String s) {
|
||||
super(s);
|
||||
}
|
||||
public class DateFormatUtilsTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new DateFormatUtils());
|
||||
Constructor<?>[] cons = DateFormatUtils.class.getDeclaredConstructors();
|
||||
|
@ -45,6 +42,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testFormat() {
|
||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
|
@ -68,6 +66,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testFormatCalendar() {
|
||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
|
@ -90,6 +89,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatUTC() {
|
||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
|
@ -102,6 +102,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTimeISO(){
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar cal = Calendar.getInstance(timeZone);
|
||||
|
@ -125,6 +126,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
assertEquals("2002-02-23T09:11:12-03:00", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateISO(){
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar cal = Calendar.getInstance(timeZone);
|
||||
|
@ -148,6 +150,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
assertEquals("2002-02-23-03:00", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeISO(){
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar cal = Calendar.getInstance(timeZone);
|
||||
|
@ -171,6 +174,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
assertEquals("T10:11:12-03:00", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeNoTISO(){
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar cal = Calendar.getInstance(timeZone);
|
||||
|
@ -194,6 +198,7 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
assertEquals("10:11:12-03:00", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMTP(){
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar cal = Calendar.getInstance(timeZone);
|
||||
|
|
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DateUtilsFragmentTest extends TestCase {
|
||||
public class DateUtilsFragmentTest {
|
||||
|
||||
private static final int months = 7; // second final prime before 12
|
||||
private static final int days = 23; // second final prime before 31 (and valid)
|
||||
|
@ -33,14 +34,16 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
private Date aDate;
|
||||
private Calendar aCalendar;
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
aCalendar = Calendar.getInstance();
|
||||
aCalendar.set(2005, months, days, hours, minutes, seconds);
|
||||
aCalendar.set(Calendar.MILLISECOND, millis);
|
||||
aDate = aCalendar.getTime();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullDate() {
|
||||
try {
|
||||
DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND);
|
||||
|
@ -68,6 +71,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
} catch(IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullCalendar() {
|
||||
try {
|
||||
DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND);
|
||||
|
@ -95,6 +99,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
} catch(IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidFragmentWithDate() {
|
||||
try {
|
||||
DateUtils.getFragmentInMilliseconds(aDate, 0);
|
||||
|
@ -122,6 +127,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
} catch(IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidFragmentWithCalendar() {
|
||||
try {
|
||||
DateUtils.getFragmentInMilliseconds(aCalendar, 0);
|
||||
|
@ -149,6 +155,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
} catch(IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondFragmentInLargerUnitWithDate() {
|
||||
assertEquals(0, DateUtils.getFragmentInMilliseconds(aDate, Calendar.MILLISECOND));
|
||||
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.MILLISECOND));
|
||||
|
@ -157,6 +164,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MILLISECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondFragmentInLargerUnitWithCalendar() {
|
||||
assertEquals(0, DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MILLISECOND));
|
||||
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.MILLISECOND));
|
||||
|
@ -165,6 +173,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MILLISECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondFragmentInLargerUnitWithDate() {
|
||||
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.SECOND));
|
||||
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.SECOND));
|
||||
|
@ -172,6 +181,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.SECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondFragmentInLargerUnitWithCalendar() {
|
||||
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.SECOND));
|
||||
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.SECOND));
|
||||
|
@ -179,51 +189,61 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.SECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinuteFragmentInLargerUnitWithDate() {
|
||||
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MINUTE));
|
||||
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MINUTE));
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinuteFragmentInLargerUnitWithCalendar() {
|
||||
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MINUTE));
|
||||
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MINUTE));
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHourOfDayFragmentInLargerUnitWithDate() {
|
||||
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.HOUR_OF_DAY));
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHourOfDayFragmentInLargerUnitWithCalendar() {
|
||||
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.HOUR_OF_DAY));
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDayOfYearFragmentInLargerUnitWithDate() {
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DAY_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDayOfYearFragmentInLargerUnitWithCalendar() {
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DAY_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateFragmentInLargerUnitWithDate() {
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DATE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateFragmentInLargerUnitWithCalendar() {
|
||||
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DATE));
|
||||
}
|
||||
|
||||
//Calendar.SECOND as useful fragment
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfSecondWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.SECOND);
|
||||
assertEquals(millis, testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfSecondWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.SECOND);
|
||||
assertEquals(millis, testResult);
|
||||
|
@ -232,21 +252,25 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
|
||||
//Calendar.MINUTE as useful fragment
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfMinuteWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfMinuteWithCalender() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsofMinuteWithDate() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MINUTE);
|
||||
assertEquals(seconds, testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsofMinuteWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MINUTE);
|
||||
assertEquals(seconds, testResult);
|
||||
|
@ -255,16 +279,19 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
|
||||
//Calendar.HOUR_OF_DAY as useful fragment
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfHourWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfHourWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsofHourWithDate() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY);
|
||||
assertEquals(
|
||||
|
@ -274,6 +301,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsofHourWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY);
|
||||
assertEquals(
|
||||
|
@ -283,17 +311,20 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfHourWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.HOUR_OF_DAY);
|
||||
assertEquals(minutes, testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfHourWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.HOUR_OF_DAY);
|
||||
assertEquals(minutes, testResult);
|
||||
}
|
||||
|
||||
//Calendar.DATE and Calendar.DAY_OF_YEAR as useful fragment
|
||||
@Test
|
||||
public void testMillisecondsOfDayWithDate() {
|
||||
long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE);
|
||||
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
|
||||
|
@ -302,6 +333,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue, testresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfDayWithCalendar() {
|
||||
long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE);
|
||||
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
|
||||
|
@ -310,6 +342,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue, testresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsOfDayWithDate() {
|
||||
long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE);
|
||||
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
|
||||
|
@ -318,6 +351,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue, testresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsOfDayWithCalendar() {
|
||||
long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE);
|
||||
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
|
||||
|
@ -326,6 +360,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue, testresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfDayWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE);
|
||||
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
|
||||
|
@ -334,6 +369,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue,testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfDayWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE);
|
||||
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
|
||||
|
@ -342,6 +378,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue, testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursOfDayWithDate() {
|
||||
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.DATE);
|
||||
long expectedValue = hours;
|
||||
|
@ -350,6 +387,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
assertEquals(expectedValue,testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursOfDayWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DATE);
|
||||
long expectedValue = hours;
|
||||
|
@ -360,6 +398,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
|
||||
|
||||
//Calendar.MONTH as useful fragment
|
||||
@Test
|
||||
public void testMillisecondsOfMonthWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
|
||||
|
@ -367,6 +406,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfMonthWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
|
||||
|
@ -374,6 +414,7 @@ public class DateUtilsFragmentTest extends TestCase {
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsOfMonthWithDate() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH);
|
||||
assertEquals(
|
||||
|
@ -384,6 +425,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsOfMonthWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH);
|
||||
assertEquals(
|
||||
|
@ -394,6 +436,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfMonthWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH);
|
||||
assertEquals(minutes
|
||||
|
@ -402,6 +445,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfMonthWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH);
|
||||
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
|
||||
|
@ -409,6 +453,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursOfMonthWithDate() {
|
||||
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
|
||||
assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY))
|
||||
|
@ -416,6 +461,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursOfMonthWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
|
||||
assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY))
|
||||
|
@ -424,6 +470,7 @@ testResult);
|
|||
}
|
||||
|
||||
//Calendar.YEAR as useful fragment
|
||||
@Test
|
||||
public void testMillisecondsOfYearWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
@ -433,6 +480,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMillisecondsOfYearWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR);
|
||||
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
|
||||
|
@ -440,6 +488,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsOfYearWithDate() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.YEAR);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
@ -452,6 +501,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondsOfYearWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR);
|
||||
assertEquals(
|
||||
|
@ -462,6 +512,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfYearWithDate() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.YEAR);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
@ -472,6 +523,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutesOfYearWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR);
|
||||
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
|
||||
|
@ -479,6 +531,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursOfYearWithDate() {
|
||||
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
@ -488,6 +541,7 @@ testResult);
|
|||
testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursOfYearWithCalendar() {
|
||||
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR);
|
||||
assertEquals( hours +((aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* These Unit-tests will check all possible extremes when using some rounding-methods of DateUtils.
|
||||
* The extremes are tested at the switch-point in milliseconds
|
||||
|
@ -37,7 +38,7 @@ import junit.framework.TestCase;
|
|||
* @since 3.0
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DateUtilsRoundingTest extends TestCase {
|
||||
public class DateUtilsRoundingTest {
|
||||
|
||||
DateFormat dateTimeParser;
|
||||
|
||||
|
@ -53,9 +54,10 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
Calendar januaryOneCalendar;
|
||||
FastDateFormat fdf = DateFormatUtils.ISO_DATETIME_FORMAT;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
|
||||
|
||||
targetYearDate = dateTimeParser.parse("January 1, 2007 0:00:00.000");
|
||||
|
@ -79,6 +81,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundYear() throws Exception {
|
||||
final int calendarField = Calendar.YEAR;
|
||||
Date roundedUpDate = dateTimeParser.parse("January 1, 2008 0:00:00.000");
|
||||
|
@ -95,6 +98,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundMonth() throws Exception {
|
||||
final int calendarField = Calendar.MONTH;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -138,6 +142,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundSemiMonth() throws Exception {
|
||||
final int calendarField = DateUtils.SEMI_MONTH;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -205,6 +210,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundDate() throws Exception {
|
||||
final int calendarField = Calendar.DATE;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -229,6 +235,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundDayOfMonth() throws Exception {
|
||||
final int calendarField = Calendar.DAY_OF_MONTH;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -253,6 +260,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundAmPm() throws Exception {
|
||||
final int calendarField = Calendar.AM_PM;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -284,6 +292,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundHourOfDay() throws Exception {
|
||||
final int calendarField = Calendar.HOUR_OF_DAY;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -308,6 +317,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundHour() throws Exception {
|
||||
final int calendarField = Calendar.HOUR;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -332,6 +342,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundMinute() throws Exception {
|
||||
final int calendarField = Calendar.MINUTE;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -356,6 +367,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundSecond() throws Exception {
|
||||
final int calendarField = Calendar.SECOND;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -380,6 +392,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testRoundMilliSecond() throws Exception {
|
||||
final int calendarField = Calendar.MILLISECOND;
|
||||
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
|
||||
|
@ -400,6 +413,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateYear() throws Exception {
|
||||
final int calendarField = Calendar.YEAR;
|
||||
Date lastTruncateDate = dateTimeParser.parse("December 31, 2007 23:59:59.999");
|
||||
|
@ -412,6 +426,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateMonth() throws Exception {
|
||||
final int calendarField = Calendar.MONTH;
|
||||
Date truncatedDate = dateTimeParser.parse("March 1, 2008 0:00:00.000");
|
||||
|
@ -426,6 +441,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateSemiMonth() throws Exception {
|
||||
final int calendarField = DateUtils.SEMI_MONTH;
|
||||
Date truncatedDate, lastTruncateDate;
|
||||
|
@ -478,6 +494,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateDate() throws Exception {
|
||||
final int calendarField = Calendar.DATE;
|
||||
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
|
||||
|
@ -490,6 +507,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateDayOfMonth() throws Exception {
|
||||
final int calendarField = Calendar.DAY_OF_MONTH;
|
||||
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
|
||||
|
@ -503,6 +521,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateAmPm() throws Exception {
|
||||
final int calendarField = Calendar.AM_PM;
|
||||
|
||||
|
@ -521,6 +540,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateHour() throws Exception {
|
||||
final int calendarField = Calendar.HOUR;
|
||||
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:59:59.999");
|
||||
|
@ -533,6 +553,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateHourOfDay() throws Exception {
|
||||
final int calendarField = Calendar.HOUR_OF_DAY;
|
||||
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:59:59.999");
|
||||
|
@ -545,6 +566,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateMinute() throws Exception {
|
||||
final int calendarField = Calendar.MINUTE;
|
||||
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:15:59.999");
|
||||
|
@ -557,6 +579,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateSecond() throws Exception {
|
||||
final int calendarField = Calendar.SECOND;
|
||||
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:15:14.999");
|
||||
|
@ -569,6 +592,7 @@ public class DateUtilsRoundingTest extends TestCase {
|
|||
* @throws Exception
|
||||
* @since 3.0
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateMilliSecond() throws Exception {
|
||||
final int calendarField = Calendar.MILLISECOND;
|
||||
baseTruncateTest(targetMilliSecondDate, targetMilliSecondDate, calendarField);
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
@ -32,15 +35,13 @@ import java.util.NoSuchElementException;
|
|||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.time.DateUtils}.
|
||||
*
|
||||
*/
|
||||
public class DateUtilsTest extends TestCase {
|
||||
public class DateUtilsTest {
|
||||
|
||||
private static final long MILLIS_TEST;
|
||||
static {
|
||||
|
@ -80,13 +81,10 @@ public class DateUtilsTest extends TestCase {
|
|||
TimeZone zone = null;
|
||||
TimeZone defaultZone = null;
|
||||
|
||||
public DateUtilsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
|
||||
dateParser = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
|
||||
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
|
||||
|
@ -139,6 +137,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new DateUtils());
|
||||
Constructor<?>[] cons = DateUtils.class.getDeclaredConstructors();
|
||||
|
@ -149,6 +148,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsSameDay_Date() {
|
||||
Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
|
||||
Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
|
||||
|
@ -166,6 +166,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsSameDay_Cal() {
|
||||
GregorianCalendar cal1 = new GregorianCalendar(2004, 6, 9, 13, 45);
|
||||
GregorianCalendar cal2 = new GregorianCalendar(2004, 6, 9, 13, 45);
|
||||
|
@ -183,6 +184,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsSameInstant_Date() {
|
||||
Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
|
||||
Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
|
||||
|
@ -200,6 +202,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsSameInstant_Cal() {
|
||||
GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
|
||||
GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT-1"));
|
||||
|
@ -218,6 +221,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsSameLocalTime_Cal() {
|
||||
GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
|
||||
GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT-1"));
|
||||
|
@ -244,6 +248,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testParseDate() throws Exception {
|
||||
GregorianCalendar cal = new GregorianCalendar(1972, 11, 3);
|
||||
String dateStr = "1972-12-03";
|
||||
|
@ -281,6 +286,7 @@ public class DateUtilsTest extends TestCase {
|
|||
} catch (ParseException ex) {}
|
||||
}
|
||||
// LANG-486
|
||||
@Test
|
||||
public void testParseDateWithLeniency() throws Exception {
|
||||
GregorianCalendar cal = new GregorianCalendar(1998, 6, 30);
|
||||
String dateStr = "02 942, 1996";
|
||||
|
@ -296,6 +302,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddYears() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addYears(base, 0);
|
||||
|
@ -315,6 +322,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddMonths() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addMonths(base, 0);
|
||||
|
@ -334,6 +342,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddWeeks() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addWeeks(base, 0);
|
||||
|
@ -353,6 +362,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddDays() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addDays(base, 0);
|
||||
|
@ -372,6 +382,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddHours() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addHours(base, 0);
|
||||
|
@ -391,6 +402,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddMinutes() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addMinutes(base, 0);
|
||||
|
@ -410,6 +422,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddSeconds() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addSeconds(base, 0);
|
||||
|
@ -429,6 +442,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testAddMilliseconds() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.addMilliseconds(base, 0);
|
||||
|
@ -448,6 +462,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetYears() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setYears(base, 2000);
|
||||
|
@ -467,6 +482,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetMonths() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setMonths(base, 5);
|
||||
|
@ -488,6 +504,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetDays() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setDays(base, 1);
|
||||
|
@ -509,6 +526,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetHours() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setHours(base, 0);
|
||||
|
@ -530,6 +548,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetMinutes() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setMinutes(base, 0);
|
||||
|
@ -551,6 +570,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetSeconds() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setSeconds(base, 0);
|
||||
|
@ -572,6 +592,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testSetMilliseconds() throws Exception {
|
||||
Date base = new Date(MILLIS_TEST);
|
||||
Date result = DateUtils.setMilliseconds(base, 0);
|
||||
|
@ -606,6 +627,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testToCalendar() {
|
||||
assertEquals("Failed to convert to a Calendar and back", date1, DateUtils.toCalendar(date1).getTime());
|
||||
try {
|
||||
|
@ -620,6 +642,7 @@ public class DateUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests various values with the round method
|
||||
*/
|
||||
@Test
|
||||
public void testRound() throws Exception {
|
||||
// tests for public static Date round(Date date, int field)
|
||||
assertEquals("round year-1 failed",
|
||||
|
@ -843,6 +866,7 @@ public class DateUtilsTest extends TestCase {
|
|||
* Tests the Changes Made by LANG-346 to the DateUtils.modify() private method invoked
|
||||
* by DateUtils.round().
|
||||
*/
|
||||
@Test
|
||||
public void testRoundLang346() throws Exception
|
||||
{
|
||||
TimeZone.setDefault(defaultZone);
|
||||
|
@ -905,6 +929,7 @@ public class DateUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests various values with the trunc method
|
||||
*/
|
||||
@Test
|
||||
public void testTruncate() throws Exception {
|
||||
// tests public static Date truncate(Date date, int field)
|
||||
assertEquals("truncate year-1 failed",
|
||||
|
@ -1098,6 +1123,7 @@ public class DateUtilsTest extends TestCase {
|
|||
*
|
||||
* see http://issues.apache.org/jira/browse/LANG-59
|
||||
*/
|
||||
@Test
|
||||
public void testTruncateLang59() throws Exception {
|
||||
if (!SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) {
|
||||
this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION);
|
||||
|
@ -1173,6 +1199,7 @@ public class DateUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// http://issues.apache.org/jira/browse/LANG-530
|
||||
@Test
|
||||
public void testLang530() throws ParseException {
|
||||
Date d = new Date();
|
||||
String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
|
||||
|
@ -1184,6 +1211,7 @@ public class DateUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests various values with the ceiling method
|
||||
*/
|
||||
@Test
|
||||
public void testCeil() throws Exception {
|
||||
// test javadoc
|
||||
assertEquals("ceiling javadoc-1 failed",
|
||||
|
@ -1433,6 +1461,7 @@ public class DateUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests the iterator exceptions
|
||||
*/
|
||||
@Test
|
||||
public void testIteratorEx() throws Exception {
|
||||
try {
|
||||
DateUtils.iterator(Calendar.getInstance(), -9999);
|
||||
|
@ -1458,6 +1487,7 @@ public class DateUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests the calendar iterator for week ranges
|
||||
*/
|
||||
@Test
|
||||
public void testWeekIterator() throws Exception {
|
||||
Calendar now = Calendar.getInstance();
|
||||
for (int i = 0; i< 7; i++) {
|
||||
|
@ -1504,6 +1534,7 @@ public class DateUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests the calendar iterator for month-based ranges
|
||||
*/
|
||||
@Test
|
||||
public void testMonthIterator() throws Exception {
|
||||
Iterator<?> it = DateUtils.iterator(date1, DateUtils.RANGE_MONTH_SUNDAY);
|
||||
assertWeekIterator(it,
|
||||
|
@ -1556,12 +1587,12 @@ public class DateUtilsTest extends TestCase {
|
|||
*/
|
||||
private static void assertWeekIterator(Iterator<?> it, Calendar start, Calendar end) {
|
||||
Calendar cal = (Calendar) it.next();
|
||||
assertEquals("", start, cal, 0);
|
||||
assertCalendarsEquals("", start, cal, 0);
|
||||
Calendar last = null;
|
||||
int count = 1;
|
||||
while (it.hasNext()) {
|
||||
//Check this is just a date (no time component)
|
||||
assertEquals("", cal, DateUtils.truncate(cal, Calendar.DATE), 0);
|
||||
assertCalendarsEquals("", cal, DateUtils.truncate(cal, Calendar.DATE), 0);
|
||||
|
||||
last = cal;
|
||||
cal = (Calendar) it.next();
|
||||
|
@ -1569,19 +1600,19 @@ public class DateUtilsTest extends TestCase {
|
|||
|
||||
//Check that this is one day more than the last date
|
||||
last.add(Calendar.DATE, 1);
|
||||
assertEquals("", last, cal, 0);
|
||||
assertCalendarsEquals("", last, cal, 0);
|
||||
}
|
||||
if (count % 7 != 0) {
|
||||
throw new AssertionFailedError("There were " + count + " days in this iterator");
|
||||
}
|
||||
assertEquals("", end, cal, 0);
|
||||
assertCalendarsEquals("", end, cal, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check that Calendar objects are close enough
|
||||
* delta is in milliseconds
|
||||
*/
|
||||
private static void assertEquals(String message, Calendar cal1, Calendar cal2, long delta) {
|
||||
private static void assertCalendarsEquals(String message, Calendar cal1, Calendar cal2, long delta) {
|
||||
if (Math.abs(cal1.getTime().getTime() - cal2.getTime().getTime()) > delta) {
|
||||
throw new AssertionFailedError(
|
||||
message + " expected " + cal1.getTime() + " but got " + cal2.getTime());
|
||||
|
|
|
@ -17,24 +17,21 @@
|
|||
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* TestCase for DurationFormatUtils.
|
||||
*
|
||||
*/
|
||||
public class DurationFormatUtilsTest extends TestCase {
|
||||
|
||||
public DurationFormatUtilsTest(String s) {
|
||||
super(s);
|
||||
}
|
||||
public class DurationFormatUtilsTest {
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new DurationFormatUtils());
|
||||
Constructor<?>[] cons = DurationFormatUtils.class.getDeclaredConstructors();
|
||||
|
@ -45,6 +42,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testFormatDurationWords() {
|
||||
String text = null;
|
||||
|
||||
|
@ -132,6 +130,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
/**
|
||||
* Tests that "1 <unit>s" gets converted to "1 <unit>" but that "11 <unit>s" is left alone.
|
||||
*/
|
||||
@Test
|
||||
public void testFormatDurationPluralWords() {
|
||||
long oneSecond = 1000;
|
||||
long oneMinute = oneSecond * 60;
|
||||
|
@ -174,6 +173,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
assertEquals("1 day 1 hour 1 minute 1 second", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatDurationHMS() {
|
||||
long time = 0;
|
||||
assertEquals("0:00:00.000", DurationFormatUtils.formatDurationHMS(time));
|
||||
|
@ -203,6 +203,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
assertEquals("1:02:12.789", DurationFormatUtils.formatDurationHMS(time));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatDurationISO() {
|
||||
assertEquals("P0Y0M0DT0H0M0.000S", DurationFormatUtils.formatDurationISO(0L));
|
||||
assertEquals("P0Y0M0DT0H0M0.001S", DurationFormatUtils.formatDurationISO(1L));
|
||||
|
@ -211,6 +212,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
assertEquals("P0Y0M0DT0H1M15.321S", DurationFormatUtils.formatDurationISO(75321L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatDuration() {
|
||||
long duration = 0;
|
||||
assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
|
||||
|
@ -248,6 +250,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatPeriodISO() {
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar base = Calendar.getInstance(timeZone);
|
||||
|
@ -275,6 +278,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
// assertEquals("P1Y2M3DT10H30M", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatPeriod() {
|
||||
Calendar cal1970 = Calendar.getInstance();
|
||||
cal1970.set(1970, 0, 1, 0, 0, 0);
|
||||
|
@ -328,6 +332,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
assertEquals("048", DurationFormatUtils.formatPeriod(time1970, time, "MMM"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLexx() {
|
||||
// tests each constant
|
||||
assertArrayEquals(new DurationFormatUtils.Token[]{
|
||||
|
@ -381,18 +386,21 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
|
||||
|
||||
// http://issues.apache.org/bugzilla/show_bug.cgi?id=38401
|
||||
@Test
|
||||
public void testBugzilla38401() {
|
||||
assertEqualDuration( "0000/00/30 16:00:00 000", new int[] { 2006, 0, 26, 18, 47, 34 },
|
||||
new int[] { 2006, 1, 26, 10, 47, 34 }, "yyyy/MM/dd HH:mm:ss SSS");
|
||||
}
|
||||
|
||||
// https://issues.apache.org/jira/browse/LANG-281
|
||||
@Test
|
||||
public void testJiraLang281() {
|
||||
assertEqualDuration( "09", new int[] { 2005, 11, 31, 0, 0, 0 },
|
||||
new int[] { 2006, 9, 6, 0, 0, 0 }, "MM");
|
||||
}
|
||||
|
||||
// Testing the under a day range in DurationFormatUtils.formatPeriod
|
||||
@Test
|
||||
public void testLowDurations() {
|
||||
for(int hr=0; hr < 24; hr++) {
|
||||
for(int min=0; min < 60; min++) {
|
||||
|
@ -408,6 +416,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
// Attempting to test edge cases in DurationFormatUtils.formatPeriod
|
||||
@Test
|
||||
public void testEdgeDurations() {
|
||||
assertEqualDuration( "01", new int[] { 2006, 0, 15, 0, 0, 0 },
|
||||
new int[] { 2006, 2, 10, 0, 0, 0 }, "MM");
|
||||
|
@ -497,6 +506,7 @@ public class DurationFormatUtilsTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDurationsByBruteForce() {
|
||||
bruteForce(2006, 0, 1, "d", Calendar.DAY_OF_MONTH);
|
||||
bruteForce(2006, 0, 2, "d", Calendar.DAY_OF_MONTH);
|
||||
|
|
|
@ -16,21 +16,22 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* TestCase for StopWatch.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StopWatchTest extends TestCase {
|
||||
|
||||
public StopWatchTest(String s) {
|
||||
super(s);
|
||||
}
|
||||
public class StopWatchTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testStopWatchSimple(){
|
||||
StopWatch watch = new StopWatch();
|
||||
watch.start();
|
||||
|
@ -46,6 +47,7 @@ public class StopWatchTest extends TestCase {
|
|||
assertEquals(0, watch.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopWatchSimpleGet(){
|
||||
StopWatch watch = new StopWatch();
|
||||
assertEquals(0, watch.getTime());
|
||||
|
@ -56,6 +58,7 @@ public class StopWatchTest extends TestCase {
|
|||
assertTrue(watch.getTime() < 2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopWatchSplit(){
|
||||
StopWatch watch = new StopWatch();
|
||||
watch.start();
|
||||
|
@ -77,6 +80,7 @@ public class StopWatchTest extends TestCase {
|
|||
assertTrue(totalTime < 1900);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopWatchSuspend(){
|
||||
StopWatch watch = new StopWatch();
|
||||
watch.start();
|
||||
|
@ -95,6 +99,7 @@ public class StopWatchTest extends TestCase {
|
|||
assertTrue(totalTime < 1300);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLang315() {
|
||||
StopWatch watch = new StopWatch();
|
||||
watch.start();
|
||||
|
@ -108,6 +113,7 @@ public class StopWatchTest extends TestCase {
|
|||
}
|
||||
|
||||
// test bad states
|
||||
@Test
|
||||
public void testBadStates() {
|
||||
StopWatch watch = new StopWatch();
|
||||
try {
|
||||
|
@ -192,6 +198,7 @@ public class StopWatchTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStartTime() {
|
||||
long beforeStopWatch = System.currentTimeMillis();
|
||||
StopWatch watch = new StopWatch();
|
||||
|
|
Loading…
Reference in New Issue