Update tests to JUnit Jupiter (closes #375)
This patch finalizes the upgrade of commons-lang's tests to use JUnit Jupiter and remove the Vintage Engine dependency entirely. While most of these changes are drop-in replacements with no functional benefit, there are some non-obvious changes worth mentioning. Unlike org.junit.Assert.assertEquals(double, double, double), org.junit.jupiter.api.Assertions.assertEquals(double, double, double) does not support deltas of zero, only strictly positive deltas. This issue will be addressed in JUnit Jupiter 5.4 (see https://github.com/junit-team/junit5/pull/1613 for details). In the meanwhile, assertTrue(expected==actual) was used, and TODO comments were placed in the code to refactor it to assertEquals once JUnit 5.4 is available. Unlike org.junit.Test, org.junit.jupiter.api.Test does not have an "expected" argument. Instead, an explicit call to org.junit.jupiter.api.Assertions.assertThrows is used. Unlike org.junit.Test, org.junit.jupiter.api.Test does not have a "timeout" argument either. Instead, an explicit call to org.junit.jupiter.api.Assertions.assertTimeoutPreemptively is used. JUnit Jupiter also no longer has the concept of Rules. Usages of the SystemDefaultsSwitch rule and its accompanying annotates were replaced with the @DefaultLocale annotation that Benedikt Ritter contributed to JUnit Pioneer, the semi-official JUnit extension project. Following the removal of their usages, the SystemDefaults annotation, the SystemDefaultsSwitch rule and the SystemDefaultsSwitchTest class that tests them had no more use, and they were removed entirely. It's also worth noting this is a minimal patch for migrating the package's tests to Jupiter. There are several tests that can be made more elegant with Jupiter's new features, but that work is left for subsequent patches.
This commit is contained in:
parent
ca2e59c513
commit
e99b0dde8e
6
pom.xml
6
pom.xml
|
@ -537,12 +537,6 @@
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Vintage engine needed for exectuing JUnit 4.x tests. Remove once all tests have been migrated to JUnit 5. -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit-pioneer</groupId>
|
<groupId>org.junit-pioneer</groupId>
|
||||||
<artifactId>junit-pioneer</artifactId>
|
<artifactId>junit-pioneer</artifactId>
|
||||||
|
|
|
@ -22,23 +22,26 @@ import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.CURLY;
|
||||||
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.LARRY;
|
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.LARRY;
|
||||||
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.MOE;
|
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.MOE;
|
||||||
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.SHEMP;
|
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.SHEMP;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -377,6 +380,17 @@ public class AnnotationUtilsTest {
|
||||||
Stooge[] stooges();
|
Stooge[] stooges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
public @interface TestMethodAnnotation {
|
||||||
|
Class<? extends Throwable> expected() default None.class;
|
||||||
|
|
||||||
|
long timeout() default 0L;
|
||||||
|
|
||||||
|
class None extends Throwable {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum Stooge {
|
public enum Stooge {
|
||||||
MOE, LARRY, CURLY, JOE, SHEMP
|
MOE, LARRY, CURLY, JOE, SHEMP
|
||||||
}
|
}
|
||||||
|
@ -386,7 +400,7 @@ public class AnnotationUtilsTest {
|
||||||
private Field field3;
|
private Field field3;
|
||||||
private Field field4;
|
private Field field4;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
field1 = getClass().getDeclaredField("dummy1");
|
field1 = getClass().getDeclaredField("dummy1");
|
||||||
field2 = getClass().getDeclaredField("dummy2");
|
field2 = getClass().getDeclaredField("dummy2");
|
||||||
|
@ -444,65 +458,73 @@ public class AnnotationUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 666000)
|
@Test
|
||||||
public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
|
public void testGeneratedAnnotationEquivalentToRealAnnotation() {
|
||||||
final Test real = getClass().getDeclaredMethod(
|
assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
|
||||||
"testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
|
final Test real = getClass().getDeclaredMethod(
|
||||||
|
"testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
|
||||||
|
|
||||||
final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
|
final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||||
if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
|
if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
|
||||||
return Boolean.valueOf(proxy == args[0]);
|
return Boolean.valueOf(proxy == args[0]);
|
||||||
|
}
|
||||||
|
if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
|
||||||
|
return Integer.valueOf(System.identityHashCode(proxy));
|
||||||
|
}
|
||||||
|
if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
|
||||||
|
return "Test proxy";
|
||||||
|
}
|
||||||
|
return method.invoke(real, args);
|
||||||
}
|
}
|
||||||
if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
|
};
|
||||||
return Integer.valueOf(System.identityHashCode(proxy));
|
|
||||||
}
|
|
||||||
if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
|
|
||||||
return "Test proxy";
|
|
||||||
}
|
|
||||||
return method.invoke(real, args);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
||||||
.getContextClassLoader(), new Class[] { Test.class },
|
.getContextClassLoader(), new Class[]{Test.class},
|
||||||
generatedTestInvocationHandler);
|
generatedTestInvocationHandler);
|
||||||
assertTrue(real.equals(generated));
|
assertTrue(real.equals(generated));
|
||||||
assertFalse(generated.equals(real));
|
assertFalse(generated.equals(real));
|
||||||
assertTrue(AnnotationUtils.equals(generated, real));
|
assertTrue(AnnotationUtils.equals(generated, real));
|
||||||
assertTrue(AnnotationUtils.equals(real, generated));
|
assertTrue(AnnotationUtils.equals(real, generated));
|
||||||
|
|
||||||
final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
||||||
.getContextClassLoader(), new Class[] { Test.class },
|
.getContextClassLoader(), new Class[]{Test.class},
|
||||||
generatedTestInvocationHandler);
|
generatedTestInvocationHandler);
|
||||||
assertFalse(generated.equals(generated2));
|
assertFalse(generated.equals(generated2));
|
||||||
assertFalse(generated2.equals(generated));
|
assertFalse(generated2.equals(generated));
|
||||||
assertTrue(AnnotationUtils.equals(generated, generated2));
|
assertTrue(AnnotationUtils.equals(generated, generated2));
|
||||||
assertTrue(AnnotationUtils.equals(generated2, generated));
|
assertTrue(AnnotationUtils.equals(generated2, generated));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 666000)
|
@Test
|
||||||
public void testHashCode() throws Exception {
|
public void testHashCode() {
|
||||||
final Test test = getClass().getDeclaredMethod("testHashCode").getAnnotation(Test.class);
|
assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
|
||||||
assertEquals(test.hashCode(), AnnotationUtils.hashCode(test));
|
final Test test = getClass().getDeclaredMethod("testHashCode").getAnnotation(Test.class);
|
||||||
final TestAnnotation testAnnotation1 = field1.getAnnotation(TestAnnotation.class);
|
assertEquals(test.hashCode(), AnnotationUtils.hashCode(test));
|
||||||
assertEquals(testAnnotation1.hashCode(), AnnotationUtils.hashCode(testAnnotation1));
|
final TestAnnotation testAnnotation1 = field1.getAnnotation(TestAnnotation.class);
|
||||||
final TestAnnotation testAnnotation3 = field3.getAnnotation(TestAnnotation.class);
|
assertEquals(testAnnotation1.hashCode(), AnnotationUtils.hashCode(testAnnotation1));
|
||||||
assertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3));
|
final TestAnnotation testAnnotation3 = field3.getAnnotation(TestAnnotation.class);
|
||||||
|
assertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 666000)
|
@Test
|
||||||
public void testToString() throws Exception {
|
@TestMethodAnnotation(timeout = 666000)
|
||||||
final Test testAnnotation = getClass().getDeclaredMethod("testToString")
|
public void testToString() {
|
||||||
.getAnnotation(Test.class);
|
assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
|
||||||
final String annotationString = AnnotationUtils.toString(testAnnotation);
|
final TestMethodAnnotation testAnnotation =
|
||||||
assertTrue(annotationString.startsWith("@org.junit.Test("));
|
getClass().getDeclaredMethod("testToString").getAnnotation(TestMethodAnnotation.class);
|
||||||
assertTrue(annotationString.endsWith(")"));
|
|
||||||
assertTrue(annotationString.contains("expected=class org.junit.Test$None"));
|
final String annotationString = AnnotationUtils.toString(testAnnotation);
|
||||||
assertTrue(annotationString.contains("timeout=666000"));
|
assertTrue(annotationString.startsWith("@org.apache.commons.lang3.AnnotationUtilsTest$TestMethodAnnotation("));
|
||||||
assertTrue(annotationString.contains(", "));
|
assertTrue(annotationString.endsWith(")"));
|
||||||
|
assertTrue(annotationString.contains("expected=class org.apache.commons.lang3.AnnotationUtilsTest$TestMethodAnnotation$None"));
|
||||||
|
assertTrue(annotationString.contains("timeout=666000"));
|
||||||
|
assertTrue(annotationString.contains(", "));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import org.apache.commons.lang3.arch.Processor;
|
import org.apache.commons.lang3.arch.Processor;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link ArchUtils}.
|
* Test class for {@link ArchUtils}.
|
||||||
|
|
|
@ -17,16 +17,16 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests ArrayUtils add methods.
|
* Tests ArrayUtils add methods.
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests ArrayUtils insert methods.
|
* Tests ArrayUtils insert methods.
|
||||||
|
|
|
@ -17,15 +17,16 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests ArrayUtils remove and removeElement methods.
|
* Tests ArrayUtils remove and removeElement methods.
|
||||||
|
@ -90,19 +91,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(Object.class, array2.getClass().getComponentType());
|
assertEquals(Object.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllObjectArrayNegativeIndex() {
|
public void testRemoveAllObjectArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new Object[] { "a", "b" }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new Object[] { "a", "b" }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllObjectArrayOutOfBoundsIndex() {
|
public void testRemoveAllObjectArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new Object[] { "a", "b" }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new Object[] { "a", "b" }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullObjectArray() {
|
public void testRemoveAllNullObjectArray() {
|
||||||
ArrayUtils.remove((Object[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((Object[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -206,19 +207,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(boolean.class, array2.getClass().getComponentType());
|
assertEquals(boolean.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllBooleanArrayNegativeIndex() {
|
public void testRemoveAllBooleanArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new boolean[] { true, false }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new boolean[] { true, false }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllBooleanArrayOutOfBoundsIndex() {
|
public void testRemoveAllBooleanArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new boolean[] { true, false }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new boolean[] { true, false }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullBooleanArray() {
|
public void testRemoveAllNullBooleanArray() {
|
||||||
ArrayUtils.removeAll((boolean[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((boolean[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -283,19 +284,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(byte.class, array2.getClass().getComponentType());
|
assertEquals(byte.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllByteArrayNegativeIndex() {
|
public void testRemoveAllByteArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new byte[] { 1, 2 }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new byte[] { 1, 2 }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllByteArrayOutOfBoundsIndex() {
|
public void testRemoveAllByteArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new byte[] { 1, 2 }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new byte[] { 1, 2 }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullByteArray() {
|
public void testRemoveAllNullByteArray() {
|
||||||
ArrayUtils.removeAll((byte[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((byte[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -360,19 +361,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(char.class, array2.getClass().getComponentType());
|
assertEquals(char.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllCharArrayNegativeIndex() {
|
public void testRemoveAllCharArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new char[] { 'a', 'b' }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new char[] { 'a', 'b' }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllCharArrayOutOfBoundsIndex() {
|
public void testRemoveAllCharArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new char[] { 'a', 'b' }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new char[] { 'a', 'b' }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullCharArray() {
|
public void testRemoveAllNullCharArray() {
|
||||||
ArrayUtils.removeAll((char[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((char[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -437,19 +438,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(double.class, array2.getClass().getComponentType());
|
assertEquals(double.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllDoubleArrayNegativeIndex() {
|
public void testRemoveAllDoubleArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new double[] { 1, 2 }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new double[] { 1, 2 }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllDoubleArrayOutOfBoundsIndex() {
|
public void testRemoveAllDoubleArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new double[] { 1, 2 }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new double[] { 1, 2 }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullDoubleArray() {
|
public void testRemoveAllNullDoubleArray() {
|
||||||
ArrayUtils.removeAll((double[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((double[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -514,19 +515,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(float.class, array2.getClass().getComponentType());
|
assertEquals(float.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllFloatArrayNegativeIndex() {
|
public void testRemoveAllFloatArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new float[] { 1, 2 }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new float[] { 1, 2 }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllFloatArrayOutOfBoundsIndex() {
|
public void testRemoveAllFloatArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new float[] { 1, 2 }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new float[] { 1, 2 }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullFloatArray() {
|
public void testRemoveAllNullFloatArray() {
|
||||||
ArrayUtils.removeAll((float[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((float[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -597,19 +598,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(int.class, array2.getClass().getComponentType());
|
assertEquals(int.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllIntArrayNegativeIndex() {
|
public void testRemoveAllIntArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new int[] { 1, 2 }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new int[] { 1, 2 }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllIntArrayOutOfBoundsIndex() {
|
public void testRemoveAllIntArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new int[] { 1, 2 }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new int[] { 1, 2 }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullIntArray() {
|
public void testRemoveAllNullIntArray() {
|
||||||
ArrayUtils.removeAll((int[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((int[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -674,19 +675,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(long.class, array2.getClass().getComponentType());
|
assertEquals(long.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllLongArrayNegativeIndex() {
|
public void testRemoveAllLongArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new long[] { 1, 2 }, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new long[] { 1, 2 }, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllLongArrayOutOfBoundsIndex() {
|
public void testRemoveAllLongArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new long[] { 1, 2 }, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new long[] { 1, 2 }, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullLongArray() {
|
public void testRemoveAllNullLongArray() {
|
||||||
ArrayUtils.removeAll((long[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((long[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -751,19 +752,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
||||||
assertEquals(short.class, array2.getClass().getComponentType());
|
assertEquals(short.class, array2.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllShortArrayNegativeIndex() {
|
public void testRemoveAllShortArrayNegativeIndex() {
|
||||||
ArrayUtils.removeAll(new short[] { 1, 2 }, -1, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new short[] { 1, 2 }, -1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllShortArrayOutOfBoundsIndex() {
|
public void testRemoveAllShortArrayOutOfBoundsIndex() {
|
||||||
ArrayUtils.removeAll(new short[] { 1, 2 }, 2, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll(new short[] { 1, 2 }, 2, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testRemoveAllNullShortArray() {
|
public void testRemoveAllNullShortArray() {
|
||||||
ArrayUtils.removeAll((short[]) null, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((short[]) null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests ArrayUtils remove and removeElement methods.
|
* Tests ArrayUtils remove and removeElement methods.
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,11 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test BitField functionality
|
* Class to test BitField functionality
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,11 +17,11 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
public class CharEncodingTest {
|
public class CharEncodingTest {
|
||||||
|
|
||||||
private void assertSupportedEncoding(final String name) {
|
private void assertSupportedEncoding(final String name) {
|
||||||
assertTrue("Encoding should be supported: " + name, CharEncoding.isSupported(name));
|
assertTrue(CharEncoding.isSupported(name), "Encoding should be supported: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,17 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.CharRange}.
|
* Unit tests {@link org.apache.commons.lang3.CharRange}.
|
||||||
|
@ -398,10 +399,10 @@ public class CharRangeTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test
|
||||||
public void testIteratorRemove() {
|
public void testIteratorRemove() {
|
||||||
final CharRange a = CharRange.is('a');
|
final CharRange a = CharRange.is('a');
|
||||||
final Iterator<Character> aIt = a.iterator();
|
final Iterator<Character> aIt = a.iterator();
|
||||||
aIt.remove();
|
assertThrows(UnsupportedOperationException.class, aIt::remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests CharSequenceUtils
|
* Tests CharSequenceUtils
|
||||||
|
@ -64,14 +65,14 @@ public class CharSequenceUtilsTest {
|
||||||
assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3));
|
assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testSubSequenceNegativeStart() {
|
public void testSubSequenceNegativeStart() {
|
||||||
assertNull(CharSequenceUtils.subSequence(StringUtils.EMPTY, -1));
|
assertThrows(IndexOutOfBoundsException.class, () -> CharSequenceUtils.subSequence(StringUtils.EMPTY, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testSubSequenceTooLong() {
|
public void testSubSequenceTooLong() {
|
||||||
assertNull(CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
|
assertThrows(IndexOutOfBoundsException.class, () -> CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestData{
|
static class TestData{
|
||||||
|
@ -154,7 +155,7 @@ public class CharSequenceUtilsTest {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final boolean stringCheck = invoke();
|
final boolean stringCheck = invoke();
|
||||||
assertEquals(id + " Failed test " + data, data.expected, stringCheck);
|
assertEquals(data.expected, stringCheck, id + " Failed test " + data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.CharSet}.
|
* Unit tests {@link org.apache.commons.lang3.CharSet}.
|
||||||
|
|
|
@ -16,16 +16,16 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.CharSetUtils}.
|
* Unit tests {@link org.apache.commons.lang3.CharSetUtils}.
|
||||||
|
|
|
@ -16,18 +16,18 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.CharUtils}.
|
* Unit tests {@link org.apache.commons.lang3.CharUtils}.
|
||||||
|
|
|
@ -16,15 +16,16 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -40,14 +41,15 @@ public class ClassPathUtilsTest {
|
||||||
assertFalse(Modifier.isFinal(ClassPathUtils.class.getModifiers()));
|
assertFalse(Modifier.isFinal(ClassPathUtils.class.getModifiers()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedNameNullClassString() throws Exception {
|
public void testToFullyQualifiedNameNullClassString() {
|
||||||
ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties");
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedNameClassNull() throws Exception {
|
public void testToFullyQualifiedNameClassNull() {
|
||||||
ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, null);
|
assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -58,14 +60,16 @@ public class ClassPathUtilsTest {
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedNameNullPackageString() throws Exception {
|
public void testToFullyQualifiedNameNullPackageString() {
|
||||||
ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties");
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedNamePackageNull() throws Exception {
|
public void testToFullyQualifiedNamePackageNull() {
|
||||||
ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null);
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -76,14 +80,15 @@ public class ClassPathUtilsTest {
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedPathClassNullString() throws Exception {
|
public void testToFullyQualifiedPathClassNullString() {
|
||||||
ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties");
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedPathClassNull() throws Exception {
|
public void testToFullyQualifiedPathClassNull() {
|
||||||
ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, null);
|
assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -94,14 +99,16 @@ public class ClassPathUtilsTest {
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedPathPackageNullString() throws Exception {
|
public void testToFullyQualifiedPathPackageNullString() {
|
||||||
ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties");
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testToFullyQualifiedPathPackageNull() throws Exception {
|
public void testToFullyQualifiedPathPackageNull() {
|
||||||
ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null);
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,15 +16,16 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -42,7 +43,7 @@ import org.apache.commons.lang3.ClassUtils.Interfaces;
|
||||||
import org.apache.commons.lang3.reflect.testbed.GenericConsumer;
|
import org.apache.commons.lang3.reflect.testbed.GenericConsumer;
|
||||||
import org.apache.commons.lang3.reflect.testbed.GenericParent;
|
import org.apache.commons.lang3.reflect.testbed.GenericParent;
|
||||||
import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
|
import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.ClassUtils}.
|
* Unit tests {@link org.apache.commons.lang3.ClassUtils}.
|
||||||
|
@ -175,14 +176,14 @@ public class ClassUtilsTest {
|
||||||
assertEquals("java.lang.String", ClassUtils.getAbbreviatedName(String.class, 20));
|
assertEquals("java.lang.String", ClassUtils.getAbbreviatedName(String.class, 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void test_getAbbreviatedName_Class_NegativeLen() {
|
public void test_getAbbreviatedName_Class_NegativeLen() {
|
||||||
ClassUtils.getAbbreviatedName(String.class, -10);
|
assertThrows(IllegalArgumentException.class, () -> ClassUtils.getAbbreviatedName(String.class, -10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void test_getAbbreviatedName_Class_ZeroLen() {
|
public void test_getAbbreviatedName_Class_ZeroLen() {
|
||||||
ClassUtils.getAbbreviatedName(String.class, 0);
|
assertThrows(IllegalArgumentException.class, () -> ClassUtils.getAbbreviatedName(String.class, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -813,84 +814,84 @@ public class ClassUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
|
public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
|
||||||
// test byte conversions
|
// test byte conversions
|
||||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Byte.class, Character.TYPE), "byte -> char");
|
||||||
assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.class, Byte.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Byte.TYPE), "byte -> byte");
|
||||||
assertTrue("byte -> short", ClassUtils.isAssignable(Byte.class, Short.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Short.TYPE), "byte -> short");
|
||||||
assertTrue("byte -> int", ClassUtils.isAssignable(Byte.class, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Integer.TYPE), "byte -> int");
|
||||||
assertTrue("byte -> long", ClassUtils.isAssignable(Byte.class, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Long.TYPE), "byte -> long");
|
||||||
assertTrue("byte -> float", ClassUtils.isAssignable(Byte.class, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Float.TYPE), "byte -> float");
|
||||||
assertTrue("byte -> double", ClassUtils.isAssignable(Byte.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Double.TYPE), "byte -> double");
|
||||||
assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Byte.class, Boolean.TYPE), "byte -> boolean");
|
||||||
|
|
||||||
// test short conversions
|
// test short conversions
|
||||||
assertFalse("short -> char", ClassUtils.isAssignable(Short.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Short.class, Character.TYPE), "short -> char");
|
||||||
assertFalse("short -> byte", ClassUtils.isAssignable(Short.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Short.class, Byte.TYPE), "short -> byte");
|
||||||
assertTrue("short -> short", ClassUtils.isAssignable(Short.class, Short.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.class, Short.TYPE), "short -> short");
|
||||||
assertTrue("short -> int", ClassUtils.isAssignable(Short.class, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.class, Integer.TYPE), "short -> int");
|
||||||
assertTrue("short -> long", ClassUtils.isAssignable(Short.class, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.class, Long.TYPE), "short -> long");
|
||||||
assertTrue("short -> float", ClassUtils.isAssignable(Short.class, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.class, Float.TYPE), "short -> float");
|
||||||
assertTrue("short -> double", ClassUtils.isAssignable(Short.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.class, Double.TYPE), "short -> double");
|
||||||
assertFalse("short -> boolean", ClassUtils.isAssignable(Short.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Short.class, Boolean.TYPE), "short -> boolean");
|
||||||
|
|
||||||
// test char conversions
|
// test char conversions
|
||||||
assertTrue("char -> char", ClassUtils.isAssignable(Character.class, Character.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.class, Character.TYPE), "char -> char");
|
||||||
assertFalse("char -> byte", ClassUtils.isAssignable(Character.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Character.class, Byte.TYPE), "char -> byte");
|
||||||
assertFalse("char -> short", ClassUtils.isAssignable(Character.class, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Character.class, Short.TYPE), "char -> short");
|
||||||
assertTrue("char -> int", ClassUtils.isAssignable(Character.class, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.class, Integer.TYPE), "char -> int");
|
||||||
assertTrue("char -> long", ClassUtils.isAssignable(Character.class, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.class, Long.TYPE), "char -> long");
|
||||||
assertTrue("char -> float", ClassUtils.isAssignable(Character.class, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.class, Float.TYPE), "char -> float");
|
||||||
assertTrue("char -> double", ClassUtils.isAssignable(Character.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.class, Double.TYPE), "char -> double");
|
||||||
assertFalse("char -> boolean", ClassUtils.isAssignable(Character.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Character.class, Boolean.TYPE), "char -> boolean");
|
||||||
|
|
||||||
// test int conversions
|
// test int conversions
|
||||||
assertFalse("int -> char", ClassUtils.isAssignable(Integer.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Character.TYPE), "int -> char");
|
||||||
assertFalse("int -> byte", ClassUtils.isAssignable(Integer.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Byte.TYPE), "int -> byte");
|
||||||
assertFalse("int -> short", ClassUtils.isAssignable(Integer.class, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Short.TYPE), "int -> short");
|
||||||
assertTrue("int -> int", ClassUtils.isAssignable(Integer.class, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Integer.TYPE), "int -> int");
|
||||||
assertTrue("int -> long", ClassUtils.isAssignable(Integer.class, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Long.TYPE), "int -> long");
|
||||||
assertTrue("int -> float", ClassUtils.isAssignable(Integer.class, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Float.TYPE), "int -> float");
|
||||||
assertTrue("int -> double", ClassUtils.isAssignable(Integer.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Double.TYPE), "int -> double");
|
||||||
assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Boolean.TYPE), "int -> boolean");
|
||||||
|
|
||||||
// test long conversions
|
// test long conversions
|
||||||
assertFalse("long -> char", ClassUtils.isAssignable(Long.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.class, Character.TYPE), "long -> char");
|
||||||
assertFalse("long -> byte", ClassUtils.isAssignable(Long.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.class, Byte.TYPE), "long -> byte");
|
||||||
assertFalse("long -> short", ClassUtils.isAssignable(Long.class, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.class, Short.TYPE), "long -> short");
|
||||||
assertFalse("long -> int", ClassUtils.isAssignable(Long.class, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.class, Integer.TYPE), "long -> int");
|
||||||
assertTrue("long -> long", ClassUtils.isAssignable(Long.class, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Long.class, Long.TYPE), "long -> long");
|
||||||
assertTrue("long -> float", ClassUtils.isAssignable(Long.class, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Long.class, Float.TYPE), "long -> float");
|
||||||
assertTrue("long -> double", ClassUtils.isAssignable(Long.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Long.class, Double.TYPE), "long -> double");
|
||||||
assertFalse("long -> boolean", ClassUtils.isAssignable(Long.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.class, Boolean.TYPE), "long -> boolean");
|
||||||
|
|
||||||
// test float conversions
|
// test float conversions
|
||||||
assertFalse("float -> char", ClassUtils.isAssignable(Float.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.class, Character.TYPE), "float -> char");
|
||||||
assertFalse("float -> byte", ClassUtils.isAssignable(Float.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.class, Byte.TYPE), "float -> byte");
|
||||||
assertFalse("float -> short", ClassUtils.isAssignable(Float.class, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.class, Short.TYPE), "float -> short");
|
||||||
assertFalse("float -> int", ClassUtils.isAssignable(Float.class, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.class, Integer.TYPE), "float -> int");
|
||||||
assertFalse("float -> long", ClassUtils.isAssignable(Float.class, Long.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.class, Long.TYPE), "float -> long");
|
||||||
assertTrue("float -> float", ClassUtils.isAssignable(Float.class, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Float.class, Float.TYPE), "float -> float");
|
||||||
assertTrue("float -> double", ClassUtils.isAssignable(Float.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Float.class, Double.TYPE), "float -> double");
|
||||||
assertFalse("float -> boolean", ClassUtils.isAssignable(Float.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.class, Boolean.TYPE), "float -> boolean");
|
||||||
|
|
||||||
// test double conversions
|
// test double conversions
|
||||||
assertFalse("double -> char", ClassUtils.isAssignable(Double.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Character.TYPE), "double -> char");
|
||||||
assertFalse("double -> byte", ClassUtils.isAssignable(Double.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Byte.TYPE), "double -> byte");
|
||||||
assertFalse("double -> short", ClassUtils.isAssignable(Double.class, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Short.TYPE), "double -> short");
|
||||||
assertFalse("double -> int", ClassUtils.isAssignable(Double.class, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Integer.TYPE), "double -> int");
|
||||||
assertFalse("double -> long", ClassUtils.isAssignable(Double.class, Long.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Long.TYPE), "double -> long");
|
||||||
assertFalse("double -> float", ClassUtils.isAssignable(Double.class, Float.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Float.TYPE), "double -> float");
|
||||||
assertTrue("double -> double", ClassUtils.isAssignable(Double.class, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Double.class, Double.TYPE), "double -> double");
|
||||||
assertFalse("double -> boolean", ClassUtils.isAssignable(Double.class, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.class, Boolean.TYPE), "double -> boolean");
|
||||||
|
|
||||||
// test boolean conversions
|
// test boolean conversions
|
||||||
assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.class, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Character.TYPE), "boolean -> char");
|
||||||
assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.class, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Byte.TYPE), "boolean -> byte");
|
||||||
assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.class, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Short.TYPE), "boolean -> short");
|
||||||
assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.class, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Integer.TYPE), "boolean -> int");
|
||||||
assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.class, Long.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Long.TYPE), "boolean -> long");
|
||||||
assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.class, Float.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Float.TYPE), "boolean -> float");
|
||||||
assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.class, Double.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Double.TYPE), "boolean -> double");
|
||||||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE));
|
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.TYPE), "boolean -> boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -920,167 +921,167 @@ public class ClassUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_isAssignable_Unboxing_Widening() throws Exception {
|
public void test_isAssignable_Unboxing_Widening() throws Exception {
|
||||||
// test byte conversions
|
// test byte conversions
|
||||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Byte.class, Character.TYPE, true), "byte -> char");
|
||||||
assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.class, Byte.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Byte.TYPE, true), "byte -> byte");
|
||||||
assertTrue("byte -> short", ClassUtils.isAssignable(Byte.class, Short.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Short.TYPE, true), "byte -> short");
|
||||||
assertTrue("byte -> int", ClassUtils.isAssignable(Byte.class, Integer.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Integer.TYPE, true), "byte -> int");
|
||||||
assertTrue("byte -> long", ClassUtils.isAssignable(Byte.class, Long.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Long.TYPE, true), "byte -> long");
|
||||||
assertTrue("byte -> float", ClassUtils.isAssignable(Byte.class, Float.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Float.TYPE, true), "byte -> float");
|
||||||
assertTrue("byte -> double", ClassUtils.isAssignable(Byte.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Byte.class, Double.TYPE, true), "byte -> double");
|
||||||
assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Byte.class, Boolean.TYPE, true), "byte -> boolean");
|
||||||
|
|
||||||
// test short conversions
|
// test short conversions
|
||||||
assertFalse("short -> char", ClassUtils.isAssignable(Short.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Short.class, Character.TYPE, true), "short -> char");
|
||||||
assertFalse("short -> byte", ClassUtils.isAssignable(Short.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Short.class, Byte.TYPE, true), "short -> byte");
|
||||||
assertTrue("short -> short", ClassUtils.isAssignable(Short.class, Short.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Short.class, Short.TYPE, true), "short -> short");
|
||||||
assertTrue("short -> int", ClassUtils.isAssignable(Short.class, Integer.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Short.class, Integer.TYPE, true), "short -> int");
|
||||||
assertTrue("short -> long", ClassUtils.isAssignable(Short.class, Long.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Short.class, Long.TYPE, true), "short -> long");
|
||||||
assertTrue("short -> float", ClassUtils.isAssignable(Short.class, Float.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Short.class, Float.TYPE, true), "short -> float");
|
||||||
assertTrue("short -> double", ClassUtils.isAssignable(Short.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Short.class, Double.TYPE, true), "short -> double");
|
||||||
assertFalse("short -> boolean", ClassUtils.isAssignable(Short.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Short.class, Boolean.TYPE, true), "short -> boolean");
|
||||||
|
|
||||||
// test char conversions
|
// test char conversions
|
||||||
assertTrue("char -> char", ClassUtils.isAssignable(Character.class, Character.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Character.class, Character.TYPE, true), "char -> char");
|
||||||
assertFalse("char -> byte", ClassUtils.isAssignable(Character.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Character.class, Byte.TYPE, true), "char -> byte");
|
||||||
assertFalse("char -> short", ClassUtils.isAssignable(Character.class, Short.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Character.class, Short.TYPE, true), "char -> short");
|
||||||
assertTrue("char -> int", ClassUtils.isAssignable(Character.class, Integer.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Character.class, Integer.TYPE, true), "char -> int");
|
||||||
assertTrue("char -> long", ClassUtils.isAssignable(Character.class, Long.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Character.class, Long.TYPE, true), "char -> long");
|
||||||
assertTrue("char -> float", ClassUtils.isAssignable(Character.class, Float.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Character.class, Float.TYPE, true), "char -> float");
|
||||||
assertTrue("char -> double", ClassUtils.isAssignable(Character.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Character.class, Double.TYPE, true), "char -> double");
|
||||||
assertFalse("char -> boolean", ClassUtils.isAssignable(Character.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Character.class, Boolean.TYPE, true), "char -> boolean");
|
||||||
|
|
||||||
// test int conversions
|
// test int conversions
|
||||||
assertFalse("int -> char", ClassUtils.isAssignable(Integer.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Character.TYPE, true), "int -> char");
|
||||||
assertFalse("int -> byte", ClassUtils.isAssignable(Integer.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Byte.TYPE, true), "int -> byte");
|
||||||
assertFalse("int -> short", ClassUtils.isAssignable(Integer.class, Short.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Short.TYPE, true), "int -> short");
|
||||||
assertTrue("int -> int", ClassUtils.isAssignable(Integer.class, Integer.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Integer.TYPE, true), "int -> int");
|
||||||
assertTrue("int -> long", ClassUtils.isAssignable(Integer.class, Long.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Long.TYPE, true), "int -> long");
|
||||||
assertTrue("int -> float", ClassUtils.isAssignable(Integer.class, Float.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Float.TYPE, true), "int -> float");
|
||||||
assertTrue("int -> double", ClassUtils.isAssignable(Integer.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Integer.class, Double.TYPE, true), "int -> double");
|
||||||
assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Integer.class, Boolean.TYPE, true), "int -> boolean");
|
||||||
|
|
||||||
// test long conversions
|
// test long conversions
|
||||||
assertFalse("long -> char", ClassUtils.isAssignable(Long.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Long.class, Character.TYPE, true), "long -> char");
|
||||||
assertFalse("long -> byte", ClassUtils.isAssignable(Long.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Long.class, Byte.TYPE, true), "long -> byte");
|
||||||
assertFalse("long -> short", ClassUtils.isAssignable(Long.class, Short.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Long.class, Short.TYPE, true), "long -> short");
|
||||||
assertFalse("long -> int", ClassUtils.isAssignable(Long.class, Integer.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Long.class, Integer.TYPE, true), "long -> int");
|
||||||
assertTrue("long -> long", ClassUtils.isAssignable(Long.class, Long.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Long.class, Long.TYPE, true), "long -> long");
|
||||||
assertTrue("long -> float", ClassUtils.isAssignable(Long.class, Float.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Long.class, Float.TYPE, true), "long -> float");
|
||||||
assertTrue("long -> double", ClassUtils.isAssignable(Long.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Long.class, Double.TYPE, true), "long -> double");
|
||||||
assertFalse("long -> boolean", ClassUtils.isAssignable(Long.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Long.class, Boolean.TYPE, true), "long -> boolean");
|
||||||
|
|
||||||
// test float conversions
|
// test float conversions
|
||||||
assertFalse("float -> char", ClassUtils.isAssignable(Float.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Float.class, Character.TYPE, true), "float -> char");
|
||||||
assertFalse("float -> byte", ClassUtils.isAssignable(Float.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Float.class, Byte.TYPE, true), "float -> byte");
|
||||||
assertFalse("float -> short", ClassUtils.isAssignable(Float.class, Short.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Float.class, Short.TYPE, true), "float -> short");
|
||||||
assertFalse("float -> int", ClassUtils.isAssignable(Float.class, Integer.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Float.class, Integer.TYPE, true), "float -> int");
|
||||||
assertFalse("float -> long", ClassUtils.isAssignable(Float.class, Long.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Float.class, Long.TYPE, true), "float -> long");
|
||||||
assertTrue("float -> float", ClassUtils.isAssignable(Float.class, Float.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Float.class, Float.TYPE, true), "float -> float");
|
||||||
assertTrue("float -> double", ClassUtils.isAssignable(Float.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Float.class, Double.TYPE, true), "float -> double");
|
||||||
assertFalse("float -> boolean", ClassUtils.isAssignable(Float.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Float.class, Boolean.TYPE, true), "float -> boolean");
|
||||||
|
|
||||||
// test double conversions
|
// test double conversions
|
||||||
assertFalse("double -> char", ClassUtils.isAssignable(Double.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Character.TYPE, true), "double -> char");
|
||||||
assertFalse("double -> byte", ClassUtils.isAssignable(Double.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Byte.TYPE, true), "double -> byte");
|
||||||
assertFalse("double -> short", ClassUtils.isAssignable(Double.class, Short.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Short.TYPE, true), "double -> short");
|
||||||
assertFalse("double -> int", ClassUtils.isAssignable(Double.class, Integer.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Integer.TYPE, true), "double -> int");
|
||||||
assertFalse("double -> long", ClassUtils.isAssignable(Double.class, Long.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Long.TYPE, true), "double -> long");
|
||||||
assertFalse("double -> float", ClassUtils.isAssignable(Double.class, Float.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Float.TYPE, true), "double -> float");
|
||||||
assertTrue("double -> double", ClassUtils.isAssignable(Double.class, Double.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Double.class, Double.TYPE, true), "double -> double");
|
||||||
assertFalse("double -> boolean", ClassUtils.isAssignable(Double.class, Boolean.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Double.class, Boolean.TYPE, true), "double -> boolean");
|
||||||
|
|
||||||
// test boolean conversions
|
// test boolean conversions
|
||||||
assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.class, Character.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Character.TYPE, true), "boolean -> char");
|
||||||
assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.class, Byte.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Byte.TYPE, true), "boolean -> byte");
|
||||||
assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.class, Short.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Short.TYPE, true), "boolean -> short");
|
||||||
assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.class, Integer.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Integer.TYPE, true), "boolean -> int");
|
||||||
assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.class, Long.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Long.TYPE, true), "boolean -> long");
|
||||||
assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.class, Float.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Float.TYPE, true), "boolean -> float");
|
||||||
assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.class, Double.TYPE, true));
|
assertFalse(ClassUtils.isAssignable(Boolean.class, Double.TYPE, true), "boolean -> double");
|
||||||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true));
|
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true), "boolean -> boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_isAssignable_Widening() throws Exception {
|
public void test_isAssignable_Widening() throws Exception {
|
||||||
// test byte conversions
|
// test byte conversions
|
||||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Byte.TYPE, Character.TYPE), "byte -> char");
|
||||||
assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.TYPE, Byte.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Byte.TYPE), "byte -> byte");
|
||||||
assertTrue("byte -> short", ClassUtils.isAssignable(Byte.TYPE, Short.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Short.TYPE), "byte -> short");
|
||||||
assertTrue("byte -> int", ClassUtils.isAssignable(Byte.TYPE, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Integer.TYPE), "byte -> int");
|
||||||
assertTrue("byte -> long", ClassUtils.isAssignable(Byte.TYPE, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Long.TYPE), "byte -> long");
|
||||||
assertTrue("byte -> float", ClassUtils.isAssignable(Byte.TYPE, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Float.TYPE), "byte -> float");
|
||||||
assertTrue("byte -> double", ClassUtils.isAssignable(Byte.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Double.TYPE), "byte -> double");
|
||||||
assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Byte.TYPE, Boolean.TYPE), "byte -> boolean");
|
||||||
|
|
||||||
// test short conversions
|
// test short conversions
|
||||||
assertFalse("short -> char", ClassUtils.isAssignable(Short.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Short.TYPE, Character.TYPE), "short -> char");
|
||||||
assertFalse("short -> byte", ClassUtils.isAssignable(Short.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Short.TYPE, Byte.TYPE), "short -> byte");
|
||||||
assertTrue("short -> short", ClassUtils.isAssignable(Short.TYPE, Short.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.TYPE, Short.TYPE), "short -> short");
|
||||||
assertTrue("short -> int", ClassUtils.isAssignable(Short.TYPE, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.TYPE, Integer.TYPE), "short -> int");
|
||||||
assertTrue("short -> long", ClassUtils.isAssignable(Short.TYPE, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.TYPE, Long.TYPE), "short -> long");
|
||||||
assertTrue("short -> float", ClassUtils.isAssignable(Short.TYPE, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.TYPE, Float.TYPE), "short -> float");
|
||||||
assertTrue("short -> double", ClassUtils.isAssignable(Short.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Short.TYPE, Double.TYPE), "short -> double");
|
||||||
assertFalse("short -> boolean", ClassUtils.isAssignable(Short.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Short.TYPE, Boolean.TYPE), "short -> boolean");
|
||||||
|
|
||||||
// test char conversions
|
// test char conversions
|
||||||
assertTrue("char -> char", ClassUtils.isAssignable(Character.TYPE, Character.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.TYPE, Character.TYPE), "char -> char");
|
||||||
assertFalse("char -> byte", ClassUtils.isAssignable(Character.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Character.TYPE, Byte.TYPE), "char -> byte");
|
||||||
assertFalse("char -> short", ClassUtils.isAssignable(Character.TYPE, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Character.TYPE, Short.TYPE), "char -> short");
|
||||||
assertTrue("char -> int", ClassUtils.isAssignable(Character.TYPE, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.TYPE, Integer.TYPE), "char -> int");
|
||||||
assertTrue("char -> long", ClassUtils.isAssignable(Character.TYPE, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.TYPE, Long.TYPE), "char -> long");
|
||||||
assertTrue("char -> float", ClassUtils.isAssignable(Character.TYPE, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.TYPE, Float.TYPE), "char -> float");
|
||||||
assertTrue("char -> double", ClassUtils.isAssignable(Character.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Character.TYPE, Double.TYPE), "char -> double");
|
||||||
assertFalse("char -> boolean", ClassUtils.isAssignable(Character.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Character.TYPE, Boolean.TYPE), "char -> boolean");
|
||||||
|
|
||||||
// test int conversions
|
// test int conversions
|
||||||
assertFalse("int -> char", ClassUtils.isAssignable(Integer.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Character.TYPE), "int -> char");
|
||||||
assertFalse("int -> byte", ClassUtils.isAssignable(Integer.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Byte.TYPE), "int -> byte");
|
||||||
assertFalse("int -> short", ClassUtils.isAssignable(Integer.TYPE, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Short.TYPE), "int -> short");
|
||||||
assertTrue("int -> int", ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE), "int -> int");
|
||||||
assertTrue("int -> long", ClassUtils.isAssignable(Integer.TYPE, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Long.TYPE), "int -> long");
|
||||||
assertTrue("int -> float", ClassUtils.isAssignable(Integer.TYPE, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Float.TYPE), "int -> float");
|
||||||
assertTrue("int -> double", ClassUtils.isAssignable(Integer.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Double.TYPE), "int -> double");
|
||||||
assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Boolean.TYPE), "int -> boolean");
|
||||||
|
|
||||||
// test long conversions
|
// test long conversions
|
||||||
assertFalse("long -> char", ClassUtils.isAssignable(Long.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.TYPE, Character.TYPE), "long -> char");
|
||||||
assertFalse("long -> byte", ClassUtils.isAssignable(Long.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.TYPE, Byte.TYPE), "long -> byte");
|
||||||
assertFalse("long -> short", ClassUtils.isAssignable(Long.TYPE, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.TYPE, Short.TYPE), "long -> short");
|
||||||
assertFalse("long -> int", ClassUtils.isAssignable(Long.TYPE, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.TYPE, Integer.TYPE), "long -> int");
|
||||||
assertTrue("long -> long", ClassUtils.isAssignable(Long.TYPE, Long.TYPE));
|
assertTrue(ClassUtils.isAssignable(Long.TYPE, Long.TYPE), "long -> long");
|
||||||
assertTrue("long -> float", ClassUtils.isAssignable(Long.TYPE, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Long.TYPE, Float.TYPE), "long -> float");
|
||||||
assertTrue("long -> double", ClassUtils.isAssignable(Long.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Long.TYPE, Double.TYPE), "long -> double");
|
||||||
assertFalse("long -> boolean", ClassUtils.isAssignable(Long.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Long.TYPE, Boolean.TYPE), "long -> boolean");
|
||||||
|
|
||||||
// test float conversions
|
// test float conversions
|
||||||
assertFalse("float -> char", ClassUtils.isAssignable(Float.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.TYPE, Character.TYPE), "float -> char");
|
||||||
assertFalse("float -> byte", ClassUtils.isAssignable(Float.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.TYPE, Byte.TYPE), "float -> byte");
|
||||||
assertFalse("float -> short", ClassUtils.isAssignable(Float.TYPE, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.TYPE, Short.TYPE), "float -> short");
|
||||||
assertFalse("float -> int", ClassUtils.isAssignable(Float.TYPE, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.TYPE, Integer.TYPE), "float -> int");
|
||||||
assertFalse("float -> long", ClassUtils.isAssignable(Float.TYPE, Long.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.TYPE, Long.TYPE), "float -> long");
|
||||||
assertTrue("float -> float", ClassUtils.isAssignable(Float.TYPE, Float.TYPE));
|
assertTrue(ClassUtils.isAssignable(Float.TYPE, Float.TYPE), "float -> float");
|
||||||
assertTrue("float -> double", ClassUtils.isAssignable(Float.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Float.TYPE, Double.TYPE), "float -> double");
|
||||||
assertFalse("float -> boolean", ClassUtils.isAssignable(Float.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Float.TYPE, Boolean.TYPE), "float -> boolean");
|
||||||
|
|
||||||
// test double conversions
|
// test double conversions
|
||||||
assertFalse("double -> char", ClassUtils.isAssignable(Double.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Character.TYPE), "double -> char");
|
||||||
assertFalse("double -> byte", ClassUtils.isAssignable(Double.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Byte.TYPE), "double -> byte");
|
||||||
assertFalse("double -> short", ClassUtils.isAssignable(Double.TYPE, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Short.TYPE), "double -> short");
|
||||||
assertFalse("double -> int", ClassUtils.isAssignable(Double.TYPE, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Integer.TYPE), "double -> int");
|
||||||
assertFalse("double -> long", ClassUtils.isAssignable(Double.TYPE, Long.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Long.TYPE), "double -> long");
|
||||||
assertFalse("double -> float", ClassUtils.isAssignable(Double.TYPE, Float.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Float.TYPE), "double -> float");
|
||||||
assertTrue("double -> double", ClassUtils.isAssignable(Double.TYPE, Double.TYPE));
|
assertTrue(ClassUtils.isAssignable(Double.TYPE, Double.TYPE), "double -> double");
|
||||||
assertFalse("double -> boolean", ClassUtils.isAssignable(Double.TYPE, Boolean.TYPE));
|
assertFalse(ClassUtils.isAssignable(Double.TYPE, Boolean.TYPE), "double -> boolean");
|
||||||
|
|
||||||
// test boolean conversions
|
// test boolean conversions
|
||||||
assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.TYPE, Character.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Character.TYPE), "boolean -> char");
|
||||||
assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.TYPE, Byte.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Byte.TYPE), "boolean -> byte");
|
||||||
assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.TYPE, Short.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Short.TYPE), "boolean -> short");
|
||||||
assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.TYPE, Integer.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Integer.TYPE), "boolean -> int");
|
||||||
assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.TYPE, Long.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Long.TYPE), "boolean -> long");
|
||||||
assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.TYPE, Float.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Float.TYPE), "boolean -> float");
|
||||||
assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.TYPE, Double.TYPE));
|
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Double.TYPE), "boolean -> double");
|
||||||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
|
assertTrue(ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE), "boolean -> boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
@ -1244,76 +1245,76 @@ public class ClassUtilsTest {
|
||||||
public void testIsPrimitiveOrWrapper() {
|
public void testIsPrimitiveOrWrapper() {
|
||||||
|
|
||||||
// test primitive wrapper classes
|
// test primitive wrapper classes
|
||||||
assertTrue("Boolean.class", ClassUtils.isPrimitiveOrWrapper(Boolean.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.class), "Boolean.class");
|
||||||
assertTrue("Byte.class", ClassUtils.isPrimitiveOrWrapper(Byte.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Byte.class), "Byte.class");
|
||||||
assertTrue("Character.class", ClassUtils.isPrimitiveOrWrapper(Character.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Character.class), "Character.class");
|
||||||
assertTrue("Short.class", ClassUtils.isPrimitiveOrWrapper(Short.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Short.class), "Short.class");
|
||||||
assertTrue("Integer.class", ClassUtils.isPrimitiveOrWrapper(Integer.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Integer.class), "Integer.class");
|
||||||
assertTrue("Long.class", ClassUtils.isPrimitiveOrWrapper(Long.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Long.class), "Long.class");
|
||||||
assertTrue("Double.class", ClassUtils.isPrimitiveOrWrapper(Double.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Double.class), "Double.class");
|
||||||
assertTrue("Float.class", ClassUtils.isPrimitiveOrWrapper(Float.class));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Float.class), "Float.class");
|
||||||
|
|
||||||
// test primitive classes
|
// test primitive classes
|
||||||
assertTrue("boolean", ClassUtils.isPrimitiveOrWrapper(Boolean.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.TYPE), "boolean");
|
||||||
assertTrue("byte", ClassUtils.isPrimitiveOrWrapper(Byte.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Byte.TYPE), "byte");
|
||||||
assertTrue("char", ClassUtils.isPrimitiveOrWrapper(Character.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Character.TYPE), "char");
|
||||||
assertTrue("short", ClassUtils.isPrimitiveOrWrapper(Short.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Short.TYPE), "short");
|
||||||
assertTrue("int", ClassUtils.isPrimitiveOrWrapper(Integer.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Integer.TYPE), "int");
|
||||||
assertTrue("long", ClassUtils.isPrimitiveOrWrapper(Long.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Long.TYPE), "long");
|
||||||
assertTrue("double", ClassUtils.isPrimitiveOrWrapper(Double.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Double.TYPE), "double");
|
||||||
assertTrue("float", ClassUtils.isPrimitiveOrWrapper(Float.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Float.TYPE), "float");
|
||||||
assertTrue("Void.TYPE", ClassUtils.isPrimitiveOrWrapper(Void.TYPE));
|
assertTrue(ClassUtils.isPrimitiveOrWrapper(Void.TYPE), "Void.TYPE");
|
||||||
|
|
||||||
// others
|
// others
|
||||||
assertFalse("null", ClassUtils.isPrimitiveOrWrapper(null));
|
assertFalse(ClassUtils.isPrimitiveOrWrapper(null), "null");
|
||||||
assertFalse("Void.class", ClassUtils.isPrimitiveOrWrapper(Void.class));
|
assertFalse(ClassUtils.isPrimitiveOrWrapper(Void.class), "Void.class");
|
||||||
assertFalse("String.class", ClassUtils.isPrimitiveOrWrapper(String.class));
|
assertFalse(ClassUtils.isPrimitiveOrWrapper(String.class), "String.class");
|
||||||
assertFalse("this.getClass()", ClassUtils.isPrimitiveOrWrapper(this.getClass()));
|
assertFalse(ClassUtils.isPrimitiveOrWrapper(this.getClass()), "this.getClass()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsPrimitiveWrapper() {
|
public void testIsPrimitiveWrapper() {
|
||||||
|
|
||||||
// test primitive wrapper classes
|
// test primitive wrapper classes
|
||||||
assertTrue("Boolean.class", ClassUtils.isPrimitiveWrapper(Boolean.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Boolean.class), "Boolean.class");
|
||||||
assertTrue("Byte.class", ClassUtils.isPrimitiveWrapper(Byte.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Byte.class), "Byte.class");
|
||||||
assertTrue("Character.class", ClassUtils.isPrimitiveWrapper(Character.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Character.class), "Character.class");
|
||||||
assertTrue("Short.class", ClassUtils.isPrimitiveWrapper(Short.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Short.class), "Short.class");
|
||||||
assertTrue("Integer.class", ClassUtils.isPrimitiveWrapper(Integer.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Integer.class), "Integer.class");
|
||||||
assertTrue("Long.class", ClassUtils.isPrimitiveWrapper(Long.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Long.class), "Long.class");
|
||||||
assertTrue("Double.class", ClassUtils.isPrimitiveWrapper(Double.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Double.class), "Double.class");
|
||||||
assertTrue("Float.class", ClassUtils.isPrimitiveWrapper(Float.class));
|
assertTrue(ClassUtils.isPrimitiveWrapper(Float.class), "Float.class");
|
||||||
|
|
||||||
// test primitive classes
|
// test primitive classes
|
||||||
assertFalse("boolean", ClassUtils.isPrimitiveWrapper(Boolean.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Boolean.TYPE), "boolean");
|
||||||
assertFalse("byte", ClassUtils.isPrimitiveWrapper(Byte.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Byte.TYPE), "byte");
|
||||||
assertFalse("char", ClassUtils.isPrimitiveWrapper(Character.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Character.TYPE), "char");
|
||||||
assertFalse("short", ClassUtils.isPrimitiveWrapper(Short.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Short.TYPE), "short");
|
||||||
assertFalse("int", ClassUtils.isPrimitiveWrapper(Integer.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Integer.TYPE), "int");
|
||||||
assertFalse("long", ClassUtils.isPrimitiveWrapper(Long.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Long.TYPE), "long");
|
||||||
assertFalse("double", ClassUtils.isPrimitiveWrapper(Double.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Double.TYPE), "double");
|
||||||
assertFalse("float", ClassUtils.isPrimitiveWrapper(Float.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Float.TYPE), "float");
|
||||||
|
|
||||||
// others
|
// others
|
||||||
assertFalse("null", ClassUtils.isPrimitiveWrapper(null));
|
assertFalse(ClassUtils.isPrimitiveWrapper(null), "null");
|
||||||
assertFalse("Void.class", ClassUtils.isPrimitiveWrapper(Void.class));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Void.class), "Void.class");
|
||||||
assertFalse("Void.TYPE", ClassUtils.isPrimitiveWrapper(Void.TYPE));
|
assertFalse(ClassUtils.isPrimitiveWrapper(Void.TYPE), "Void.TYPE");
|
||||||
assertFalse("String.class", ClassUtils.isPrimitiveWrapper(String.class));
|
assertFalse(ClassUtils.isPrimitiveWrapper(String.class), "String.class");
|
||||||
assertFalse("this.getClass()", ClassUtils.isPrimitiveWrapper(this.getClass()));
|
assertFalse(ClassUtils.isPrimitiveWrapper(this.getClass()), "this.getClass()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrimitivesToWrappers() {
|
public void testPrimitivesToWrappers() {
|
||||||
// test null
|
// test null
|
||||||
// assertNull("null -> null", ClassUtils.primitivesToWrappers(null)); // generates warning
|
// assertNull("null -> null", ClassUtils.primitivesToWrappers(null)); // generates warning
|
||||||
assertNull("null -> null", ClassUtils.primitivesToWrappers((Class<?>[]) null)); // equivalent cast to avoid warning
|
assertNull(ClassUtils.primitivesToWrappers((Class<?>[]) null), "null -> null"); // equivalent cast to avoid warning
|
||||||
// Other possible casts for null
|
// Other possible casts for null
|
||||||
assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers()));
|
assertTrue(Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers()), "empty -> empty");
|
||||||
final Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>)null); // == new Class<?>[]{null}
|
final Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>)null); // == new Class<?>[]{null}
|
||||||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
assertTrue(Arrays.equals(new Class<?>[]{null}, castNull), "(Class<?>)null -> [null]");
|
||||||
// test empty array is returned unchanged
|
// test empty array is returned unchanged
|
||||||
assertArrayEquals("empty -> empty",
|
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY),
|
||||||
ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY));
|
"empty -> empty");
|
||||||
|
|
||||||
// test an array of various classes
|
// test an array of various classes
|
||||||
final Class<?>[] primitives = new Class[] {
|
final Class<?>[] primitives = new Class[] {
|
||||||
|
@ -1328,7 +1329,7 @@ public class ClassUtilsTest {
|
||||||
final Class<?> primitive = primitives[i];
|
final Class<?> primitive = primitives[i];
|
||||||
final Class<?> expectedWrapper = ClassUtils.primitiveToWrapper(primitive);
|
final Class<?> expectedWrapper = ClassUtils.primitiveToWrapper(primitive);
|
||||||
|
|
||||||
assertEquals(primitive + " -> " + expectedWrapper, expectedWrapper, wrappers[i]);
|
assertEquals(expectedWrapper, wrappers[i], primitive + " -> " + expectedWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test an array of no primitive classes
|
// test an array of no primitive classes
|
||||||
|
@ -1336,42 +1337,30 @@ public class ClassUtilsTest {
|
||||||
String.class, ClassUtils.class, Void.TYPE
|
String.class, ClassUtils.class, Void.TYPE
|
||||||
};
|
};
|
||||||
// This used to return the exact same array, but no longer does.
|
// This used to return the exact same array, but no longer does.
|
||||||
assertNotSame("unmodified", noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives));
|
assertNotSame(noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives), "unmodified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrimitiveToWrapper() {
|
public void testPrimitiveToWrapper() {
|
||||||
|
|
||||||
// test primitive classes
|
// test primitive classes
|
||||||
assertEquals("boolean -> Boolean.class",
|
assertEquals(Boolean.class, ClassUtils.primitiveToWrapper(Boolean.TYPE), "boolean -> Boolean.class");
|
||||||
Boolean.class, ClassUtils.primitiveToWrapper(Boolean.TYPE));
|
assertEquals(Byte.class, ClassUtils.primitiveToWrapper(Byte.TYPE), "byte -> Byte.class");
|
||||||
assertEquals("byte -> Byte.class",
|
assertEquals(Character.class, ClassUtils.primitiveToWrapper(Character.TYPE), "char -> Character.class");
|
||||||
Byte.class, ClassUtils.primitiveToWrapper(Byte.TYPE));
|
assertEquals(Short.class, ClassUtils.primitiveToWrapper(Short.TYPE), "short -> Short.class");
|
||||||
assertEquals("char -> Character.class",
|
assertEquals(Integer.class, ClassUtils.primitiveToWrapper(Integer.TYPE), "int -> Integer.class");
|
||||||
Character.class, ClassUtils.primitiveToWrapper(Character.TYPE));
|
assertEquals(Long.class, ClassUtils.primitiveToWrapper(Long.TYPE), "long -> Long.class");
|
||||||
assertEquals("short -> Short.class",
|
assertEquals(Double.class, ClassUtils.primitiveToWrapper(Double.TYPE), "double -> Double.class");
|
||||||
Short.class, ClassUtils.primitiveToWrapper(Short.TYPE));
|
assertEquals(Float.class, ClassUtils.primitiveToWrapper(Float.TYPE), "float -> Float.class");
|
||||||
assertEquals("int -> Integer.class",
|
|
||||||
Integer.class, ClassUtils.primitiveToWrapper(Integer.TYPE));
|
|
||||||
assertEquals("long -> Long.class",
|
|
||||||
Long.class, ClassUtils.primitiveToWrapper(Long.TYPE));
|
|
||||||
assertEquals("double -> Double.class",
|
|
||||||
Double.class, ClassUtils.primitiveToWrapper(Double.TYPE));
|
|
||||||
assertEquals("float -> Float.class",
|
|
||||||
Float.class, ClassUtils.primitiveToWrapper(Float.TYPE));
|
|
||||||
|
|
||||||
// test a few other classes
|
// test a few other classes
|
||||||
assertEquals("String.class -> String.class",
|
assertEquals(String.class, ClassUtils.primitiveToWrapper(String.class), "String.class -> String.class");
|
||||||
String.class, ClassUtils.primitiveToWrapper(String.class));
|
assertEquals(ClassUtils.class, ClassUtils.primitiveToWrapper(ClassUtils.class),
|
||||||
assertEquals("ClassUtils.class -> ClassUtils.class",
|
"ClassUtils.class -> ClassUtils.class");
|
||||||
org.apache.commons.lang3.ClassUtils.class,
|
assertEquals(Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE), "Void.TYPE -> Void.TYPE");
|
||||||
ClassUtils.primitiveToWrapper(org.apache.commons.lang3.ClassUtils.class));
|
|
||||||
assertEquals("Void.TYPE -> Void.TYPE",
|
|
||||||
Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE));
|
|
||||||
|
|
||||||
// test null
|
// test null
|
||||||
assertNull("null -> null",
|
assertNull(ClassUtils.primitiveToWrapper(null), "null -> null");
|
||||||
ClassUtils.primitiveToWrapper(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957
|
// Show the Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957
|
||||||
|
@ -1395,9 +1384,9 @@ public class ClassUtilsTest {
|
||||||
assertNull(ClassUtils.toClass((Object[]) null)); // equivalent explicit cast
|
assertNull(ClassUtils.toClass((Object[]) null)); // equivalent explicit cast
|
||||||
|
|
||||||
// Additional varargs tests
|
// Additional varargs tests
|
||||||
assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass()));
|
assertTrue(Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass()), "empty -> empty");
|
||||||
final Class<?>[] castNull = ClassUtils.toClass((Object) null); // == new Object[]{null}
|
final Class<?>[] castNull = ClassUtils.toClass((Object) null); // == new Object[]{null}
|
||||||
assertTrue("(Object)null -> [null]", Arrays.equals(new Object[]{null}, castNull));
|
assertTrue(Arrays.equals(new Object[]{null}, castNull), "(Object)null -> [null]");
|
||||||
|
|
||||||
assertSame(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(ArrayUtils.EMPTY_OBJECT_ARRAY));
|
assertSame(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(ArrayUtils.EMPTY_OBJECT_ARRAY));
|
||||||
|
|
||||||
|
@ -1427,28 +1416,27 @@ public class ClassUtilsTest {
|
||||||
|
|
||||||
final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
|
final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
|
||||||
// now test the result
|
// now test the result
|
||||||
assertEquals("Wrong length of result array", classes.length, primitives.length);
|
assertEquals(classes.length, primitives.length, "Wrong length of result array");
|
||||||
for (int i = 0; i < classes.length; i++) {
|
for (int i = 0; i < classes.length; i++) {
|
||||||
final Class<?> expectedPrimitive = ClassUtils.wrapperToPrimitive(classes[i]);
|
final Class<?> expectedPrimitive = ClassUtils.wrapperToPrimitive(classes[i]);
|
||||||
assertEquals(classes[i] + " -> " + expectedPrimitive, expectedPrimitive,
|
assertEquals(expectedPrimitive, primitives[i], classes[i] + " -> " + expectedPrimitive);
|
||||||
primitives[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrappersToPrimitivesEmpty() {
|
public void testWrappersToPrimitivesEmpty() {
|
||||||
final Class<?>[] empty = new Class[0];
|
final Class<?>[] empty = new Class[0];
|
||||||
assertArrayEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
|
assertArrayEquals(empty, ClassUtils.wrappersToPrimitives(empty), "Wrong result for empty input");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrappersToPrimitivesNull() {
|
public void testWrappersToPrimitivesNull() {
|
||||||
// assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives(null)); // generates warning
|
// assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives(null)); // generates warning
|
||||||
assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives((Class<?>[]) null)); // equivalent cast
|
assertNull(ClassUtils.wrappersToPrimitives((Class<?>[]) null), "Wrong result for null input"); // equivalent cast
|
||||||
// Other possible casts for null
|
// Other possible casts for null
|
||||||
assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.wrappersToPrimitives()));
|
assertTrue(Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.wrappersToPrimitives()), "empty -> empty");
|
||||||
final Class<?>[] castNull = ClassUtils.wrappersToPrimitives((Class<?>)null); // == new Class<?>[]{null}
|
final Class<?>[] castNull = ClassUtils.wrappersToPrimitives((Class<?>)null); // == new Class<?>[]{null}
|
||||||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
assertTrue(Arrays.equals(new Class<?>[]{null}, castNull), "(Class<?>)null -> [null]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1460,19 +1448,18 @@ public class ClassUtilsTest {
|
||||||
};
|
};
|
||||||
for (final Class<?> primitive : primitives) {
|
for (final Class<?> primitive : primitives) {
|
||||||
final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
|
final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
|
||||||
assertFalse("Still primitive", wrapperCls.isPrimitive());
|
assertFalse(wrapperCls.isPrimitive(), "Still primitive");
|
||||||
assertEquals(wrapperCls + " -> " + primitive, primitive,
|
assertEquals(primitive, ClassUtils.wrapperToPrimitive(wrapperCls), wrapperCls + " -> " + primitive);
|
||||||
ClassUtils.wrapperToPrimitive(wrapperCls));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapperToPrimitiveNoWrapper() {
|
public void testWrapperToPrimitiveNoWrapper() {
|
||||||
assertNull("Wrong result for non wrapper class", ClassUtils.wrapperToPrimitive(String.class));
|
assertNull(ClassUtils.wrapperToPrimitive(String.class), "Wrong result for non wrapper class");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapperToPrimitiveNull() {
|
public void testWrapperToPrimitiveNull() {
|
||||||
assertNull("Wrong result for null class", ClassUtils.wrapperToPrimitive(null));
|
assertNull(ClassUtils.wrapperToPrimitive(null), "Wrong result for null class");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -519,7 +519,7 @@ public class ConversionTest {
|
||||||
return out.substring(0, out.length() - 1);
|
return out.substring(0, out.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// org.junit.Assert(boolean[], boolean[]) does not exist in JUnit 4.2
|
// org.junit.jupiter.api.Assertions(boolean[], boolean[]) does not exist in JUnit 4.2
|
||||||
static void assertBinaryEquals(final boolean[] expected, final boolean[] actual) {
|
static void assertBinaryEquals(final boolean[] expected, final boolean[] actual) {
|
||||||
assertEquals(expected.length, actual.length);
|
assertEquals(expected.length, actual.length);
|
||||||
for (int i = 0; i < expected.length; i++ ) {
|
for (int i = 0; i < expected.length; i++ ) {
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -29,8 +30,8 @@ import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -46,7 +47,7 @@ public class EnumUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_getEnumMap() {
|
public void test_getEnumMap() {
|
||||||
final Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
|
final Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
|
||||||
assertEquals( "getEnumMap not created correctly", "{RED=RED, AMBER=AMBER, GREEN=GREEN}", test.toString());
|
assertEquals("{RED=RED, AMBER=AMBER, GREEN=GREEN}", test.toString(), "getEnumMap not created correctly");
|
||||||
assertEquals(3, test.size());
|
assertEquals(3, test.size());
|
||||||
assertTrue(test.containsKey("RED"));
|
assertTrue(test.containsKey("RED"));
|
||||||
assertEquals(Traffic.RED, test.get("RED"));
|
assertEquals(Traffic.RED, test.get("RED"));
|
||||||
|
@ -75,9 +76,9 @@ public class EnumUtilsTest {
|
||||||
assertFalse(EnumUtils.isValidEnum(Traffic.class, null));
|
assertFalse(EnumUtils.isValidEnum(Traffic.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_isValidEnum_nullClass() {
|
public void test_isValidEnum_nullClass() {
|
||||||
EnumUtils.isValidEnum(null, "PURPLE");
|
assertThrows(NullPointerException.class, () -> EnumUtils.isValidEnum(null, "PURPLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -89,9 +90,9 @@ public class EnumUtilsTest {
|
||||||
assertFalse(EnumUtils.isValidEnumIgnoreCase(Traffic.class, null));
|
assertFalse(EnumUtils.isValidEnumIgnoreCase(Traffic.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_isValidEnumIgnoreCase_nullClass() {
|
public void test_isValidEnumIgnoreCase_nullClass() {
|
||||||
EnumUtils.isValidEnumIgnoreCase(null, "PURPLE");
|
assertThrows(NullPointerException.class, () -> EnumUtils.isValidEnumIgnoreCase(null, "PURPLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -109,9 +110,9 @@ public class EnumUtilsTest {
|
||||||
assertNull(EnumUtils.getEnum(rawType, "rawType"));
|
assertNull(EnumUtils.getEnum(rawType, "rawType"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_getEnum_nullClass() {
|
public void test_getEnum_nullClass() {
|
||||||
EnumUtils.getEnum((Class<Traffic>) null, "PURPLE");
|
assertThrows(NullPointerException.class, () -> EnumUtils.getEnum((Class<Traffic>) null, "PURPLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -129,83 +130,89 @@ public class EnumUtilsTest {
|
||||||
assertNull(EnumUtils.getEnumIgnoreCase(rawType, "rawType"));
|
assertNull(EnumUtils.getEnumIgnoreCase(rawType, "rawType"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_getEnumIgnoreCase_nullClass() {
|
public void test_getEnumIgnoreCase_nullClass() {
|
||||||
EnumUtils.getEnumIgnoreCase((Class<Traffic>) null, "PURPLE");
|
assertThrows(NullPointerException.class, () -> EnumUtils.getEnumIgnoreCase((Class<Traffic>) null, "PURPLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVector_nullClass() {
|
public void test_generateBitVector_nullClass() {
|
||||||
EnumUtils.generateBitVector(null, EnumSet.of(Traffic.RED));
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVector(null, EnumSet.of(Traffic.RED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nullClass() {
|
public void test_generateBitVectors_nullClass() {
|
||||||
EnumUtils.generateBitVectors(null, EnumSet.of(Traffic.RED));
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVectors(null, EnumSet.of(Traffic.RED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVector_nullIterable() {
|
public void test_generateBitVector_nullIterable() {
|
||||||
EnumUtils.generateBitVector(Traffic.class, (Iterable<Traffic>) null);
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> EnumUtils.generateBitVector(Traffic.class, (Iterable<Traffic>) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nullIterable() {
|
public void test_generateBitVectors_nullIterable() {
|
||||||
EnumUtils.generateBitVectors(null, (Iterable<Traffic>) null);
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVectors(null, (Iterable<Traffic>) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVector_nullElement() {
|
public void test_generateBitVector_nullElement() {
|
||||||
EnumUtils.generateBitVector(Traffic.class, Arrays.asList(Traffic.RED, null));
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> EnumUtils.generateBitVector(Traffic.class, Arrays.asList(Traffic.RED, null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nullElement() {
|
public void test_generateBitVectors_nullElement() {
|
||||||
EnumUtils.generateBitVectors(Traffic.class, Arrays.asList(Traffic.RED, null));
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> EnumUtils.generateBitVectors(Traffic.class, Arrays.asList(Traffic.RED, null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVector_nullClassWithArray() {
|
public void test_generateBitVector_nullClassWithArray() {
|
||||||
EnumUtils.generateBitVector(null, Traffic.RED);
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVector(null, Traffic.RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nullClassWithArray() {
|
public void test_generateBitVectors_nullClassWithArray() {
|
||||||
EnumUtils.generateBitVectors(null, Traffic.RED);
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVectors(null, Traffic.RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVector_nullArray() {
|
public void test_generateBitVector_nullArray() {
|
||||||
EnumUtils.generateBitVector(Traffic.class, (Traffic[]) null);
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVector(Traffic.class, (Traffic[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nullArray() {
|
public void test_generateBitVectors_nullArray() {
|
||||||
EnumUtils.generateBitVectors(Traffic.class, (Traffic[]) null);
|
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVectors(Traffic.class, (Traffic[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVector_nullArrayElement() {
|
public void test_generateBitVector_nullArrayElement() {
|
||||||
EnumUtils.generateBitVector(Traffic.class, Traffic.RED, null);
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> EnumUtils.generateBitVector(Traffic.class, Traffic.RED, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nullArrayElement() {
|
public void test_generateBitVectors_nullArrayElement() {
|
||||||
EnumUtils.generateBitVectors(Traffic.class, Traffic.RED, null);
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> EnumUtils.generateBitVectors(Traffic.class, Traffic.RED, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVector_longClass() {
|
public void test_generateBitVector_longClass() {
|
||||||
EnumUtils.generateBitVector(TooMany.class, EnumSet.of(TooMany.A1));
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> EnumUtils.generateBitVector(TooMany.class, EnumSet.of(TooMany.A1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVector_longClassWithArray() {
|
public void test_generateBitVector_longClassWithArray() {
|
||||||
EnumUtils.generateBitVector(TooMany.class, TooMany.A1);
|
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVector(TooMany.class, TooMany.A1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVector_nonEnumClass() {
|
public void test_generateBitVector_nonEnumClass() {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final
|
final
|
||||||
|
@ -213,11 +220,11 @@ public class EnumUtilsTest {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final
|
final
|
||||||
List rawList = new ArrayList();
|
List rawList = new ArrayList();
|
||||||
EnumUtils.generateBitVector(rawType, rawList);
|
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVector(rawType, rawList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nonEnumClass() {
|
public void test_generateBitVectors_nonEnumClass() {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final
|
final
|
||||||
|
@ -225,25 +232,25 @@ public class EnumUtilsTest {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final
|
final
|
||||||
List rawList = new ArrayList();
|
List rawList = new ArrayList();
|
||||||
EnumUtils.generateBitVectors(rawType, rawList);
|
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVectors(rawType, rawList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVector_nonEnumClassWithArray() {
|
public void test_generateBitVector_nonEnumClassWithArray() {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final
|
final
|
||||||
Class rawType = Object.class;
|
Class rawType = Object.class;
|
||||||
EnumUtils.generateBitVector(rawType);
|
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVector(rawType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_generateBitVectors_nonEnumClassWithArray() {
|
public void test_generateBitVectors_nonEnumClassWithArray() {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final
|
final
|
||||||
Class rawType = Object.class;
|
Class rawType = Object.class;
|
||||||
EnumUtils.generateBitVectors(rawType);
|
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVectors(rawType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -332,19 +339,19 @@ public class EnumUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertArrayEquals(final long[] actual, final long... expected) {
|
private void assertArrayEquals(final long[] actual, final long... expected) {
|
||||||
Assert.assertArrayEquals(expected, actual);
|
Assertions.assertArrayEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_processBitVector_nullClass() {
|
public void test_processBitVector_nullClass() {
|
||||||
final Class<Traffic> empty = null;
|
final Class<Traffic> empty = null;
|
||||||
EnumUtils.processBitVector(empty, 0L);
|
assertThrows(NullPointerException.class, () -> EnumUtils.processBitVector(empty, 0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void test_processBitVectors_nullClass() {
|
public void test_processBitVectors_nullClass() {
|
||||||
final Class<Traffic> empty = null;
|
final Class<Traffic> empty = null;
|
||||||
EnumUtils.processBitVectors(empty, 0L);
|
assertThrows(NullPointerException.class, () -> EnumUtils.processBitVectors(empty, 0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -402,9 +409,9 @@ public class EnumUtilsTest {
|
||||||
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, Long.MIN_VALUE));
|
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, Long.MIN_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void test_processBitVector_longClass() {
|
public void test_processBitVector_longClass() {
|
||||||
EnumUtils.processBitVector(TooMany.class, 0L);
|
assertThrows(IllegalArgumentException.class, () -> EnumUtils.processBitVector(TooMany.class, 0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
|
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
|
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_1;
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||||
|
@ -45,32 +45,32 @@ public class JavaVersionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetJavaVersion() {
|
public void testGetJavaVersion() {
|
||||||
assertEquals("0.9 failed", JAVA_0_9, get("0.9"));
|
assertEquals(JAVA_0_9, get("0.9"), "0.9 failed");
|
||||||
assertEquals("1.1 failed", JAVA_1_1, get("1.1"));
|
assertEquals(JAVA_1_1, get("1.1"), "1.1 failed");
|
||||||
assertEquals("1.2 failed", JAVA_1_2, get("1.2"));
|
assertEquals(JAVA_1_2, get("1.2"), "1.2 failed");
|
||||||
assertEquals("1.3 failed", JAVA_1_3, get("1.3"));
|
assertEquals(JAVA_1_3, get("1.3"), "1.3 failed");
|
||||||
assertEquals("1.4 failed", JAVA_1_4, get("1.4"));
|
assertEquals(JAVA_1_4, get("1.4"), "1.4 failed");
|
||||||
assertEquals("1.5 failed", JAVA_1_5, get("1.5"));
|
assertEquals(JAVA_1_5, get("1.5"), "1.5 failed");
|
||||||
assertEquals("1.6 failed", JAVA_1_6, get("1.6"));
|
assertEquals(JAVA_1_6, get("1.6"), "1.6 failed");
|
||||||
assertEquals("1.7 failed", JAVA_1_7, get("1.7"));
|
assertEquals(JAVA_1_7, get("1.7"), "1.7 failed");
|
||||||
assertEquals("1.8 failed", JAVA_1_8, get("1.8"));
|
assertEquals(JAVA_1_8, get("1.8"), "1.8 failed");
|
||||||
assertEquals("9 failed", JAVA_9, get("9"));
|
assertEquals(JAVA_9, get("9"), "9 failed");
|
||||||
assertEquals("10 failed", JAVA_10, get("10"));
|
assertEquals(JAVA_10, get("10"), "10 failed");
|
||||||
assertEquals("11 failed", JavaVersion.JAVA_11, get("11"));
|
assertEquals(JavaVersion.JAVA_11, get("11"), "11 failed");
|
||||||
assertEquals("1.10 failed", JAVA_RECENT, get("1.10"));
|
assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed");
|
||||||
// assertNull("2.10 unexpectedly worked", get("2.10"));
|
// assertNull("2.10 unexpectedly worked", get("2.10"));
|
||||||
assertEquals("Wrapper method failed", get("1.5"), getJavaVersion("1.5"));
|
assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed");
|
||||||
assertEquals("Unhandled", JAVA_RECENT, get("12")); // LANG-1384
|
assertEquals(JAVA_RECENT, get("12"), "Unhandled"); // LANG-1384
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAtLeast() {
|
public void testAtLeast() {
|
||||||
assertFalse("1.2 at least 1.5 passed", JAVA_1_2.atLeast(JAVA_1_5));
|
assertFalse(JAVA_1_2.atLeast(JAVA_1_5), "1.2 at least 1.5 passed");
|
||||||
assertTrue("1.5 at least 1.2 failed", JAVA_1_5.atLeast(JAVA_1_2));
|
assertTrue(JAVA_1_5.atLeast(JAVA_1_2), "1.5 at least 1.2 failed");
|
||||||
assertFalse("1.6 at least 1.7 passed", JAVA_1_6.atLeast(JAVA_1_7));
|
assertFalse(JAVA_1_6.atLeast(JAVA_1_7), "1.6 at least 1.7 passed");
|
||||||
|
|
||||||
assertTrue("0.9 at least 1.5 failed", JAVA_0_9.atLeast(JAVA_1_5));
|
assertTrue(JAVA_0_9.atLeast(JAVA_1_5), "0.9 at least 1.5 failed");
|
||||||
assertFalse("0.9 at least 1.6 passed", JAVA_0_9.atLeast(JAVA_1_6));
|
assertFalse(JAVA_0_9.atLeast(JAVA_1_6), "0.9 at least 1.6 passed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
|
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -35,8 +35,8 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link LocaleUtils}.
|
* Unit tests for {@link LocaleUtils}.
|
||||||
|
@ -51,7 +51,7 @@ public class LocaleUtilsTest {
|
||||||
private static final Locale LOCALE_QQ = new Locale("qq", "");
|
private static final Locale LOCALE_QQ = new Locale("qq", "");
|
||||||
private static final Locale LOCALE_QQ_ZZ = new Locale("qq", "ZZ");
|
private static final Locale LOCALE_QQ_ZZ = new Locale("qq", "ZZ");
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Testing #LANG-304. Must be called before availableLocaleSet is called.
|
// Testing #LANG-304. Must be called before availableLocaleSet is called.
|
||||||
LocaleUtils.isAvailableLocale(Locale.getDefault());
|
LocaleUtils.isAvailableLocale(Locale.getDefault());
|
||||||
|
@ -79,7 +79,7 @@ public class LocaleUtilsTest {
|
||||||
*/
|
*/
|
||||||
private static void assertValidToLocale(final String language) {
|
private static void assertValidToLocale(final String language) {
|
||||||
final Locale locale = LocaleUtils.toLocale(language);
|
final Locale locale = LocaleUtils.toLocale(language);
|
||||||
assertNotNull("valid locale", locale);
|
assertNotNull(locale, "valid locale");
|
||||||
assertEquals(language, locale.getLanguage());
|
assertEquals(language, locale.getLanguage());
|
||||||
//country and variant are empty
|
//country and variant are empty
|
||||||
assertTrue(locale.getCountry() == null || locale.getCountry().isEmpty());
|
assertTrue(locale.getCountry() == null || locale.getCountry().isEmpty());
|
||||||
|
@ -95,7 +95,7 @@ public class LocaleUtilsTest {
|
||||||
*/
|
*/
|
||||||
private static void assertValidToLocale(final String localeString, final String language, final String country) {
|
private static void assertValidToLocale(final String localeString, final String language, final String country) {
|
||||||
final Locale locale = LocaleUtils.toLocale(localeString);
|
final Locale locale = LocaleUtils.toLocale(localeString);
|
||||||
assertNotNull("valid locale", locale);
|
assertNotNull(locale, "valid locale");
|
||||||
assertEquals(language, locale.getLanguage());
|
assertEquals(language, locale.getLanguage());
|
||||||
assertEquals(country, locale.getCountry());
|
assertEquals(country, locale.getCountry());
|
||||||
//variant is empty
|
//variant is empty
|
||||||
|
@ -114,7 +114,7 @@ public class LocaleUtilsTest {
|
||||||
final String localeString, final String language,
|
final String localeString, final String language,
|
||||||
final String country, final String variant) {
|
final String country, final String variant) {
|
||||||
final Locale locale = LocaleUtils.toLocale(localeString);
|
final Locale locale = LocaleUtils.toLocale(localeString);
|
||||||
assertNotNull("valid locale", locale);
|
assertNotNull(locale, "valid locale");
|
||||||
assertEquals(language, locale.getLanguage());
|
assertEquals(language, locale.getLanguage());
|
||||||
assertEquals(country, locale.getCountry());
|
assertEquals(country, locale.getCountry());
|
||||||
assertEquals(variant, locale.getVariant());
|
assertEquals(variant, locale.getVariant());
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.NotImplementedException}.
|
* Unit tests {@link org.apache.commons.lang3.NotImplementedException}.
|
||||||
|
@ -46,9 +46,9 @@ public class NotImplementedExceptionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCorrect(final String assertMessage, final NotImplementedException nie, final String message, final Throwable nested, final String code) {
|
private void assertCorrect(final String assertMessage, final NotImplementedException nie, final String message, final Throwable nested, final String code) {
|
||||||
assertNotNull(assertMessage + ": target is null", nie);
|
assertNotNull(nie, assertMessage + ": target is null");
|
||||||
assertEquals(assertMessage + ": Message not equal", message, nie.getMessage());
|
assertEquals(message, nie.getMessage(), assertMessage + ": Message not equal");
|
||||||
assertEquals(assertMessage + ": Nested throwable not equal", nested, nie.getCause());
|
assertEquals(nested, nie.getCause(), assertMessage + ": Nested throwable not equal");
|
||||||
assertEquals(assertMessage + ": Code not equal", code, nie.getCode());
|
assertEquals(code, nie.getCode(), assertMessage + ": Code not equal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
@ -43,7 +44,7 @@ import java.util.Set;
|
||||||
import org.apache.commons.lang3.exception.CloneFailedException;
|
import org.apache.commons.lang3.exception.CloneFailedException;
|
||||||
import org.apache.commons.lang3.mutable.MutableObject;
|
import org.apache.commons.lang3.mutable.MutableObject;
|
||||||
import org.apache.commons.lang3.text.StrBuilder;
|
import org.apache.commons.lang3.text.StrBuilder;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.ObjectUtils}.
|
* Unit tests {@link org.apache.commons.lang3.ObjectUtils}.
|
||||||
|
@ -111,8 +112,8 @@ public class ObjectUtilsTest {
|
||||||
public void testIsNull() {
|
public void testIsNull() {
|
||||||
final Object o = FOO;
|
final Object o = FOO;
|
||||||
final Object dflt = BAR;
|
final Object dflt = BAR;
|
||||||
assertSame("dflt was not returned when o was null", dflt, ObjectUtils.defaultIfNull(null, dflt));
|
assertSame(dflt, ObjectUtils.defaultIfNull(null, dflt), "dflt was not returned when o was null");
|
||||||
assertSame("dflt was returned when o was not null", o, ObjectUtils.defaultIfNull(o, dflt));
|
assertSame(o, ObjectUtils.defaultIfNull(o, dflt), "dflt was returned when o was not null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -168,20 +169,20 @@ public class ObjectUtilsTest {
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
assertTrue("ObjectUtils.equals(null, null) returned false", ObjectUtils.equals(null, null));
|
assertTrue(ObjectUtils.equals(null, null), "ObjectUtils.equals(null, null) returned false");
|
||||||
assertTrue("ObjectUtils.equals(\"foo\", null) returned true", !ObjectUtils.equals(FOO, null));
|
assertTrue(!ObjectUtils.equals(FOO, null), "ObjectUtils.equals(\"foo\", null) returned true");
|
||||||
assertTrue("ObjectUtils.equals(null, \"bar\") returned true", !ObjectUtils.equals(null, BAR));
|
assertTrue(!ObjectUtils.equals(null, BAR), "ObjectUtils.equals(null, \"bar\") returned true");
|
||||||
assertTrue("ObjectUtils.equals(\"foo\", \"bar\") returned true", !ObjectUtils.equals(FOO, BAR));
|
assertTrue(!ObjectUtils.equals(FOO, BAR), "ObjectUtils.equals(\"foo\", \"bar\") returned true");
|
||||||
assertTrue("ObjectUtils.equals(\"foo\", \"foo\") returned false", ObjectUtils.equals(FOO, FOO));
|
assertTrue(ObjectUtils.equals(FOO, FOO), "ObjectUtils.equals(\"foo\", \"foo\") returned false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotEqual() {
|
public void testNotEqual() {
|
||||||
assertFalse("ObjectUtils.notEqual(null, null) returned false", ObjectUtils.notEqual(null, null));
|
assertFalse(ObjectUtils.notEqual(null, null), "ObjectUtils.notEqual(null, null) returned false");
|
||||||
assertTrue("ObjectUtils.notEqual(\"foo\", null) returned true", ObjectUtils.notEqual(FOO, null));
|
assertTrue(ObjectUtils.notEqual(FOO, null), "ObjectUtils.notEqual(\"foo\", null) returned true");
|
||||||
assertTrue("ObjectUtils.notEqual(null, \"bar\") returned true", ObjectUtils.notEqual(null, BAR));
|
assertTrue(ObjectUtils.notEqual(null, BAR), "ObjectUtils.notEqual(null, \"bar\") returned true");
|
||||||
assertTrue("ObjectUtils.notEqual(\"foo\", \"bar\") returned true", ObjectUtils.notEqual(FOO, BAR));
|
assertTrue(ObjectUtils.notEqual(FOO, BAR), "ObjectUtils.notEqual(\"foo\", \"bar\") returned true");
|
||||||
assertFalse("ObjectUtils.notEqual(\"foo\", \"foo\") returned false", ObjectUtils.notEqual(FOO, FOO));
|
assertFalse(ObjectUtils.notEqual(FOO, FOO), "ObjectUtils.notEqual(\"foo\", \"foo\") returned false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -430,17 +431,17 @@ public class ObjectUtilsTest {
|
||||||
final Integer two = Integer.valueOf(2);
|
final Integer two = Integer.valueOf(2);
|
||||||
final Integer nullValue = null;
|
final Integer nullValue = null;
|
||||||
|
|
||||||
assertEquals("Null Null false", 0, ObjectUtils.compare(nullValue, nullValue));
|
assertEquals(0, ObjectUtils.compare(nullValue, nullValue), "Null Null false");
|
||||||
assertEquals("Null Null true", 0, ObjectUtils.compare(nullValue, nullValue, true));
|
assertEquals(0, ObjectUtils.compare(nullValue, nullValue, true), "Null Null true");
|
||||||
|
|
||||||
assertEquals("Null one false", -1, ObjectUtils.compare(nullValue, one));
|
assertEquals(-1, ObjectUtils.compare(nullValue, one), "Null one false");
|
||||||
assertEquals("Null one true", 1, ObjectUtils.compare(nullValue, one, true));
|
assertEquals(1, ObjectUtils.compare(nullValue, one, true), "Null one true");
|
||||||
|
|
||||||
assertEquals("one Null false", 1, ObjectUtils.compare(one, nullValue));
|
assertEquals(1, ObjectUtils.compare(one, nullValue), "one Null false");
|
||||||
assertEquals("one Null true", -1, ObjectUtils.compare(one, nullValue, true));
|
assertEquals(-1, ObjectUtils.compare(one, nullValue, true), "one Null true");
|
||||||
|
|
||||||
assertEquals("one two false", -1, ObjectUtils.compare(one, two));
|
assertEquals(-1, ObjectUtils.compare(one, two), "one two false");
|
||||||
assertEquals("one two true", -1, ObjectUtils.compare(one, two, true));
|
assertEquals(-1, ObjectUtils.compare(one, two, true), "one two true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -460,14 +461,14 @@ public class ObjectUtilsTest {
|
||||||
ObjectUtils.median(Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8)));
|
ObjectUtils.median(Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testMedian_nullItems() {
|
public void testMedian_nullItems() {
|
||||||
ObjectUtils.median((String[]) null);
|
assertThrows(NullPointerException.class, () -> ObjectUtils.median((String[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testMedian_emptyItems() {
|
public void testMedian_emptyItems() {
|
||||||
ObjectUtils.<String> median();
|
assertThrows(IllegalArgumentException.class, ObjectUtils::<String>median);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -485,19 +486,21 @@ public class ObjectUtilsTest {
|
||||||
assertSame(blah, ObjectUtils.median(cmp, foo, bar, baz, blah, wah));
|
assertSame(blah, ObjectUtils.median(cmp, foo, bar, baz, blah, wah));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testComparatorMedian_nullComparator() {
|
public void testComparatorMedian_nullComparator() {
|
||||||
ObjectUtils.median((Comparator<CharSequence>) null, new NonComparableCharSequence("foo"));
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ObjectUtils.median((Comparator<CharSequence>) null, new NonComparableCharSequence("foo")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testComparatorMedian_nullItems() {
|
public void testComparatorMedian_nullItems() {
|
||||||
ObjectUtils.median(new CharSequenceComparator(), (CharSequence[]) null);
|
assertThrows(NullPointerException.class,
|
||||||
|
() -> ObjectUtils.median(new CharSequenceComparator(), (CharSequence[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testComparatorMedian_emptyItems() {
|
public void testComparatorMedian_emptyItems() {
|
||||||
ObjectUtils.median(new CharSequenceComparator());
|
assertThrows(IllegalArgumentException.class, () -> ObjectUtils.median(new CharSequenceComparator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -532,18 +535,12 @@ public class ObjectUtilsTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
|
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
|
||||||
*
|
|
||||||
* @throws java.lang.Throwable because we expect this to fail
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NoSuchMethodException.class)
|
@Test
|
||||||
public void testCloneOfUncloneable() throws Throwable {
|
public void testCloneOfUncloneable() {
|
||||||
final UncloneableString string = new UncloneableString("apache");
|
final UncloneableString string = new UncloneableString("apache");
|
||||||
try {
|
CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.clone(string));
|
||||||
ObjectUtils.clone(string);
|
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
|
||||||
fail("Thrown " + CloneFailedException.class.getName() + " expected");
|
|
||||||
} catch (final CloneFailedException e) {
|
|
||||||
throw e.getCause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -584,18 +581,12 @@ public class ObjectUtilsTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
|
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
|
||||||
*
|
|
||||||
* @throws java.lang.Throwable because we expect this to fail
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NoSuchMethodException.class)
|
@Test
|
||||||
public void testPossibleCloneOfUncloneable() throws Throwable {
|
public void testPossibleCloneOfUncloneable() {
|
||||||
final UncloneableString string = new UncloneableString("apache");
|
final UncloneableString string = new UncloneableString("apache");
|
||||||
try {
|
CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string));
|
||||||
ObjectUtils.cloneIfPossible(string);
|
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
|
||||||
fail("Thrown " + CloneFailedException.class.getName() + " expected");
|
|
||||||
} catch (final CloneFailedException e) {
|
|
||||||
throw e.getCause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -605,15 +596,18 @@ public class ObjectUtilsTest {
|
||||||
// bytecode to see if the literals were folded into the
|
// bytecode to see if the literals were folded into the
|
||||||
// class, or if the bytecode kept the method call.
|
// class, or if the bytecode kept the method call.
|
||||||
|
|
||||||
assertTrue("CONST(boolean)", ObjectUtils.CONST(true));
|
// TODO: JUnit Jupiter 5.3.1 doesn't support delta=0.
|
||||||
assertEquals("CONST(byte)", (byte) 3, ObjectUtils.CONST((byte) 3));
|
// This should be replaced when it is supported in JUnit Jupiter 5.4.
|
||||||
assertEquals("CONST(char)", (char) 3, ObjectUtils.CONST((char) 3));
|
// See https://github.com/junit-team/junit5/pull/1613 for details.
|
||||||
assertEquals("CONST(short)", (short) 3, ObjectUtils.CONST((short) 3));
|
assertTrue(ObjectUtils.CONST(true), "CONST(boolean)");
|
||||||
assertEquals("CONST(int)", 3, ObjectUtils.CONST(3));
|
assertEquals((byte) 3, ObjectUtils.CONST((byte) 3), "CONST(byte)");
|
||||||
assertEquals("CONST(long)", 3L, ObjectUtils.CONST(3L));
|
assertEquals((char) 3, ObjectUtils.CONST((char) 3), "CONST(char)");
|
||||||
assertEquals("CONST(float)", 3f, ObjectUtils.CONST(3f), 0);
|
assertEquals((short) 3, ObjectUtils.CONST((short) 3), "CONST(short)");
|
||||||
assertEquals("CONST(double)", 3.0, ObjectUtils.CONST(3.0), 0);
|
assertEquals(3, ObjectUtils.CONST(3), "CONST(int)");
|
||||||
assertEquals("CONST(Object)", "abc", ObjectUtils.CONST("abc"));
|
assertEquals(3L, ObjectUtils.CONST(3L), "CONST(long)");
|
||||||
|
assertTrue(3f == ObjectUtils.CONST(3f), "CONST(float)");
|
||||||
|
assertTrue(3.0 == ObjectUtils.CONST(3.0), "CONST(double)");
|
||||||
|
assertEquals("abc", ObjectUtils.CONST("abc"), "CONST(Object)");
|
||||||
|
|
||||||
// Make sure documentation examples from Javadoc all work
|
// Make sure documentation examples from Javadoc all work
|
||||||
// (this fixed a lot of my bugs when I these!)
|
// (this fixed a lot of my bugs when I these!)
|
||||||
|
@ -644,8 +638,8 @@ public class ObjectUtilsTest {
|
||||||
assertEquals(123, MAGIC_INT);
|
assertEquals(123, MAGIC_INT);
|
||||||
assertEquals(123, MAGIC_LONG1);
|
assertEquals(123, MAGIC_LONG1);
|
||||||
assertEquals(3, MAGIC_LONG2);
|
assertEquals(3, MAGIC_LONG2);
|
||||||
assertEquals(1.0f, MAGIC_FLOAT, 0.0f);
|
assertTrue(1.0f == MAGIC_FLOAT);
|
||||||
assertEquals(1.0, MAGIC_DOUBLE, 0.0);
|
assertTrue(1.0 == MAGIC_DOUBLE);
|
||||||
assertEquals("abc", MAGIC_STRING);
|
assertEquals("abc", MAGIC_STRING);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,23 +16,23 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.allOf;
|
import static org.hamcrest.Matchers.allOf;
|
||||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.RandomStringUtils}.
|
* Unit tests {@link org.apache.commons.lang3.RandomStringUtils}.
|
||||||
|
@ -57,96 +57,96 @@ public class RandomStringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testRandomStringUtils() {
|
public void testRandomStringUtils() {
|
||||||
String r1 = RandomStringUtils.random(50);
|
String r1 = RandomStringUtils.random(50);
|
||||||
assertEquals("random(50) length", 50, r1.length());
|
assertEquals(50, r1.length(), "random(50) length");
|
||||||
String r2 = RandomStringUtils.random(50);
|
String r2 = RandomStringUtils.random(50);
|
||||||
assertEquals("random(50) length", 50, r2.length());
|
assertEquals(50, r2.length(), "random(50) length");
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomAscii(50);
|
r1 = RandomStringUtils.randomAscii(50);
|
||||||
assertEquals("randomAscii(50) length", 50, r1.length());
|
assertEquals(50, r1.length(), "randomAscii(50) length");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("char between 32 and 127", r1.charAt(i) >= 32 && r1.charAt(i) <= 127);
|
assertTrue(r1.charAt(i) >= 32 && r1.charAt(i) <= 127, "char between 32 and 127");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomAscii(50);
|
r2 = RandomStringUtils.randomAscii(50);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomAlphabetic(50);
|
r1 = RandomStringUtils.randomAlphabetic(50);
|
||||||
assertEquals("randomAlphabetic(50)", 50, r1.length());
|
assertEquals(50, r1.length(), "randomAlphabetic(50)");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("r1 contains alphabetic", Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i)));
|
assertTrue(Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i)), "r1 contains alphabetic");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomAlphabetic(50);
|
r2 = RandomStringUtils.randomAlphabetic(50);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomAlphanumeric(50);
|
r1 = RandomStringUtils.randomAlphanumeric(50);
|
||||||
assertEquals("randomAlphanumeric(50)", 50, r1.length());
|
assertEquals(50, r1.length(), "randomAlphanumeric(50)");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("r1 contains alphanumeric", Character.isLetterOrDigit(r1.charAt(i)));
|
assertTrue(Character.isLetterOrDigit(r1.charAt(i)), "r1 contains alphanumeric");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomAlphabetic(50);
|
r2 = RandomStringUtils.randomAlphabetic(50);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomGraph(50);
|
r1 = RandomStringUtils.randomGraph(50);
|
||||||
assertEquals("randomGraph(50) length", 50, r1.length());
|
assertEquals(50, r1.length(), "randomGraph(50) length");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("char between 33 and 126", r1.charAt(i) >= 33 && r1.charAt(i) <= 126);
|
assertTrue(r1.charAt(i) >= 33 && r1.charAt(i) <= 126, "char between 33 and 126");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomGraph(50);
|
r2 = RandomStringUtils.randomGraph(50);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomNumeric(50);
|
r1 = RandomStringUtils.randomNumeric(50);
|
||||||
assertEquals("randomNumeric(50)", 50, r1.length());
|
assertEquals(50, r1.length(), "randomNumeric(50)");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("r1 contains numeric", Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i)));
|
assertTrue(Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i)), "r1 contains numeric");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomNumeric(50);
|
r2 = RandomStringUtils.randomNumeric(50);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomPrint(50);
|
r1 = RandomStringUtils.randomPrint(50);
|
||||||
assertEquals("randomPrint(50) length", 50, r1.length());
|
assertEquals(50, r1.length(), "randomPrint(50) length");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("char between 32 and 126", r1.charAt(i) >= 32 && r1.charAt(i) <= 126);
|
assertTrue(r1.charAt(i) >= 32 && r1.charAt(i) <= 126, "char between 32 and 126");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomPrint(50);
|
r2 = RandomStringUtils.randomPrint(50);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
String set = "abcdefg";
|
String set = "abcdefg";
|
||||||
r1 = RandomStringUtils.random(50, set);
|
r1 = RandomStringUtils.random(50, set);
|
||||||
assertEquals("random(50, \"abcdefg\")", 50, r1.length());
|
assertEquals(50, r1.length(), "random(50, \"abcdefg\")");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1);
|
assertTrue(set.indexOf(r1.charAt(i)) > -1, "random char in set");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.random(50, set);
|
r2 = RandomStringUtils.random(50, set);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.random(50, (String) null);
|
r1 = RandomStringUtils.random(50, (String) null);
|
||||||
assertEquals("random(50) length", 50, r1.length());
|
assertEquals(50, r1.length(), "random(50) length");
|
||||||
r2 = RandomStringUtils.random(50, (String) null);
|
r2 = RandomStringUtils.random(50, (String) null);
|
||||||
assertEquals("random(50) length", 50, r2.length());
|
assertEquals(50, r2.length(), "random(50) length");
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
set = "stuvwxyz";
|
set = "stuvwxyz";
|
||||||
r1 = RandomStringUtils.random(50, set.toCharArray());
|
r1 = RandomStringUtils.random(50, set.toCharArray());
|
||||||
assertEquals("random(50, \"stuvwxyz\")", 50, r1.length());
|
assertEquals(50, r1.length(), "random(50, \"stuvwxyz\")");
|
||||||
for(int i = 0; i < r1.length(); i++) {
|
for(int i = 0; i < r1.length(); i++) {
|
||||||
assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1);
|
assertTrue(set.indexOf(r1.charAt(i)) > -1, "random char in set");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.random(50, set);
|
r2 = RandomStringUtils.random(50, set);
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.random(50, (char[]) null);
|
r1 = RandomStringUtils.random(50, (char[]) null);
|
||||||
assertEquals("random(50) length", 50, r1.length());
|
assertEquals(50, r1.length(), "random(50) length");
|
||||||
r2 = RandomStringUtils.random(50, (char[]) null);
|
r2 = RandomStringUtils.random(50, (char[]) null);
|
||||||
assertEquals("random(50) length", 50, r2.length());
|
assertEquals(50, r2.length(), "random(50) length");
|
||||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
final long seed = System.currentTimeMillis();
|
final long seed = System.currentTimeMillis();
|
||||||
r1 = RandomStringUtils.random(50,0,0,true,true,null,new Random(seed));
|
r1 = RandomStringUtils.random(50,0,0,true,true,null,new Random(seed));
|
||||||
r2 = RandomStringUtils.random(50,0,0,true,true,null,new Random(seed));
|
r2 = RandomStringUtils.random(50,0,0,true,true,null,new Random(seed));
|
||||||
assertEquals("r1.equals(r2)", r1, r2);
|
assertEquals(r1, r2, "r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.random(0);
|
r1 = RandomStringUtils.random(0);
|
||||||
assertEquals("random(0).equals(\"\")", "", r1);
|
assertEquals("", r1, "random(0).equals(\"\")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -162,8 +162,8 @@ public class RandomStringUtilsTest {
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
} catch (final IllegalArgumentException ex) { // distinguish from Random#nextInt message
|
} catch (final IllegalArgumentException ex) { // distinguish from Random#nextInt message
|
||||||
final String msg = ex.getMessage();
|
final String msg = ex.getMessage();
|
||||||
assertTrue("Message (" + msg + ") must contain 'start'", msg.contains("start"));
|
assertTrue(msg.contains("start"), "Message (" + msg + ") must contain 'start'");
|
||||||
assertTrue("Message (" + msg + ") must contain 'end'", msg.contains("end"));
|
assertTrue(msg.contains("end"), "Message (" + msg + ") must contain 'end'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public class RandomStringUtilsTest {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
final String s = RandomStringUtils.randomAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
final String s = RandomStringUtils.randomAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||||
assertTrue(s, s.matches(pattern));
|
assertTrue(s.matches(pattern), s);
|
||||||
|
|
||||||
if (s.length() < minCreatedLength) {
|
if (s.length() < minCreatedLength) {
|
||||||
minCreatedLength = s.length();
|
minCreatedLength = s.length();
|
||||||
|
@ -349,7 +349,7 @@ public class RandomStringUtilsTest {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||||
assertTrue(s, s.matches(pattern));
|
assertTrue(s.matches(pattern), s);
|
||||||
|
|
||||||
if (s.length() < minCreatedLength) {
|
if (s.length() < minCreatedLength) {
|
||||||
minCreatedLength = s.length();
|
minCreatedLength = s.length();
|
||||||
|
@ -374,7 +374,7 @@ public class RandomStringUtilsTest {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
final String s = RandomStringUtils.randomAlphanumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
final String s = RandomStringUtils.randomAlphanumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||||
assertTrue(s, s.matches(pattern));
|
assertTrue(s.matches(pattern), s);
|
||||||
|
|
||||||
if (s.length() < minCreatedLength) {
|
if (s.length() < minCreatedLength) {
|
||||||
minCreatedLength = s.length();
|
minCreatedLength = s.length();
|
||||||
|
@ -399,7 +399,7 @@ public class RandomStringUtilsTest {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
final String s = RandomStringUtils.randomGraph(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
final String s = RandomStringUtils.randomGraph(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||||
assertTrue(s, s.matches(pattern));
|
assertTrue(s.matches(pattern), s);
|
||||||
|
|
||||||
if (s.length() < minCreatedLength) {
|
if (s.length() < minCreatedLength) {
|
||||||
minCreatedLength = s.length();
|
minCreatedLength = s.length();
|
||||||
|
@ -424,7 +424,7 @@ public class RandomStringUtilsTest {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
final String s = RandomStringUtils.randomNumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
final String s = RandomStringUtils.randomNumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||||
assertTrue(s, s.matches(pattern));
|
assertTrue(s.matches(pattern), s);
|
||||||
|
|
||||||
if (s.length() < minCreatedLength) {
|
if (s.length() < minCreatedLength) {
|
||||||
minCreatedLength = s.length();
|
minCreatedLength = s.length();
|
||||||
|
@ -449,7 +449,7 @@ public class RandomStringUtilsTest {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
final String s = RandomStringUtils.randomPrint(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
final String s = RandomStringUtils.randomPrint(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||||
assertTrue(s, s.matches(pattern));
|
assertTrue(s.matches(pattern), s);
|
||||||
|
|
||||||
if (s.length() < minCreatedLength) {
|
if (s.length() < minCreatedLength) {
|
||||||
minCreatedLength = s.length();
|
minCreatedLength = s.length();
|
||||||
|
@ -488,8 +488,7 @@ public class RandomStringUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Perform chi-square test with df = 3-1 = 2, testing at .001 level
|
// Perform chi-square test with df = 3-1 = 2, testing at .001 level
|
||||||
assertTrue("test homogeneity -- will fail about 1 in 1000 times",
|
assertTrue(chiSquare(expected,counts) < 13.82, "test homogeneity -- will fail about 1 in 1000 times");
|
||||||
chiSquare(expected,counts) < 13.82);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -525,8 +524,9 @@ public class RandomStringUtilsTest {
|
||||||
for (int i=0; i < orig.length() && i < copy.length(); i++) {
|
for (int i=0; i < orig.length() && i < copy.length(); i++) {
|
||||||
final char o = orig.charAt(i);
|
final char o = orig.charAt(i);
|
||||||
final char c = copy.charAt(i);
|
final char c = copy.charAt(i);
|
||||||
assertEquals("differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," +
|
assertEquals(o, c,
|
||||||
Integer.toHexString(new Character(c).hashCode()) + ")", o, c);
|
"differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," +
|
||||||
|
Integer.toHexString(new Character(c).hashCode()) + ")");
|
||||||
}
|
}
|
||||||
// compare length also
|
// compare length also
|
||||||
assertEquals(orig.length(), copy.length());
|
assertEquals(orig.length(), copy.length());
|
||||||
|
@ -559,7 +559,7 @@ public class RandomStringUtilsTest {
|
||||||
|
|
||||||
final String result = RandomStringUtils.random(2, start, end, false, false, null, fixedRandom);
|
final String result = RandomStringUtils.random(2, start, end, false, false, null, fixedRandom);
|
||||||
final int c = result.codePointAt(0);
|
final int c = result.codePointAt(0);
|
||||||
assertTrue(String.format("Character '%d' not in range [%d,%d).", c, start, end), c >= start && c < end);
|
assertTrue(c >= start && c < end, String.format("Character '%d' not in range [%d,%d).", c, start, end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -47,49 +48,49 @@ public class RandomUtilsTest {
|
||||||
assertFalse(Modifier.isFinal(RandomUtils.class.getModifiers()));
|
assertFalse(Modifier.isFinal(RandomUtils.class.getModifiers()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextBytesNegative() throws Exception {
|
public void testNextBytesNegative() {
|
||||||
RandomUtils.nextBytes(-1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextBytes(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextIntNegative() throws Exception {
|
public void testNextIntNegative() {
|
||||||
RandomUtils.nextInt(-1, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextInt(-1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextLongNegative() throws Exception {
|
public void testNextLongNegative() {
|
||||||
RandomUtils.nextLong(-1, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextLong(-1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextDoubleNegative() throws Exception {
|
public void testNextDoubleNegative() {
|
||||||
RandomUtils.nextDouble(-1, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextDouble(-1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextFloatNegative() throws Exception {
|
public void testNextFloatNegative() {
|
||||||
RandomUtils.nextFloat(-1, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextFloat(-1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextIntLowerGreaterUpper() throws Exception {
|
public void testNextIntLowerGreaterUpper() {
|
||||||
RandomUtils.nextInt(2, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextInt(2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextLongLowerGreaterUpper() throws Exception {
|
public void testNextLongLowerGreaterUpper() {
|
||||||
RandomUtils.nextLong(2, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextLong(2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextDoubleLowerGreaterUpper() throws Exception {
|
public void testNextDoubleLowerGreaterUpper() {
|
||||||
RandomUtils.nextDouble(2, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextDouble(2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNextFloatLowerGreaterUpper() throws Exception {
|
public void testNextFloatLowerGreaterUpper() {
|
||||||
RandomUtils.nextFloat(2, 1);
|
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextFloat(2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,17 +17,18 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -47,7 +48,7 @@ public class RangeTest {
|
||||||
private Range<Double> doubleRange;
|
private Range<Double> doubleRange;
|
||||||
|
|
||||||
@SuppressWarnings("cast") // intRange
|
@SuppressWarnings("cast") // intRange
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
byteRange = Range.between((byte) 0, (byte) 5);
|
byteRange = Range.between((byte) 0, (byte) 5);
|
||||||
byteRange2 = Range.between((byte) 0, (byte) 5);
|
byteRange2 = Range.between((byte) 0, (byte) 5);
|
||||||
|
@ -84,13 +85,13 @@ public class RangeTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Range<Integer> ri = Range.is(10);
|
Range<Integer> ri = Range.is(10);
|
||||||
assertFalse("should not contain null", ri.contains(null));
|
assertFalse(ri.contains(null), "should not contain null");
|
||||||
assertTrue("should contain 10", ri.contains(10));
|
assertTrue(ri.contains(10), "should contain 10");
|
||||||
assertFalse("should not contain 11", ri.contains(11));
|
assertFalse(ri.contains(11), "should not contain 11");
|
||||||
ri = Range.is(10, c);
|
ri = Range.is(10, c);
|
||||||
assertFalse("should not contain null", ri.contains(null));
|
assertFalse(ri.contains(null), "should not contain null");
|
||||||
assertTrue("should contain 10", ri.contains(10));
|
assertTrue(ri.contains(10), "should contain 10");
|
||||||
assertTrue("should contain 11", ri.contains(11));
|
assertTrue(ri.contains(11), "should contain 11");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -108,29 +109,29 @@ public class RangeTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Range<Integer> rb = Range.between(-10, 20);
|
Range<Integer> rb = Range.between(-10, 20);
|
||||||
assertFalse("should not contain null", rb.contains(null));
|
assertFalse(rb.contains(null), "should not contain null");
|
||||||
assertTrue("should contain 10", rb.contains(10));
|
assertTrue(rb.contains(10), "should contain 10");
|
||||||
assertTrue("should contain -10", rb.contains(-10));
|
assertTrue(rb.contains(-10), "should contain -10");
|
||||||
assertFalse("should not contain 21", rb.contains(21));
|
assertFalse(rb.contains(21), "should not contain 21");
|
||||||
assertFalse("should not contain -11", rb.contains(-11));
|
assertFalse(rb.contains(-11), "should not contain -11");
|
||||||
rb = Range.between(-10, 20, c);
|
rb = Range.between(-10, 20, c);
|
||||||
assertFalse("should not contain null", rb.contains(null));
|
assertFalse(rb.contains(null), "should not contain null");
|
||||||
assertTrue("should contain 10", rb.contains(10));
|
assertTrue(rb.contains(10), "should contain 10");
|
||||||
assertTrue("should contain -10", rb.contains(-10));
|
assertTrue(rb.contains(-10), "should contain -10");
|
||||||
assertTrue("should contain 21", rb.contains(21));
|
assertTrue(rb.contains(21), "should contain 21");
|
||||||
assertTrue("should contain -11", rb.contains(-11));
|
assertTrue(rb.contains(-11), "should contain -11");
|
||||||
Range<String> rbstr = Range.between("house", "i");
|
Range<String> rbstr = Range.between("house", "i");
|
||||||
assertFalse("should not contain null", rbstr.contains(null));
|
assertFalse(rbstr.contains(null), "should not contain null");
|
||||||
assertTrue("should contain house", rbstr.contains("house"));
|
assertTrue(rbstr.contains("house"), "should contain house");
|
||||||
assertTrue("should contain i", rbstr.contains("i"));
|
assertTrue(rbstr.contains("i"), "should contain i");
|
||||||
assertFalse("should not contain hose", rbstr.contains("hose"));
|
assertFalse(rbstr.contains("hose"), "should not contain hose");
|
||||||
assertFalse("should not contain ice", rbstr.contains("ice"));
|
assertFalse(rbstr.contains("ice"), "should not contain ice");
|
||||||
rbstr = Range.between("house", "i", lengthComp);
|
rbstr = Range.between("house", "i", lengthComp);
|
||||||
assertFalse("should not contain null", rbstr.contains(null));
|
assertFalse(rbstr.contains(null), "should not contain null");
|
||||||
assertTrue("should contain house", rbstr.contains("house"));
|
assertTrue(rbstr.contains("house"), "should contain house");
|
||||||
assertTrue("should contain i", rbstr.contains("i"));
|
assertTrue(rbstr.contains("i"), "should contain i");
|
||||||
assertFalse("should not contain houses", rbstr.contains("houses"));
|
assertFalse(rbstr.contains("houses"), "should not contain houses");
|
||||||
assertFalse("should not contain ''", rbstr.contains(""));
|
assertFalse(rbstr.contains(""), "should not contain ''");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -375,14 +376,14 @@ public class RangeTest {
|
||||||
assertEquals(Range.between(10, 15), intRange.intersectionWith(Range.between(5, 15)));
|
assertEquals(Range.between(10, 15), intRange.intersectionWith(Range.between(5, 15)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testIntersectionWithNull() {
|
public void testIntersectionWithNull() {
|
||||||
intRange.intersectionWith(null);
|
assertThrows(IllegalArgumentException.class, () -> intRange.intersectionWith(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testIntersectionWithNonOverlapping() {
|
public void testIntersectionWithNonOverlapping() {
|
||||||
intRange.intersectionWith(Range.between(0, 9));
|
assertThrows(IllegalArgumentException.class, () -> intRange.intersectionWith(Range.between(0, 9)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for methods of {@link org.apache.commons.lang3.RegExUtils} which been moved to their own test classes.
|
* Unit tests for methods of {@link org.apache.commons.lang3.RegExUtils} which been moved to their own test classes.
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -37,8 +38,8 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.SerializationUtils}.
|
* Unit tests {@link org.apache.commons.lang3.SerializationUtils}.
|
||||||
|
@ -52,7 +53,7 @@ public class SerializationUtilsTest {
|
||||||
private Integer iInteger;
|
private Integer iInteger;
|
||||||
private HashMap<Object, Object> iMap;
|
private HashMap<Object, Object> iMap;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
iString = "foo";
|
iString = "foo";
|
||||||
iInteger = Integer.valueOf(7);
|
iInteger = Integer.valueOf(7);
|
||||||
|
@ -114,11 +115,11 @@ public class SerializationUtilsTest {
|
||||||
assertArrayEquals(realBytes, testBytes);
|
assertArrayEquals(realBytes, testBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SerializationException.class)
|
@Test
|
||||||
public void testSerializeStreamUnserializable() throws Exception {
|
public void testSerializeStreamUnserializable() {
|
||||||
final ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
final ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||||
iMap.put(new Object(), new Object());
|
iMap.put(new Object(), new Object());
|
||||||
SerializationUtils.serialize(iMap, streamTest);
|
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap, streamTest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -138,14 +139,14 @@ public class SerializationUtilsTest {
|
||||||
assertArrayEquals(realBytes, testBytes);
|
assertArrayEquals(realBytes, testBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testSerializeStreamObjNull() throws Exception {
|
public void testSerializeStreamObjNull() {
|
||||||
SerializationUtils.serialize(iMap, null);
|
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.serialize(iMap, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testSerializeStreamNullNull() throws Exception {
|
public void testSerializeStreamNullNull() {
|
||||||
SerializationUtils.serialize(null, null);
|
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.serialize(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -188,14 +189,16 @@ public class SerializationUtilsTest {
|
||||||
assertEquals(iMap, testMap);
|
assertEquals(iMap, testMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=ClassCastException.class)
|
@Test
|
||||||
public void testDeserializeClassCastException() {
|
public void testDeserializeClassCastException() {
|
||||||
final String value = "Hello";
|
final String value = "Hello";
|
||||||
final byte[] serialized = SerializationUtils.serialize(value);
|
final byte[] serialized = SerializationUtils.serialize(value);
|
||||||
assertEquals(value, SerializationUtils.deserialize(serialized));
|
assertEquals(value, SerializationUtils.deserialize(serialized));
|
||||||
// Causes ClassCastException in call site, not in SerializationUtils.deserialize
|
assertThrows(ClassCastException.class, () -> {
|
||||||
@SuppressWarnings("unused") // needed to cause Exception
|
// Causes ClassCastException in call site, not in SerializationUtils.deserialize
|
||||||
final Integer i = SerializationUtils.deserialize(serialized);
|
@SuppressWarnings("unused") // needed to cause Exception
|
||||||
|
final Integer i = SerializationUtils.deserialize(serialized);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -211,14 +214,15 @@ public class SerializationUtilsTest {
|
||||||
assertNull(test);
|
assertNull(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testDeserializeStreamNull() throws Exception {
|
public void testDeserializeStreamNull() {
|
||||||
SerializationUtils.deserialize((InputStream) null);
|
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.deserialize((InputStream) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SerializationException.class)
|
@Test
|
||||||
public void testDeserializeStreamBadStream() throws Exception {
|
public void testDeserializeStreamBadStream() {
|
||||||
SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0]));
|
assertThrows(SerializationException.class,
|
||||||
|
() -> SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -262,10 +266,10 @@ public class SerializationUtilsTest {
|
||||||
assertArrayEquals(realBytes, testBytes);
|
assertArrayEquals(realBytes, testBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SerializationException.class)
|
@Test
|
||||||
public void testSerializeBytesUnserializable() throws Exception {
|
public void testSerializeBytesUnserializable() {
|
||||||
iMap.put(new Object(), new Object());
|
iMap.put(new Object(), new Object());
|
||||||
SerializationUtils.serialize(iMap);
|
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -317,14 +321,14 @@ public class SerializationUtilsTest {
|
||||||
assertNull(test);
|
assertNull(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testDeserializeBytesNull() throws Exception {
|
public void testDeserializeBytesNull() {
|
||||||
SerializationUtils.deserialize((byte[]) null);
|
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.deserialize((byte[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SerializationException.class)
|
@Test
|
||||||
public void testDeserializeBytesBadStream() throws Exception {
|
public void testDeserializeBytesBadStream() {
|
||||||
SerializationUtils.deserialize(new byte[0]);
|
assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(new byte[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -349,10 +353,10 @@ public class SerializationUtilsTest {
|
||||||
assertNull(test);
|
assertNull(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SerializationException.class)
|
@Test
|
||||||
public void testCloneUnserializable() throws Exception {
|
public void testCloneUnserializable() {
|
||||||
iMap.put(new Object(), new Object());
|
iMap.put(new Object(), new Object());
|
||||||
SerializationUtils.clone(iMap);
|
assertThrows(SerializationException.class, () -> SerializationUtils.clone(iMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -34,7 +35,7 @@ import java.nio.file.Paths;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
|
import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
|
||||||
import org.apache.commons.lang3.text.translate.NumericEntityEscaper;
|
import org.apache.commons.lang3.text.translate.NumericEntityEscaper;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link StringEscapeUtils}.
|
* Unit tests for {@link StringEscapeUtils}.
|
||||||
|
@ -115,7 +116,7 @@ public class StringEscapeUtilsTest {
|
||||||
private void assertEscapeJava(String message, final String expected, final String original) throws IOException {
|
private void assertEscapeJava(String message, final String expected, final String original) throws IOException {
|
||||||
final String converted = StringEscapeUtils.escapeJava(original);
|
final String converted = StringEscapeUtils.escapeJava(original);
|
||||||
message = "escapeJava(String) failed" + (message == null ? "" : (": " + message));
|
message = "escapeJava(String) failed" + (message == null ? "" : (": " + message));
|
||||||
assertEquals(message, expected, converted);
|
assertEquals(expected, converted, message);
|
||||||
|
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
StringEscapeUtils.ESCAPE_JAVA.translate(original, writer);
|
StringEscapeUtils.ESCAPE_JAVA.translate(original, writer);
|
||||||
|
@ -165,12 +166,12 @@ public class StringEscapeUtilsTest {
|
||||||
final String expected = unescaped;
|
final String expected = unescaped;
|
||||||
final String actual = StringEscapeUtils.unescapeJava(original);
|
final String actual = StringEscapeUtils.unescapeJava(original);
|
||||||
|
|
||||||
assertEquals("unescape(String) failed" +
|
assertEquals(expected, actual,
|
||||||
|
"unescape(String) failed" +
|
||||||
(message == null ? "" : (": " + message)) +
|
(message == null ? "" : (": " + message)) +
|
||||||
": expected '" + StringEscapeUtils.escapeJava(expected) +
|
": expected '" + StringEscapeUtils.escapeJava(expected) +
|
||||||
// we escape this so we can see it in the error message
|
// we escape this so we can see it in the error message
|
||||||
"' actual '" + StringEscapeUtils.escapeJava(actual) + "'",
|
"' actual '" + StringEscapeUtils.escapeJava(actual) + "'");
|
||||||
expected, actual);
|
|
||||||
|
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
StringEscapeUtils.UNESCAPE_JAVA.translate(original, writer);
|
StringEscapeUtils.UNESCAPE_JAVA.translate(original, writer);
|
||||||
|
@ -248,14 +249,14 @@ public class StringEscapeUtilsTest {
|
||||||
final String message = element[0];
|
final String message = element[0];
|
||||||
final String expected = element[1];
|
final String expected = element[1];
|
||||||
final String original = element[2];
|
final String original = element[2];
|
||||||
assertEquals(message, expected, StringEscapeUtils.escapeHtml4(original));
|
assertEquals(expected, StringEscapeUtils.escapeHtml4(original), message);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
try {
|
try {
|
||||||
StringEscapeUtils.ESCAPE_HTML4.translate(original, sw);
|
StringEscapeUtils.ESCAPE_HTML4.translate(original, sw);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
}
|
}
|
||||||
final String actual = original == null ? null : sw.toString();
|
final String actual = original == null ? null : sw.toString();
|
||||||
assertEquals(message, expected, actual);
|
assertEquals(expected, actual, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +266,7 @@ public class StringEscapeUtilsTest {
|
||||||
final String message = element[0];
|
final String message = element[0];
|
||||||
final String expected = element[2];
|
final String expected = element[2];
|
||||||
final String original = element[1];
|
final String original = element[1];
|
||||||
assertEquals(message, expected, StringEscapeUtils.unescapeHtml4(original));
|
assertEquals(expected, StringEscapeUtils.unescapeHtml4(original), message);
|
||||||
|
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
try {
|
try {
|
||||||
|
@ -273,12 +274,12 @@ public class StringEscapeUtilsTest {
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
}
|
}
|
||||||
final String actual = original == null ? null : sw.toString();
|
final String actual = original == null ? null : sw.toString();
|
||||||
assertEquals(message, expected, actual);
|
assertEquals(expected, actual, message);
|
||||||
}
|
}
|
||||||
// \u00E7 is a cedilla (c with wiggle under)
|
// \u00E7 is a cedilla (c with wiggle under)
|
||||||
// note that the test string must be 7-bit-clean (Unicode escaped) or else it will compile incorrectly
|
// note that the test string must be 7-bit-clean (Unicode escaped) or else it will compile incorrectly
|
||||||
// on some locales
|
// on some locales
|
||||||
assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais"));
|
assertEquals("Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais"), "funny chars pass through OK");
|
||||||
|
|
||||||
assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml4("Hello&;World"));
|
assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml4("Hello&;World"));
|
||||||
assertEquals("Hello&#;World", StringEscapeUtils.unescapeHtml4("Hello&#;World"));
|
assertEquals("Hello&#;World", StringEscapeUtils.unescapeHtml4("Hello&#;World"));
|
||||||
|
@ -289,8 +290,8 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnescapeHexCharsHtml() {
|
public void testUnescapeHexCharsHtml() {
|
||||||
// Simple easy to grok test
|
// Simple easy to grok test
|
||||||
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
|
assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape");
|
||||||
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
|
assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape");
|
||||||
// Test all Character values:
|
// Test all Character values:
|
||||||
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
|
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
|
||||||
final Character c1 = new Character(i);
|
final Character c1 = new Character(i);
|
||||||
|
@ -298,7 +299,7 @@ public class StringEscapeUtilsTest {
|
||||||
final String expected = c1.toString() + c2.toString();
|
final String expected = c1.toString() + c2.toString();
|
||||||
final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";";
|
final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";";
|
||||||
final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";";
|
final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";";
|
||||||
assertEquals("hex number unescape index " + (int)i, expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2));
|
assertEquals(expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2), "hex number unescape index " + (int)i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,16 +321,14 @@ public class StringEscapeUtilsTest {
|
||||||
assertEquals("<abc>", StringEscapeUtils.escapeXml("<abc>"));
|
assertEquals("<abc>", StringEscapeUtils.escapeXml("<abc>"));
|
||||||
assertEquals("<abc>", StringEscapeUtils.unescapeXml("<abc>"));
|
assertEquals("<abc>", StringEscapeUtils.unescapeXml("<abc>"));
|
||||||
|
|
||||||
assertEquals("XML should not escape >0x7f values",
|
assertEquals("\u00A1", StringEscapeUtils.escapeXml("\u00A1"), "XML should not escape >0x7f values");
|
||||||
"\u00A1", StringEscapeUtils.escapeXml("\u00A1"));
|
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "), "XML should be able to unescape >0x7f values");
|
||||||
assertEquals("XML should be able to unescape >0x7f values",
|
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "),
|
||||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
"XML should be able to unescape >0x7f values with one leading 0");
|
||||||
assertEquals("XML should be able to unescape >0x7f values with one leading 0",
|
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "),
|
||||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
"XML should be able to unescape >0x7f values with two leading 0s");
|
||||||
assertEquals("XML should be able to unescape >0x7f values with two leading 0s",
|
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "),
|
||||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
"XML should be able to unescape >0x7f values with three leading 0s");
|
||||||
assertEquals("XML should be able to unescape >0x7f values with three leading 0s",
|
|
||||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
|
||||||
|
|
||||||
assertEquals("ain't", StringEscapeUtils.unescapeXml("ain't"));
|
assertEquals("ain't", StringEscapeUtils.unescapeXml("ain't"));
|
||||||
assertEquals("ain't", StringEscapeUtils.escapeXml("ain't"));
|
assertEquals("ain't", StringEscapeUtils.escapeXml("ain't"));
|
||||||
|
@ -342,46 +341,46 @@ public class StringEscapeUtilsTest {
|
||||||
StringEscapeUtils.ESCAPE_XML.translate("<abc>", sw);
|
StringEscapeUtils.ESCAPE_XML.translate("<abc>", sw);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
}
|
}
|
||||||
assertEquals("XML was escaped incorrectly", "<abc>", sw.toString() );
|
assertEquals("<abc>", sw.toString(), "XML was escaped incorrectly");
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
try {
|
try {
|
||||||
StringEscapeUtils.UNESCAPE_XML.translate("<abc>", sw);
|
StringEscapeUtils.UNESCAPE_XML.translate("<abc>", sw);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
}
|
}
|
||||||
assertEquals("XML was unescaped incorrectly", "<abc>", sw.toString() );
|
assertEquals("<abc>", sw.toString(), "XML was unescaped incorrectly");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeXml10() throws Exception {
|
public void testEscapeXml10() throws Exception {
|
||||||
assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml10("a<b>c\"d'e&f"));
|
assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml10("a<b>c\"d'e&f"));
|
||||||
assertEquals("XML 1.0 should not escape \t \n \r",
|
assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd"), "XML 1.0 should not escape \t \n \r");
|
||||||
"a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd"));
|
assertEquals("ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb"),
|
||||||
assertEquals("XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19",
|
"XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19");
|
||||||
"ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb"));
|
assertEquals("a\ud7ff \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b"),
|
||||||
assertEquals("XML 1.0 should omit #xd800-#xdfff",
|
"XML 1.0 should omit #xd800-#xdfff");
|
||||||
"a\ud7ff \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b"));
|
assertEquals("a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb"),
|
||||||
assertEquals("XML 1.0 should omit #xfffe | #xffff",
|
"XML 1.0 should omit #xfffe | #xffff");
|
||||||
"a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb"));
|
assertEquals("a\u007e„\u0085†Ÿ\u00a0b",
|
||||||
assertEquals("XML 1.0 should escape #x7f-#x84 | #x86 - #x9f, for XML 1.1 compatibility",
|
StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"),
|
||||||
"a\u007e„\u0085†Ÿ\u00a0b", StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"));
|
"XML 1.0 should escape #x7f-#x84 | #x86 - #x9f, for XML 1.1 compatibility");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeXml11() throws Exception {
|
public void testEscapeXml11() throws Exception {
|
||||||
assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml11("a<b>c\"d'e&f"));
|
assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml11("a<b>c\"d'e&f"));
|
||||||
assertEquals("XML 1.1 should not escape \t \n \r",
|
assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"), "XML 1.1 should not escape \t \n \r");
|
||||||
"a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"));
|
assertEquals("ab", StringEscapeUtils.escapeXml11("a\u0000b"), "XML 1.1 should omit #x0");
|
||||||
assertEquals("XML 1.1 should omit #x0",
|
assertEquals("ab",
|
||||||
"ab", StringEscapeUtils.escapeXml11("a\u0000b"));
|
StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"),
|
||||||
assertEquals("XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19",
|
"XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19");
|
||||||
"ab", StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"));
|
assertEquals("a\u007e„\u0085†Ÿ\u00a0b",
|
||||||
assertEquals("XML 1.1 should escape #x7F-#x84 | #x86-#x9F",
|
StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"),
|
||||||
"a\u007e„\u0085†Ÿ\u00a0b", StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"));
|
"XML 1.1 should escape #x7F-#x84 | #x86-#x9F");
|
||||||
assertEquals("XML 1.1 should omit #xd800-#xdfff",
|
assertEquals("a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"),
|
||||||
"a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"));
|
"XML 1.1 should omit #xd800-#xdfff");
|
||||||
assertEquals("XML 1.1 should omit #xfffe | #xffff",
|
assertEquals("a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb"),
|
||||||
"a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb"));
|
"XML 1.1 should omit #xfffe | #xffff");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -404,11 +403,11 @@ public class StringEscapeUtilsTest {
|
||||||
final CharSequenceTranslator escapeXml =
|
final CharSequenceTranslator escapeXml =
|
||||||
StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );
|
StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );
|
||||||
|
|
||||||
assertEquals("Supplementary character must be represented using a single escape", "𣎴",
|
assertEquals("𣎴", escapeXml.translate("\uD84C\uDFB4"),
|
||||||
escapeXml.translate("\uD84C\uDFB4"));
|
"Supplementary character must be represented using a single escape");
|
||||||
|
|
||||||
assertEquals("Supplementary characters mixed with basic characters should be encoded correctly", "a b c 𣎴",
|
assertEquals("a b c 𣎴", escapeXml.translate("a b c \uD84C\uDFB4"),
|
||||||
escapeXml.translate("a b c \uD84C\uDFB4"));
|
"Supplementary characters mixed with basic characters should be encoded correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -436,11 +435,11 @@ public class StringEscapeUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUnescapeXmlSupplementaryCharacters() {
|
public void testUnescapeXmlSupplementaryCharacters() {
|
||||||
assertEquals("Supplementary character must be represented using a single escape", "\uD84C\uDFB4",
|
assertEquals("\uD84C\uDFB4", StringEscapeUtils.unescapeXml("𣎴"),
|
||||||
StringEscapeUtils.unescapeXml("𣎴") );
|
"Supplementary character must be represented using a single escape");
|
||||||
|
|
||||||
assertEquals("Supplementary characters mixed with basic characters should be decoded correctly", "a b c \uD84C\uDFB4",
|
assertEquals("a b c \uD84C\uDFB4", StringEscapeUtils.unescapeXml("a b c 𣎴"),
|
||||||
StringEscapeUtils.unescapeXml("a b c 𣎴") );
|
"Supplementary characters mixed with basic characters should be decoded correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests issue #38569
|
// Tests issue #38569
|
||||||
|
@ -492,10 +491,10 @@ public class StringEscapeUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test
|
||||||
public void testEscapeCsvIllegalStateException() throws IOException {
|
public void testEscapeCsvIllegalStateException() {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
StringEscapeUtils.ESCAPE_CSV.translate("foo", -1, writer);
|
assertThrows(IllegalStateException.class, () -> StringEscapeUtils.ESCAPE_CSV.translate("foo", -1, writer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -536,10 +535,10 @@ public class StringEscapeUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test
|
||||||
public void testUnescapeCsvIllegalStateException() throws IOException {
|
public void testUnescapeCsvIllegalStateException() {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
StringEscapeUtils.UNESCAPE_CSV.translate("foo", -1, writer);
|
assertThrows(IllegalStateException.class, () -> StringEscapeUtils.UNESCAPE_CSV.translate("foo", -1, writer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -556,10 +555,10 @@ public class StringEscapeUtilsTest {
|
||||||
final String original = new String(data, Charset.forName("UTF8"));
|
final String original = new String(data, Charset.forName("UTF8"));
|
||||||
|
|
||||||
final String escaped = StringEscapeUtils.escapeHtml4( original );
|
final String escaped = StringEscapeUtils.escapeHtml4( original );
|
||||||
assertEquals( "High Unicode should not have been escaped", original, escaped);
|
assertEquals(original, escaped, "High Unicode should not have been escaped");
|
||||||
|
|
||||||
final String unescaped = StringEscapeUtils.unescapeHtml4( escaped );
|
final String unescaped = StringEscapeUtils.unescapeHtml4( escaped );
|
||||||
assertEquals( "High Unicode should have been unchanged", original, unescaped);
|
assertEquals(original, unescaped, "High Unicode should have been unchanged");
|
||||||
|
|
||||||
// TODO: I think this should hold, needs further investigation
|
// TODO: I think this should hold, needs further investigation
|
||||||
// String unescapedFromEntity = StringEscapeUtils.unescapeHtml4( "𝍢" );
|
// String unescapedFromEntity = StringEscapeUtils.unescapeHtml4( "𝍢" );
|
||||||
|
@ -574,12 +573,12 @@ public class StringEscapeUtilsTest {
|
||||||
// Some random Japanese Unicode characters
|
// Some random Japanese Unicode characters
|
||||||
final String original = "\u304B\u304C\u3068";
|
final String original = "\u304B\u304C\u3068";
|
||||||
final String escaped = StringEscapeUtils.escapeHtml4(original);
|
final String escaped = StringEscapeUtils.escapeHtml4(original);
|
||||||
assertEquals( "Hiragana character Unicode behaviour should not be being escaped by escapeHtml4",
|
assertEquals(original, escaped,
|
||||||
original, escaped);
|
"Hiragana character Unicode behaviour should not be being escaped by escapeHtml4");
|
||||||
|
|
||||||
final String unescaped = StringEscapeUtils.unescapeHtml4( escaped );
|
final String unescaped = StringEscapeUtils.unescapeHtml4( escaped );
|
||||||
|
|
||||||
assertEquals( "Hiragana character Unicode behaviour has changed - expected no unescaping", escaped, unescaped);
|
assertEquals(escaped, unescaped, "Hiragana character Unicode behaviour has changed - expected no unescaping");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -594,9 +593,9 @@ public class StringEscapeUtilsTest {
|
||||||
final String input = new String(inputBytes, StandardCharsets.UTF_8);
|
final String input = new String(inputBytes, StandardCharsets.UTF_8);
|
||||||
final String escaped = StringEscapeUtils.escapeEcmaScript(input);
|
final String escaped = StringEscapeUtils.escapeEcmaScript(input);
|
||||||
// just the end:
|
// just the end:
|
||||||
assertTrue(escaped, escaped.endsWith("}]"));
|
assertTrue(escaped.endsWith("}]"), escaped);
|
||||||
// a little more:
|
// a little more:
|
||||||
assertTrue(escaped, escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"));
|
assertTrue(escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"), escaped);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,25 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.apache.commons.lang3.test.SystemDefaults;
|
import org.junitpioneer.jupiter.DefaultLocale;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Contains methods
|
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Contains methods
|
||||||
*/
|
*/
|
||||||
public class StringUtilsContainsTest {
|
public class StringUtilsContainsTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supplementary character U+20000
|
* Supplementary character U+20000
|
||||||
* See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html
|
* See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html
|
||||||
|
@ -233,7 +227,7 @@ public class StringUtilsContainsTest {
|
||||||
assertTrue(StringUtils.containsAny("abc", "d", "abc"));
|
assertTrue(StringUtils.containsAny("abc", "d", "abc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SystemDefaults(locale="de_DE")
|
@DefaultLocale(language = "de", country = "DE")
|
||||||
@Test
|
@Test
|
||||||
public void testContainsIgnoreCase_LocaleIndependence() {
|
public void testContainsIgnoreCase_LocaleIndependence() {
|
||||||
final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
|
final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
|
||||||
|
@ -253,12 +247,12 @@ public class StringUtilsContainsTest {
|
||||||
for (final Locale testLocale : locales) {
|
for (final Locale testLocale : locales) {
|
||||||
Locale.setDefault(testLocale);
|
Locale.setDefault(testLocale);
|
||||||
for (int j = 0; j < tdata.length; j++) {
|
for (int j = 0; j < tdata.length; j++) {
|
||||||
assertTrue(Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1], StringUtils
|
assertTrue(StringUtils.containsIgnoreCase(tdata[j][0], tdata[j][1]),
|
||||||
.containsIgnoreCase(tdata[j][0], tdata[j][1]));
|
Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1]);
|
||||||
}
|
}
|
||||||
for (int j = 0; j < fdata.length; j++) {
|
for (int j = 0; j < fdata.length; j++) {
|
||||||
assertFalse(Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1], StringUtils
|
assertFalse(StringUtils.containsIgnoreCase(fdata[j][0], fdata[j][1]),
|
||||||
.containsIgnoreCase(fdata[j][0], fdata[j][1]));
|
Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Empty/Blank methods
|
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Empty/Blank methods
|
||||||
|
|
|
@ -16,26 +16,20 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
|
||||||
import org.hamcrest.core.IsNot;
|
import org.hamcrest.core.IsNot;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Equals/IndexOf methods
|
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Equals/IndexOf methods
|
||||||
*/
|
*/
|
||||||
public class StringUtilsEqualsIndexOfTest {
|
public class StringUtilsEqualsIndexOfTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
|
||||||
|
|
||||||
private static final String BAR = "bar";
|
private static final String BAR = "bar";
|
||||||
/**
|
/**
|
||||||
* Supplementary character U+20000
|
* Supplementary character U+20000
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - IsX methods
|
* Unit tests {@link org.apache.commons.lang3.StringUtils} - IsX methods
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,23 +40,23 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStartsWith() {
|
public void testStartsWith() {
|
||||||
assertTrue("startsWith(null, null)", StringUtils.startsWith(null, null));
|
assertTrue(StringUtils.startsWith(null, null), "startsWith(null, null)");
|
||||||
assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, null));
|
assertFalse(StringUtils.startsWith(FOOBAR, null), "startsWith(FOOBAR, null)");
|
||||||
assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null, FOO));
|
assertFalse(StringUtils.startsWith(null, FOO), "startsWith(null, FOO)");
|
||||||
assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR, ""));
|
assertTrue(StringUtils.startsWith(FOOBAR, ""), "startsWith(FOOBAR, \"\")");
|
||||||
|
|
||||||
assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar, foo));
|
assertTrue(StringUtils.startsWith(foobar, foo), "startsWith(foobar, foo)");
|
||||||
assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR, FOO));
|
assertTrue(StringUtils.startsWith(FOOBAR, FOO), "startsWith(FOOBAR, FOO)");
|
||||||
assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar, FOO));
|
assertFalse(StringUtils.startsWith(foobar, FOO), "startsWith(foobar, FOO)");
|
||||||
assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR, foo));
|
assertFalse(StringUtils.startsWith(FOOBAR, foo), "startsWith(FOOBAR, foo)");
|
||||||
|
|
||||||
assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo, foobar));
|
assertFalse(StringUtils.startsWith(foo, foobar), "startsWith(foo, foobar)");
|
||||||
assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar, foobar));
|
assertFalse(StringUtils.startsWith(bar, foobar), "startsWith(foo, foobar)");
|
||||||
|
|
||||||
assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar, bar));
|
assertFalse(StringUtils.startsWith(foobar, bar), "startsWith(foobar, bar)");
|
||||||
assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR, BAR));
|
assertFalse(StringUtils.startsWith(FOOBAR, BAR), "startsWith(FOOBAR, BAR)");
|
||||||
assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar, BAR));
|
assertFalse(StringUtils.startsWith(foobar, BAR), "startsWith(foobar, BAR)");
|
||||||
assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR, bar));
|
assertFalse(StringUtils.startsWith(FOOBAR, bar), "startsWith(FOOBAR, bar)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,23 +64,23 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStartsWithIgnoreCase() {
|
public void testStartsWithIgnoreCase() {
|
||||||
assertTrue("startsWithIgnoreCase(null, null)", StringUtils.startsWithIgnoreCase(null, null));
|
assertTrue(StringUtils.startsWithIgnoreCase(null, null), "startsWithIgnoreCase(null, null)");
|
||||||
assertFalse("startsWithIgnoreCase(FOOBAR, null)", StringUtils.startsWithIgnoreCase(FOOBAR, null));
|
assertFalse(StringUtils.startsWithIgnoreCase(FOOBAR, null), "startsWithIgnoreCase(FOOBAR, null)");
|
||||||
assertFalse("startsWithIgnoreCase(null, FOO)", StringUtils.startsWithIgnoreCase(null, FOO));
|
assertFalse(StringUtils.startsWithIgnoreCase(null, FOO), "startsWithIgnoreCase(null, FOO)");
|
||||||
assertTrue("startsWithIgnoreCase(FOOBAR, \"\")", StringUtils.startsWithIgnoreCase(FOOBAR, ""));
|
assertTrue(StringUtils.startsWithIgnoreCase(FOOBAR, ""), "startsWithIgnoreCase(FOOBAR, \"\")");
|
||||||
|
|
||||||
assertTrue("startsWithIgnoreCase(foobar, foo)", StringUtils.startsWithIgnoreCase(foobar, foo));
|
assertTrue(StringUtils.startsWithIgnoreCase(foobar, foo), "startsWithIgnoreCase(foobar, foo)");
|
||||||
assertTrue("startsWithIgnoreCase(FOOBAR, FOO)", StringUtils.startsWithIgnoreCase(FOOBAR, FOO));
|
assertTrue(StringUtils.startsWithIgnoreCase(FOOBAR, FOO), "startsWithIgnoreCase(FOOBAR, FOO)");
|
||||||
assertTrue("startsWithIgnoreCase(foobar, FOO)", StringUtils.startsWithIgnoreCase(foobar, FOO));
|
assertTrue(StringUtils.startsWithIgnoreCase(foobar, FOO), "startsWithIgnoreCase(foobar, FOO)");
|
||||||
assertTrue("startsWithIgnoreCase(FOOBAR, foo)", StringUtils.startsWithIgnoreCase(FOOBAR, foo));
|
assertTrue(StringUtils.startsWithIgnoreCase(FOOBAR, foo), "startsWithIgnoreCase(FOOBAR, foo)");
|
||||||
|
|
||||||
assertFalse("startsWithIgnoreCase(foo, foobar)", StringUtils.startsWithIgnoreCase(foo, foobar));
|
assertFalse(StringUtils.startsWithIgnoreCase(foo, foobar), "startsWithIgnoreCase(foo, foobar)");
|
||||||
assertFalse("startsWithIgnoreCase(foo, foobar)", StringUtils.startsWithIgnoreCase(bar, foobar));
|
assertFalse(StringUtils.startsWithIgnoreCase(bar, foobar), "startsWithIgnoreCase(foo, foobar)");
|
||||||
|
|
||||||
assertFalse("startsWithIgnoreCase(foobar, bar)", StringUtils.startsWithIgnoreCase(foobar, bar));
|
assertFalse(StringUtils.startsWithIgnoreCase(foobar, bar), "startsWithIgnoreCase(foobar, bar)");
|
||||||
assertFalse("startsWithIgnoreCase(FOOBAR, BAR)", StringUtils.startsWithIgnoreCase(FOOBAR, BAR));
|
assertFalse(StringUtils.startsWithIgnoreCase(FOOBAR, BAR), "startsWithIgnoreCase(FOOBAR, BAR)");
|
||||||
assertFalse("startsWithIgnoreCase(foobar, BAR)", StringUtils.startsWithIgnoreCase(foobar, BAR));
|
assertFalse(StringUtils.startsWithIgnoreCase(foobar, BAR), "startsWithIgnoreCase(foobar, BAR)");
|
||||||
assertFalse("startsWithIgnoreCase(FOOBAR, bar)", StringUtils.startsWithIgnoreCase(FOOBAR, bar));
|
assertFalse(StringUtils.startsWithIgnoreCase(FOOBAR, bar), "startsWithIgnoreCase(FOOBAR, bar)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -96,8 +96,8 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
assertFalse(StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX"));
|
assertFalse(StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX"));
|
||||||
assertFalse(StringUtils.startsWithAny("ABCXYZ", null, "xyz", "abc"));
|
assertFalse(StringUtils.startsWithAny("ABCXYZ", null, "xyz", "abc"));
|
||||||
|
|
||||||
assertTrue("StringUtils.startsWithAny(abcxyz, StringBuilder(xyz), StringBuffer(abc))", StringUtils.startsWithAny("abcxyz", new StringBuilder("xyz"), new StringBuffer("abc")));
|
assertTrue(StringUtils.startsWithAny("abcxyz", new StringBuilder("xyz"), new StringBuffer("abc")), "StringUtils.startsWithAny(abcxyz, StringBuilder(xyz), StringBuffer(abc))");
|
||||||
assertTrue("StringUtils.startsWithAny(StringBuffer(abcxyz), StringBuilder(xyz), StringBuffer(abc))", StringUtils.startsWithAny(new StringBuffer("abcxyz"), new StringBuilder("xyz"), new StringBuffer("abc")));
|
assertTrue(StringUtils.startsWithAny(new StringBuffer("abcxyz"), new StringBuilder("xyz"), new StringBuffer("abc")), "StringUtils.startsWithAny(StringBuffer(abcxyz), StringBuilder(xyz), StringBuffer(abc))");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,30 +106,30 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEndsWith() {
|
public void testEndsWith() {
|
||||||
assertTrue("endsWith(null, null)", StringUtils.endsWith(null, null));
|
assertTrue(StringUtils.endsWith(null, null), "endsWith(null, null)");
|
||||||
assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR, null));
|
assertFalse(StringUtils.endsWith(FOOBAR, null), "endsWith(FOOBAR, null)");
|
||||||
assertFalse("endsWith(null, FOO)", StringUtils.endsWith(null, FOO));
|
assertFalse(StringUtils.endsWith(null, FOO), "endsWith(null, FOO)");
|
||||||
assertTrue("endsWith(FOOBAR, \"\")", StringUtils.endsWith(FOOBAR, ""));
|
assertTrue(StringUtils.endsWith(FOOBAR, ""), "endsWith(FOOBAR, \"\")");
|
||||||
|
|
||||||
assertFalse("endsWith(foobar, foo)", StringUtils.endsWith(foobar, foo));
|
assertFalse(StringUtils.endsWith(foobar, foo), "endsWith(foobar, foo)");
|
||||||
assertFalse("endsWith(FOOBAR, FOO)", StringUtils.endsWith(FOOBAR, FOO));
|
assertFalse(StringUtils.endsWith(FOOBAR, FOO), "endsWith(FOOBAR, FOO)");
|
||||||
assertFalse("endsWith(foobar, FOO)", StringUtils.endsWith(foobar, FOO));
|
assertFalse(StringUtils.endsWith(foobar, FOO), "endsWith(foobar, FOO)");
|
||||||
assertFalse("endsWith(FOOBAR, foo)", StringUtils.endsWith(FOOBAR, foo));
|
assertFalse(StringUtils.endsWith(FOOBAR, foo), "endsWith(FOOBAR, foo)");
|
||||||
|
|
||||||
assertFalse("endsWith(foo, foobar)", StringUtils.endsWith(foo, foobar));
|
assertFalse(StringUtils.endsWith(foo, foobar), "endsWith(foo, foobar)");
|
||||||
assertFalse("endsWith(foo, foobar)", StringUtils.endsWith(bar, foobar));
|
assertFalse(StringUtils.endsWith(bar, foobar), "endsWith(foo, foobar)");
|
||||||
|
|
||||||
assertTrue("endsWith(foobar, bar)", StringUtils.endsWith(foobar, bar));
|
assertTrue(StringUtils.endsWith(foobar, bar), "endsWith(foobar, bar)");
|
||||||
assertTrue("endsWith(FOOBAR, BAR)", StringUtils.endsWith(FOOBAR, BAR));
|
assertTrue(StringUtils.endsWith(FOOBAR, BAR), "endsWith(FOOBAR, BAR)");
|
||||||
assertFalse("endsWith(foobar, BAR)", StringUtils.endsWith(foobar, BAR));
|
assertFalse(StringUtils.endsWith(foobar, BAR), "endsWith(foobar, BAR)");
|
||||||
assertFalse("endsWith(FOOBAR, bar)", StringUtils.endsWith(FOOBAR, bar));
|
assertFalse(StringUtils.endsWith(FOOBAR, bar), "endsWith(FOOBAR, bar)");
|
||||||
|
|
||||||
// "alpha,beta,gamma,delta".endsWith("delta")
|
// "alpha,beta,gamma,delta".endsWith("delta")
|
||||||
assertTrue("endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B4)",
|
assertTrue(StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B4"),
|
||||||
StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B4"));
|
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B4)");
|
||||||
// "alpha,beta,gamma,delta".endsWith("gamma,DELTA")
|
// "alpha,beta,gamma,delta".endsWith("gamma,DELTA")
|
||||||
assertFalse("endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B3\u0394)",
|
assertFalse(StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B3\u0394"),
|
||||||
StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B3\u0394"));
|
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B3\u0394)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,23 +137,23 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEndsWithIgnoreCase() {
|
public void testEndsWithIgnoreCase() {
|
||||||
assertTrue("endsWithIgnoreCase(null, null)", StringUtils.endsWithIgnoreCase(null, null));
|
assertTrue(StringUtils.endsWithIgnoreCase(null, null), "endsWithIgnoreCase(null, null)");
|
||||||
assertFalse("endsWithIgnoreCase(FOOBAR, null)", StringUtils.endsWithIgnoreCase(FOOBAR, null));
|
assertFalse(StringUtils.endsWithIgnoreCase(FOOBAR, null), "endsWithIgnoreCase(FOOBAR, null)");
|
||||||
assertFalse("endsWithIgnoreCase(null, FOO)", StringUtils.endsWithIgnoreCase(null, FOO));
|
assertFalse(StringUtils.endsWithIgnoreCase(null, FOO), "endsWithIgnoreCase(null, FOO)");
|
||||||
assertTrue("endsWithIgnoreCase(FOOBAR, \"\")", StringUtils.endsWithIgnoreCase(FOOBAR, ""));
|
assertTrue(StringUtils.endsWithIgnoreCase(FOOBAR, ""), "endsWithIgnoreCase(FOOBAR, \"\")");
|
||||||
|
|
||||||
assertFalse("endsWithIgnoreCase(foobar, foo)", StringUtils.endsWithIgnoreCase(foobar, foo));
|
assertFalse(StringUtils.endsWithIgnoreCase(foobar, foo), "endsWithIgnoreCase(foobar, foo)");
|
||||||
assertFalse("endsWithIgnoreCase(FOOBAR, FOO)", StringUtils.endsWithIgnoreCase(FOOBAR, FOO));
|
assertFalse(StringUtils.endsWithIgnoreCase(FOOBAR, FOO), "endsWithIgnoreCase(FOOBAR, FOO)");
|
||||||
assertFalse("endsWithIgnoreCase(foobar, FOO)", StringUtils.endsWithIgnoreCase(foobar, FOO));
|
assertFalse(StringUtils.endsWithIgnoreCase(foobar, FOO), "endsWithIgnoreCase(foobar, FOO)");
|
||||||
assertFalse("endsWithIgnoreCase(FOOBAR, foo)", StringUtils.endsWithIgnoreCase(FOOBAR, foo));
|
assertFalse(StringUtils.endsWithIgnoreCase(FOOBAR, foo), "endsWithIgnoreCase(FOOBAR, foo)");
|
||||||
|
|
||||||
assertFalse("endsWithIgnoreCase(foo, foobar)", StringUtils.endsWithIgnoreCase(foo, foobar));
|
assertFalse(StringUtils.endsWithIgnoreCase(foo, foobar), "endsWithIgnoreCase(foo, foobar)");
|
||||||
assertFalse("endsWithIgnoreCase(foo, foobar)", StringUtils.endsWithIgnoreCase(bar, foobar));
|
assertFalse(StringUtils.endsWithIgnoreCase(bar, foobar), "endsWithIgnoreCase(foo, foobar)");
|
||||||
|
|
||||||
assertTrue("endsWithIgnoreCase(foobar, bar)", StringUtils.endsWithIgnoreCase(foobar, bar));
|
assertTrue(StringUtils.endsWithIgnoreCase(foobar, bar), "endsWithIgnoreCase(foobar, bar)");
|
||||||
assertTrue("endsWithIgnoreCase(FOOBAR, BAR)", StringUtils.endsWithIgnoreCase(FOOBAR, BAR));
|
assertTrue(StringUtils.endsWithIgnoreCase(FOOBAR, BAR), "endsWithIgnoreCase(FOOBAR, BAR)");
|
||||||
assertTrue("endsWithIgnoreCase(foobar, BAR)", StringUtils.endsWithIgnoreCase(foobar, BAR));
|
assertTrue(StringUtils.endsWithIgnoreCase(foobar, BAR), "endsWithIgnoreCase(foobar, BAR)");
|
||||||
assertTrue("endsWithIgnoreCase(FOOBAR, bar)", StringUtils.endsWithIgnoreCase(FOOBAR, bar));
|
assertTrue(StringUtils.endsWithIgnoreCase(FOOBAR, bar), "endsWithIgnoreCase(FOOBAR, bar)");
|
||||||
|
|
||||||
// javadoc
|
// javadoc
|
||||||
assertTrue(StringUtils.endsWithIgnoreCase("abcdef", "def"));
|
assertTrue(StringUtils.endsWithIgnoreCase("abcdef", "def"));
|
||||||
|
@ -161,22 +161,22 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
assertFalse(StringUtils.endsWithIgnoreCase("ABCDEF", "cde"));
|
assertFalse(StringUtils.endsWithIgnoreCase("ABCDEF", "cde"));
|
||||||
|
|
||||||
// "alpha,beta,gamma,delta".endsWith("DELTA")
|
// "alpha,beta,gamma,delta".endsWith("DELTA")
|
||||||
assertTrue("endsWith(\u03B1\u03B2\u03B3\u03B4, \u0394)",
|
assertTrue(StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0394"),
|
||||||
StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0394"));
|
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u0394)");
|
||||||
// "alpha,beta,gamma,delta".endsWith("GAMMA")
|
// "alpha,beta,gamma,delta".endsWith("GAMMA")
|
||||||
assertFalse("endsWith(\u03B1\u03B2\u03B3\u03B4, \u0393)",
|
assertFalse(StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0393"),
|
||||||
StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0393"));
|
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u0393)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEndsWithAny() {
|
public void testEndsWithAny() {
|
||||||
assertFalse("StringUtils.endsWithAny(null, null)", StringUtils.endsWithAny(null, (String)null));
|
assertFalse(StringUtils.endsWithAny(null, (String)null), "StringUtils.endsWithAny(null, null)");
|
||||||
assertFalse("StringUtils.endsWithAny(null, new String[] {abc})", StringUtils.endsWithAny(null, new String[] {"abc"}));
|
assertFalse(StringUtils.endsWithAny(null, new String[] {"abc"}), "StringUtils.endsWithAny(null, new String[] {abc})");
|
||||||
assertFalse("StringUtils.endsWithAny(abcxyz, null)", StringUtils.endsWithAny("abcxyz", (String)null));
|
assertFalse(StringUtils.endsWithAny("abcxyz", (String)null), "StringUtils.endsWithAny(abcxyz, null)");
|
||||||
assertTrue("StringUtils.endsWithAny(abcxyz, new String[] {\"\"})", StringUtils.endsWithAny("abcxyz", new String[] {""}));
|
assertTrue(StringUtils.endsWithAny("abcxyz", new String[] {""}), "StringUtils.endsWithAny(abcxyz, new String[] {\"\"})");
|
||||||
assertTrue("StringUtils.endsWithAny(abcxyz, new String[] {xyz})", StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}));
|
assertTrue(StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}), "StringUtils.endsWithAny(abcxyz, new String[] {xyz})");
|
||||||
assertTrue("StringUtils.endsWithAny(abcxyz, new String[] {null, xyz, abc})", StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}));
|
assertTrue(StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}), "StringUtils.endsWithAny(abcxyz, new String[] {null, xyz, abc})");
|
||||||
assertFalse("StringUtils.endsWithAny(defg, new String[] {null, xyz, abc})", StringUtils.endsWithAny("defg", new String[] {null, "xyz", "abc"}));
|
assertFalse(StringUtils.endsWithAny("defg", new String[] {null, "xyz", "abc"}), "StringUtils.endsWithAny(defg, new String[] {null, xyz, abc})");
|
||||||
assertTrue(StringUtils.endsWithAny("abcXYZ", "def", "XYZ"));
|
assertTrue(StringUtils.endsWithAny("abcXYZ", "def", "XYZ"));
|
||||||
assertFalse(StringUtils.endsWithAny("abcXYZ", "def", "xyz"));
|
assertFalse(StringUtils.endsWithAny("abcXYZ", "def", "xyz"));
|
||||||
assertTrue(StringUtils.endsWithAny("abcXYZ", "def", "YZ"));
|
assertTrue(StringUtils.endsWithAny("abcXYZ", "def", "YZ"));
|
||||||
|
@ -193,8 +193,8 @@ public class StringUtilsStartsEndsWithTest {
|
||||||
assertFalse(StringUtils.endsWithAny("abcXYZ", (CharSequence[]) null));
|
assertFalse(StringUtils.endsWithAny("abcXYZ", (CharSequence[]) null));
|
||||||
assertTrue(StringUtils.endsWithAny("abcXYZ", ""));
|
assertTrue(StringUtils.endsWithAny("abcXYZ", ""));
|
||||||
|
|
||||||
assertTrue("StringUtils.endsWithAny(abcxyz, StringBuilder(abc), StringBuffer(xyz))", StringUtils.endsWithAny("abcxyz", new StringBuilder("abc"), new StringBuffer("xyz")));
|
assertTrue(StringUtils.endsWithAny("abcxyz", new StringBuilder("abc"), new StringBuffer("xyz")), "StringUtils.endsWithAny(abcxyz, StringBuilder(abc), StringBuffer(xyz))");
|
||||||
assertTrue("StringUtils.endsWithAny(StringBuffer(abcxyz), StringBuilder(abc), StringBuffer(xyz))", StringUtils.endsWithAny(new StringBuffer("abcxyz"), new StringBuilder("abc"), new StringBuffer("xyz")));
|
assertTrue(StringUtils.endsWithAny(new StringBuffer("abcxyz"), new StringBuilder("abc"), new StringBuffer("xyz")), "StringUtils.endsWithAny(StringBuffer(abcxyz), StringBuilder(abc), StringBuffer(xyz))");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
|
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
@ -40,7 +41,7 @@ import java.util.Objects;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.WordUtils;
|
import org.apache.commons.lang3.text.WordUtils;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for methods of {@link org.apache.commons.lang3.StringUtils}
|
* Unit tests for methods of {@link org.apache.commons.lang3.StringUtils}
|
||||||
|
@ -135,45 +136,35 @@ public class StringUtilsTest {
|
||||||
public void testUpperCase() {
|
public void testUpperCase() {
|
||||||
assertNull(StringUtils.upperCase(null));
|
assertNull(StringUtils.upperCase(null));
|
||||||
assertNull(StringUtils.upperCase(null, Locale.ENGLISH));
|
assertNull(StringUtils.upperCase(null, Locale.ENGLISH));
|
||||||
assertEquals("upperCase(String) failed",
|
assertEquals("FOO TEST THING", StringUtils.upperCase("fOo test THING"), "upperCase(String) failed");
|
||||||
"FOO TEST THING", StringUtils.upperCase("fOo test THING"));
|
assertEquals("", StringUtils.upperCase(""), "upperCase(empty-string) failed");
|
||||||
assertEquals("upperCase(empty-string) failed",
|
assertEquals("FOO TEST THING", StringUtils.upperCase("fOo test THING", Locale.ENGLISH),
|
||||||
"", StringUtils.upperCase(""));
|
"upperCase(String, Locale) failed");
|
||||||
assertEquals("upperCase(String, Locale) failed",
|
assertEquals("", StringUtils.upperCase("", Locale.ENGLISH),
|
||||||
"FOO TEST THING", StringUtils.upperCase("fOo test THING", Locale.ENGLISH));
|
"upperCase(empty-string, Locale) failed");
|
||||||
assertEquals("upperCase(empty-string, Locale) failed",
|
|
||||||
"", StringUtils.upperCase("", Locale.ENGLISH));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLowerCase() {
|
public void testLowerCase() {
|
||||||
assertNull(StringUtils.lowerCase(null));
|
assertNull(StringUtils.lowerCase(null));
|
||||||
assertNull(StringUtils.lowerCase(null, Locale.ENGLISH));
|
assertNull(StringUtils.lowerCase(null, Locale.ENGLISH));
|
||||||
assertEquals("lowerCase(String) failed",
|
assertEquals("foo test thing", StringUtils.lowerCase("fOo test THING"), "lowerCase(String) failed");
|
||||||
"foo test thing", StringUtils.lowerCase("fOo test THING"));
|
assertEquals("", StringUtils.lowerCase(""), "lowerCase(empty-string) failed");
|
||||||
assertEquals("lowerCase(empty-string) failed",
|
assertEquals("foo test thing", StringUtils.lowerCase("fOo test THING", Locale.ENGLISH),
|
||||||
"", StringUtils.lowerCase(""));
|
"lowerCase(String, Locale) failed");
|
||||||
assertEquals("lowerCase(String, Locale) failed",
|
assertEquals("", StringUtils.lowerCase("", Locale.ENGLISH), "lowerCase(empty-string, Locale) failed");
|
||||||
"foo test thing", StringUtils.lowerCase("fOo test THING", Locale.ENGLISH));
|
|
||||||
assertEquals("lowerCase(empty-string, Locale) failed",
|
|
||||||
"", StringUtils.lowerCase("", Locale.ENGLISH));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCapitalize() {
|
public void testCapitalize() {
|
||||||
assertNull(StringUtils.capitalize(null));
|
assertNull(StringUtils.capitalize(null));
|
||||||
|
|
||||||
assertEquals("capitalize(empty-string) failed",
|
assertEquals("", StringUtils.capitalize(""), "capitalize(empty-string) failed");
|
||||||
"", StringUtils.capitalize(""));
|
assertEquals("X", StringUtils.capitalize("x"), "capitalize(single-char-string) failed");
|
||||||
assertEquals("capitalize(single-char-string) failed",
|
assertEquals(FOO_CAP, StringUtils.capitalize(FOO_CAP), "capitalize(String) failed");
|
||||||
"X", StringUtils.capitalize("x"));
|
assertEquals(FOO_CAP, StringUtils.capitalize(FOO_UNCAP), "capitalize(string) failed");
|
||||||
assertEquals("capitalize(String) failed",
|
|
||||||
FOO_CAP, StringUtils.capitalize(FOO_CAP));
|
|
||||||
assertEquals("capitalize(string) failed",
|
|
||||||
FOO_CAP, StringUtils.capitalize(FOO_UNCAP));
|
|
||||||
|
|
||||||
assertEquals("capitalize(String) is not using TitleCase",
|
assertEquals("\u01C8", StringUtils.capitalize("\u01C9"), "capitalize(String) is not using TitleCase");
|
||||||
"\u01C8", StringUtils.capitalize("\u01C9"));
|
|
||||||
|
|
||||||
// Javadoc examples
|
// Javadoc examples
|
||||||
assertNull(StringUtils.capitalize(null));
|
assertNull(StringUtils.capitalize(null));
|
||||||
|
@ -187,14 +178,10 @@ public class StringUtilsTest {
|
||||||
public void testUnCapitalize() {
|
public void testUnCapitalize() {
|
||||||
assertNull(StringUtils.uncapitalize(null));
|
assertNull(StringUtils.uncapitalize(null));
|
||||||
|
|
||||||
assertEquals("uncapitalize(String) failed",
|
assertEquals(FOO_UNCAP, StringUtils.uncapitalize(FOO_CAP), "uncapitalize(String) failed");
|
||||||
FOO_UNCAP, StringUtils.uncapitalize(FOO_CAP));
|
assertEquals(FOO_UNCAP, StringUtils.uncapitalize(FOO_UNCAP), "uncapitalize(string) failed");
|
||||||
assertEquals("uncapitalize(string) failed",
|
assertEquals("", StringUtils.uncapitalize(""), "uncapitalize(empty-string) failed");
|
||||||
FOO_UNCAP, StringUtils.uncapitalize(FOO_UNCAP));
|
assertEquals("x", StringUtils.uncapitalize("X"), "uncapitalize(single-char-string) failed");
|
||||||
assertEquals("uncapitalize(empty-string) failed",
|
|
||||||
"", StringUtils.uncapitalize(""));
|
|
||||||
assertEquals("uncapitalize(single-char-string) failed",
|
|
||||||
"x", StringUtils.uncapitalize("X"));
|
|
||||||
|
|
||||||
// Examples from uncapitalize Javadoc
|
// Examples from uncapitalize Javadoc
|
||||||
assertEquals("cat", StringUtils.uncapitalize("cat"));
|
assertEquals("cat", StringUtils.uncapitalize("cat"));
|
||||||
|
@ -205,16 +192,16 @@ public class StringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testReCapitalize() {
|
public void testReCapitalize() {
|
||||||
// reflection type of tests: Sentences.
|
// reflection type of tests: Sentences.
|
||||||
assertEquals("uncapitalize(capitalize(String)) failed",
|
assertEquals(SENTENCE_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(SENTENCE_UNCAP)),
|
||||||
SENTENCE_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(SENTENCE_UNCAP)));
|
"uncapitalize(capitalize(String)) failed");
|
||||||
assertEquals("capitalize(uncapitalize(String)) failed",
|
assertEquals(SENTENCE_CAP, StringUtils.capitalize(StringUtils.uncapitalize(SENTENCE_CAP)),
|
||||||
SENTENCE_CAP, StringUtils.capitalize(StringUtils.uncapitalize(SENTENCE_CAP)));
|
"capitalize(uncapitalize(String)) failed");
|
||||||
|
|
||||||
// reflection type of tests: One word.
|
// reflection type of tests: One word.
|
||||||
assertEquals("uncapitalize(capitalize(String)) failed",
|
assertEquals(FOO_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(FOO_UNCAP)),
|
||||||
FOO_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(FOO_UNCAP)));
|
"uncapitalize(capitalize(String)) failed");
|
||||||
assertEquals("capitalize(uncapitalize(String)) failed",
|
assertEquals(FOO_CAP, StringUtils.capitalize(StringUtils.uncapitalize(FOO_CAP)),
|
||||||
FOO_CAP, StringUtils.capitalize(StringUtils.uncapitalize(FOO_CAP)));
|
"capitalize(uncapitalize(String)) failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -470,9 +457,9 @@ public class StringUtilsTest {
|
||||||
assertEquals("ab", StringUtils.joinWith(null, "a", "b"));
|
assertEquals("ab", StringUtils.joinWith(null, "a", "b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testJoinWithThrowsException() {
|
public void testJoinWithThrowsException() {
|
||||||
StringUtils.joinWith(",", (Object[]) null);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.joinWith(",", (Object[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -567,36 +554,36 @@ public class StringUtilsTest {
|
||||||
String[] res;
|
String[] res;
|
||||||
// (str, sepStr)
|
// (str, sepStr)
|
||||||
res = StringUtils.split(str, sepStr);
|
res = StringUtils.split(str, sepStr);
|
||||||
assertEquals(msg, 3, res.length);
|
assertEquals(3, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0]);
|
||||||
assertEquals(msg, "b", res[1]);
|
assertEquals("b", res[1]);
|
||||||
assertEquals(msg, noMatch + "c", res[2]);
|
assertEquals(noMatch + "c", res[2]);
|
||||||
|
|
||||||
final String str2 = separator + "a" + separator;
|
final String str2 = separator + "a" + separator;
|
||||||
res = StringUtils.split(str2, sepStr);
|
res = StringUtils.split(str2, sepStr);
|
||||||
assertEquals(msg, 1, res.length);
|
assertEquals(1, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
|
|
||||||
res = StringUtils.split(str, sepStr, -1);
|
res = StringUtils.split(str, sepStr, -1);
|
||||||
assertEquals(msg, 3, res.length);
|
assertEquals(3, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, "b", res[1]);
|
assertEquals("b", res[1], msg);
|
||||||
assertEquals(msg, noMatch + "c", res[2]);
|
assertEquals(noMatch + "c", res[2], msg);
|
||||||
|
|
||||||
res = StringUtils.split(str, sepStr, 0);
|
res = StringUtils.split(str, sepStr, 0);
|
||||||
assertEquals(msg, 3, res.length);
|
assertEquals(3, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, "b", res[1]);
|
assertEquals("b", res[1], msg);
|
||||||
assertEquals(msg, noMatch + "c", res[2]);
|
assertEquals(noMatch + "c", res[2], msg);
|
||||||
|
|
||||||
res = StringUtils.split(str, sepStr, 1);
|
res = StringUtils.split(str, sepStr, 1);
|
||||||
assertEquals(msg, 1, res.length);
|
assertEquals(1, res.length, msg);
|
||||||
assertEquals(msg, str, res[0]);
|
assertEquals(str, res[0], msg);
|
||||||
|
|
||||||
res = StringUtils.split(str, sepStr, 2);
|
res = StringUtils.split(str, sepStr, 2);
|
||||||
assertEquals(msg, 2, res.length);
|
assertEquals(2, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, str.substring(2), res[1]);
|
assertEquals(str.substring(2), res[1], msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1067,41 +1054,41 @@ public class StringUtilsTest {
|
||||||
String[] res;
|
String[] res;
|
||||||
// (str, sepStr)
|
// (str, sepStr)
|
||||||
res = StringUtils.splitPreserveAllTokens(str, sepStr);
|
res = StringUtils.splitPreserveAllTokens(str, sepStr);
|
||||||
assertEquals(msg, 4, res.length);
|
assertEquals(4, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, "b", res[1]);
|
assertEquals("b", res[1], msg);
|
||||||
assertEquals(msg, "", res[2]);
|
assertEquals("", res[2], msg);
|
||||||
assertEquals(msg, noMatch + "c", res[3]);
|
assertEquals(noMatch + "c", res[3], msg);
|
||||||
|
|
||||||
final String str2 = separator + "a" + separator;
|
final String str2 = separator + "a" + separator;
|
||||||
res = StringUtils.splitPreserveAllTokens(str2, sepStr);
|
res = StringUtils.splitPreserveAllTokens(str2, sepStr);
|
||||||
assertEquals(msg, 3, res.length);
|
assertEquals(3, res.length, msg);
|
||||||
assertEquals(msg, "", res[0]);
|
assertEquals("", res[0], msg);
|
||||||
assertEquals(msg, "a", res[1]);
|
assertEquals("a", res[1], msg);
|
||||||
assertEquals(msg, "", res[2]);
|
assertEquals("", res[2], msg);
|
||||||
|
|
||||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, -1);
|
res = StringUtils.splitPreserveAllTokens(str, sepStr, -1);
|
||||||
assertEquals(msg, 4, res.length);
|
assertEquals(4, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, "b", res[1]);
|
assertEquals("b", res[1], msg);
|
||||||
assertEquals(msg, "", res[2]);
|
assertEquals("", res[2], msg);
|
||||||
assertEquals(msg, noMatch + "c", res[3]);
|
assertEquals(noMatch + "c", res[3], msg);
|
||||||
|
|
||||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, 0);
|
res = StringUtils.splitPreserveAllTokens(str, sepStr, 0);
|
||||||
assertEquals(msg, 4, res.length);
|
assertEquals(4, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, "b", res[1]);
|
assertEquals("b", res[1], msg);
|
||||||
assertEquals(msg, "", res[2]);
|
assertEquals("", res[2], msg);
|
||||||
assertEquals(msg, noMatch + "c", res[3]);
|
assertEquals(noMatch + "c", res[3], msg);
|
||||||
|
|
||||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, 1);
|
res = StringUtils.splitPreserveAllTokens(str, sepStr, 1);
|
||||||
assertEquals(msg, 1, res.length);
|
assertEquals(1, res.length, msg);
|
||||||
assertEquals(msg, str, res[0]);
|
assertEquals(str, res[0], msg);
|
||||||
|
|
||||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, 2);
|
res = StringUtils.splitPreserveAllTokens(str, sepStr, 2);
|
||||||
assertEquals(msg, 2, res.length);
|
assertEquals(2, res.length, msg);
|
||||||
assertEquals(msg, "a", res[0]);
|
assertEquals("a", res[0], msg);
|
||||||
assertEquals(msg, str.substring(2), res[1]);
|
assertEquals(str.substring(2), res[1], msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1635,8 +1622,7 @@ public class StringUtilsTest {
|
||||||
for (final String[] chopCase : chopCases) {
|
for (final String[] chopCase : chopCases) {
|
||||||
final String original = chopCase[0];
|
final String original = chopCase[0];
|
||||||
final String expectedResult = chopCase[1];
|
final String expectedResult = chopCase[1];
|
||||||
assertEquals("chop(String) failed",
|
assertEquals(expectedResult, StringUtils.chop(original), "chop(String) failed");
|
||||||
expectedResult, StringUtils.chop(original));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1664,38 +1650,23 @@ public class StringUtilsTest {
|
||||||
for (final String[] chompCase : chompCases) {
|
for (final String[] chompCase : chompCases) {
|
||||||
final String original = chompCase[0];
|
final String original = chompCase[0];
|
||||||
final String expectedResult = chompCase[1];
|
final String expectedResult = chompCase[1];
|
||||||
assertEquals("chomp(String) failed",
|
assertEquals(expectedResult, StringUtils.chomp(original), "chomp(String) failed");
|
||||||
expectedResult, StringUtils.chomp(original));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals("foo", StringUtils.chomp("foobar", "bar"), "chomp(String, String) failed");
|
||||||
"foo", StringUtils.chomp("foobar", "bar"));
|
assertEquals("foobar", StringUtils.chomp("foobar", "baz"), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals("foo", StringUtils.chomp("foo", "foooo"), "chomp(String, String) failed");
|
||||||
"foobar", StringUtils.chomp("foobar", "baz"));
|
assertEquals("foobar", StringUtils.chomp("foobar", ""), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals("foobar", StringUtils.chomp("foobar", null), "chomp(String, String) failed");
|
||||||
"foo", StringUtils.chomp("foo", "foooo"));
|
assertEquals("", StringUtils.chomp("", "foo"), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals("", StringUtils.chomp("", null), "chomp(String, String) failed");
|
||||||
"foobar", StringUtils.chomp("foobar", ""));
|
assertEquals("", StringUtils.chomp("", ""), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals(null, StringUtils.chomp(null, "foo"), "chomp(String, String) failed");
|
||||||
"foobar", StringUtils.chomp("foobar", null));
|
assertEquals(null, StringUtils.chomp(null, null), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals(null, StringUtils.chomp(null, ""), "chomp(String, String) failed");
|
||||||
"", StringUtils.chomp("", "foo"));
|
assertEquals("", StringUtils.chomp("foo", "foo"), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
assertEquals(" ", StringUtils.chomp(" foo", "foo"), "chomp(String, String) failed");
|
||||||
"", StringUtils.chomp("", null));
|
assertEquals("foo ", StringUtils.chomp("foo ", "foo"), "chomp(String, String) failed");
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
"", StringUtils.chomp("", ""));
|
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
null, StringUtils.chomp(null, "foo"));
|
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
null, StringUtils.chomp(null, null));
|
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
null, StringUtils.chomp(null, ""));
|
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
"", StringUtils.chomp("foo", "foo"));
|
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
" ", StringUtils.chomp(" foo", "foo"));
|
|
||||||
assertEquals("chomp(String, String) failed",
|
|
||||||
"foo ", StringUtils.chomp("foo ", "foo"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -2098,12 +2069,12 @@ public class StringUtilsTest {
|
||||||
final String message = "abbreviate(String,int,int) failed";
|
final String message = "abbreviate(String,int,int) failed";
|
||||||
final String actual = StringUtils.abbreviate(abcdefghijklmno, offset, maxWidth);
|
final String actual = StringUtils.abbreviate(abcdefghijklmno, offset, maxWidth);
|
||||||
if (offset >= 0 && offset < abcdefghijklmno.length()) {
|
if (offset >= 0 && offset < abcdefghijklmno.length()) {
|
||||||
assertTrue(message + " -- should contain offset character",
|
assertTrue(actual.indexOf((char) ('a' + offset)) != -1,
|
||||||
actual.indexOf((char) ('a' + offset)) != -1);
|
message + " -- should contain offset character");
|
||||||
}
|
}
|
||||||
assertTrue(message + " -- should not be greater than maxWidth",
|
assertTrue(actual.length() <= maxWidth,
|
||||||
actual.length() <= maxWidth);
|
message + " -- should not be greater than maxWidth");
|
||||||
assertEquals(message, expected, actual);
|
assertEquals(expected, actual, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2157,12 +2128,12 @@ public class StringUtilsTest {
|
||||||
final String message = "abbreviate(String,String,int,int) failed";
|
final String message = "abbreviate(String,String,int,int) failed";
|
||||||
final String actual = StringUtils.abbreviate(abcdefghijklmno, abbrevMarker, offset, maxWidth);
|
final String actual = StringUtils.abbreviate(abcdefghijklmno, abbrevMarker, offset, maxWidth);
|
||||||
if (offset >= 0 && offset < abcdefghijklmno.length()) {
|
if (offset >= 0 && offset < abcdefghijklmno.length()) {
|
||||||
assertTrue(message + " -- should contain offset character",
|
assertTrue(actual.indexOf((char) ('a' + offset)) != -1,
|
||||||
actual.indexOf((char) ('a' + offset)) != -1);
|
message + " -- should contain offset character");
|
||||||
}
|
}
|
||||||
assertTrue(message + " -- should not be greater than maxWidth",
|
assertTrue(actual.length() <= maxWidth,
|
||||||
actual.length() <= maxWidth);
|
message + " -- should not be greater than maxWidth");
|
||||||
assertEquals(message, expected, actual);
|
assertEquals(expected, actual, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2426,14 +2397,14 @@ public class StringUtilsTest {
|
||||||
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo"));
|
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetLevenshteinDistance_NullString() throws Exception {
|
public void testGetLevenshteinDistance_NullString() {
|
||||||
StringUtils.getLevenshteinDistance("a", null);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance("a", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetLevenshteinDistance_StringNull() throws Exception {
|
public void testGetLevenshteinDistance_StringNull() {
|
||||||
StringUtils.getLevenshteinDistance(null, "a");
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance(null, "a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2500,47 +2471,47 @@ public class StringUtilsTest {
|
||||||
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo", Integer.MAX_VALUE));
|
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo", Integer.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetLevenshteinDistance_NullStringInt() throws Exception {
|
public void testGetLevenshteinDistance_NullStringInt() {
|
||||||
StringUtils.getLevenshteinDistance(null, "a", 0);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance(null, "a", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetLevenshteinDistance_StringNullInt() throws Exception {
|
public void testGetLevenshteinDistance_StringNullInt() {
|
||||||
StringUtils.getLevenshteinDistance("a", null, 0);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance("a", null, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetLevenshteinDistance_StringStringNegativeInt() throws Exception {
|
public void testGetLevenshteinDistance_StringStringNegativeInt() {
|
||||||
StringUtils.getLevenshteinDistance("a", "a", -1);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance("a", "a", -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetJaroWinklerDistance_StringString() {
|
public void testGetJaroWinklerDistance_StringString() {
|
||||||
assertEquals(0.93d, StringUtils.getJaroWinklerDistance("frog", "fog"), 0.0d);
|
assertTrue(0.93d == StringUtils.getJaroWinklerDistance("frog", "fog"));
|
||||||
assertEquals(0.0d, StringUtils.getJaroWinklerDistance("fly", "ant"), 0.0d);
|
assertTrue(0.0d == StringUtils.getJaroWinklerDistance("fly", "ant"));
|
||||||
assertEquals(0.44d, StringUtils.getJaroWinklerDistance("elephant", "hippo"), 0.0d);
|
assertTrue(0.44d == StringUtils.getJaroWinklerDistance("elephant", "hippo"));
|
||||||
assertEquals(0.84d, StringUtils.getJaroWinklerDistance("dwayne", "duane"), 0.0d);
|
assertTrue(0.84d == StringUtils.getJaroWinklerDistance("dwayne", "duane"));
|
||||||
assertEquals(0.93d, StringUtils.getJaroWinklerDistance("ABC Corporation", "ABC Corp"), 0.0d);
|
assertTrue(0.93d == StringUtils.getJaroWinklerDistance("ABC Corporation", "ABC Corp"));
|
||||||
assertEquals(0.95d, StringUtils.getJaroWinklerDistance("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.0d);
|
assertTrue(0.95d == StringUtils.getJaroWinklerDistance("D N H Enterprises Inc", "D & H Enterprises, Inc."));
|
||||||
assertEquals(0.92d, StringUtils.getJaroWinklerDistance("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d);
|
assertTrue(0.92d == StringUtils.getJaroWinklerDistance("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"));
|
||||||
assertEquals(0.88d, StringUtils.getJaroWinklerDistance("PENNSYLVANIA", "PENNCISYLVNIA"), 0.0d);
|
assertTrue(0.88d == StringUtils.getJaroWinklerDistance("PENNSYLVANIA", "PENNCISYLVNIA"));
|
||||||
assertEquals(0.63d, StringUtils.getJaroWinklerDistance("Haus Ingeborg", "Ingeborg Esser"), 0.0d);
|
assertTrue(0.63d == StringUtils.getJaroWinklerDistance("Haus Ingeborg", "Ingeborg Esser"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetJaroWinklerDistance_NullNull() throws Exception {
|
public void testGetJaroWinklerDistance_NullNull() {
|
||||||
StringUtils.getJaroWinklerDistance(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getJaroWinklerDistance(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetJaroWinklerDistance_StringNull() throws Exception {
|
public void testGetJaroWinklerDistance_StringNull() {
|
||||||
StringUtils.getJaroWinklerDistance(" ", null);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getJaroWinklerDistance(" ", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetJaroWinklerDistance_NullString() throws Exception {
|
public void testGetJaroWinklerDistance_NullString() {
|
||||||
StringUtils.getJaroWinklerDistance(null, "clear");
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getJaroWinklerDistance(null, "clear"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2554,24 +2525,24 @@ public class StringUtilsTest {
|
||||||
assertEquals(3, StringUtils.getFuzzyDistance("Apache Software Foundation", "asf", Locale.ENGLISH));
|
assertEquals(3, StringUtils.getFuzzyDistance("Apache Software Foundation", "asf", Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetFuzzyDistance_NullNullNull() throws Exception {
|
public void testGetFuzzyDistance_NullNullNull() {
|
||||||
StringUtils.getFuzzyDistance(null, null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(null, null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetFuzzyDistance_StringNullLoclae() throws Exception {
|
public void testGetFuzzyDistance_StringNullLoclae() {
|
||||||
StringUtils.getFuzzyDistance(" ", null, Locale.ENGLISH);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(" ", null, Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetFuzzyDistance_NullStringLocale() throws Exception {
|
public void testGetFuzzyDistance_NullStringLocale() {
|
||||||
StringUtils.getFuzzyDistance(null, "clear", Locale.ENGLISH);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(null, "clear", Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetFuzzyDistance_StringStringNull() throws Exception {
|
public void testGetFuzzyDistance_StringStringNull() {
|
||||||
StringUtils.getFuzzyDistance(" ", "clear", null);
|
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(" ", "clear", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2663,23 +2634,23 @@ public class StringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveStartIgnoreCase() {
|
public void testRemoveStartIgnoreCase() {
|
||||||
// StringUtils.removeStart("", *) = ""
|
// StringUtils.removeStart("", *) = ""
|
||||||
assertNull("removeStartIgnoreCase(null, null)", StringUtils.removeStartIgnoreCase(null, null));
|
assertNull(StringUtils.removeStartIgnoreCase(null, null), "removeStartIgnoreCase(null, null)");
|
||||||
assertNull("removeStartIgnoreCase(null, \"\")", StringUtils.removeStartIgnoreCase(null, ""));
|
assertNull(StringUtils.removeStartIgnoreCase(null, ""), "removeStartIgnoreCase(null, \"\")");
|
||||||
assertNull("removeStartIgnoreCase(null, \"a\")", StringUtils.removeStartIgnoreCase(null, "a"));
|
assertNull(StringUtils.removeStartIgnoreCase(null, "a"), "removeStartIgnoreCase(null, \"a\")");
|
||||||
|
|
||||||
// StringUtils.removeStart(*, null) = *
|
// StringUtils.removeStart(*, null) = *
|
||||||
assertEquals("removeStartIgnoreCase(\"\", null)", StringUtils.removeStartIgnoreCase("", null), "");
|
assertEquals(StringUtils.removeStartIgnoreCase("", null), "", "removeStartIgnoreCase(\"\", null)");
|
||||||
assertEquals("removeStartIgnoreCase(\"\", \"\")", StringUtils.removeStartIgnoreCase("", ""), "");
|
assertEquals(StringUtils.removeStartIgnoreCase("", ""), "", "removeStartIgnoreCase(\"\", \"\")");
|
||||||
assertEquals("removeStartIgnoreCase(\"\", \"a\")", StringUtils.removeStartIgnoreCase("", "a"), "");
|
assertEquals(StringUtils.removeStartIgnoreCase("", "a"), "", "removeStartIgnoreCase(\"\", \"a\")");
|
||||||
|
|
||||||
// All others:
|
// All others:
|
||||||
assertEquals("removeStartIgnoreCase(\"www.domain.com\", \"www.\")", StringUtils.removeStartIgnoreCase("www.domain.com", "www."), "domain.com");
|
assertEquals(StringUtils.removeStartIgnoreCase("www.domain.com", "www."), "domain.com", "removeStartIgnoreCase(\"www.domain.com\", \"www.\")");
|
||||||
assertEquals("removeStartIgnoreCase(\"domain.com\", \"www.\")", StringUtils.removeStartIgnoreCase("domain.com", "www."), "domain.com");
|
assertEquals(StringUtils.removeStartIgnoreCase("domain.com", "www."), "domain.com", "removeStartIgnoreCase(\"domain.com\", \"www.\")");
|
||||||
assertEquals("removeStartIgnoreCase(\"domain.com\", \"\")", StringUtils.removeStartIgnoreCase("domain.com", ""), "domain.com");
|
assertEquals(StringUtils.removeStartIgnoreCase("domain.com", ""), "domain.com", "removeStartIgnoreCase(\"domain.com\", \"\")");
|
||||||
assertEquals("removeStartIgnoreCase(\"domain.com\", null)", StringUtils.removeStartIgnoreCase("domain.com", null), "domain.com");
|
assertEquals(StringUtils.removeStartIgnoreCase("domain.com", null), "domain.com", "removeStartIgnoreCase(\"domain.com\", null)");
|
||||||
|
|
||||||
// Case insensitive:
|
// Case insensitive:
|
||||||
assertEquals("removeStartIgnoreCase(\"www.domain.com\", \"WWW.\")", StringUtils.removeStartIgnoreCase("www.domain.com", "WWW."), "domain.com");
|
assertEquals(StringUtils.removeStartIgnoreCase("www.domain.com", "WWW."), "domain.com", "removeStartIgnoreCase(\"www.domain.com\", \"WWW.\")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2705,25 +2676,25 @@ public class StringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveEndIgnoreCase() {
|
public void testRemoveEndIgnoreCase() {
|
||||||
// StringUtils.removeEndIgnoreCase("", *) = ""
|
// StringUtils.removeEndIgnoreCase("", *) = ""
|
||||||
assertNull("removeEndIgnoreCase(null, null)", StringUtils.removeEndIgnoreCase(null, null));
|
assertNull(StringUtils.removeEndIgnoreCase(null, null), "removeEndIgnoreCase(null, null)");
|
||||||
assertNull("removeEndIgnoreCase(null, \"\")", StringUtils.removeEndIgnoreCase(null, ""));
|
assertNull(StringUtils.removeEndIgnoreCase(null, ""), "removeEndIgnoreCase(null, \"\")");
|
||||||
assertNull("removeEndIgnoreCase(null, \"a\")", StringUtils.removeEndIgnoreCase(null, "a"));
|
assertNull(StringUtils.removeEndIgnoreCase(null, "a"), "removeEndIgnoreCase(null, \"a\")");
|
||||||
|
|
||||||
// StringUtils.removeEnd(*, null) = *
|
// StringUtils.removeEnd(*, null) = *
|
||||||
assertEquals("removeEndIgnoreCase(\"\", null)", StringUtils.removeEndIgnoreCase("", null), "");
|
assertEquals(StringUtils.removeEndIgnoreCase("", null), "", "removeEndIgnoreCase(\"\", null)");
|
||||||
assertEquals("removeEndIgnoreCase(\"\", \"\")", StringUtils.removeEndIgnoreCase("", ""), "");
|
assertEquals(StringUtils.removeEndIgnoreCase("", ""), "", "removeEndIgnoreCase(\"\", \"\")");
|
||||||
assertEquals("removeEndIgnoreCase(\"\", \"a\")", StringUtils.removeEndIgnoreCase("", "a"), "");
|
assertEquals(StringUtils.removeEndIgnoreCase("", "a"), "", "removeEndIgnoreCase(\"\", \"a\")");
|
||||||
|
|
||||||
// All others:
|
// All others:
|
||||||
assertEquals("removeEndIgnoreCase(\"www.domain.com.\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain.com.", ".com"), "www.domain.com.");
|
assertEquals(StringUtils.removeEndIgnoreCase("www.domain.com.", ".com"), "www.domain.com.", "removeEndIgnoreCase(\"www.domain.com.\", \".com\")");
|
||||||
assertEquals("removeEndIgnoreCase(\"www.domain.com\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain.com", ".com"), "www.domain");
|
assertEquals(StringUtils.removeEndIgnoreCase("www.domain.com", ".com"), "www.domain", "removeEndIgnoreCase(\"www.domain.com\", \".com\")");
|
||||||
assertEquals("removeEndIgnoreCase(\"www.domain\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain", ".com"), "www.domain");
|
assertEquals(StringUtils.removeEndIgnoreCase("www.domain", ".com"), "www.domain", "removeEndIgnoreCase(\"www.domain\", \".com\")");
|
||||||
assertEquals("removeEndIgnoreCase(\"domain.com\", \"\")", StringUtils.removeEndIgnoreCase("domain.com", ""), "domain.com");
|
assertEquals(StringUtils.removeEndIgnoreCase("domain.com", ""), "domain.com", "removeEndIgnoreCase(\"domain.com\", \"\")");
|
||||||
assertEquals("removeEndIgnoreCase(\"domain.com\", null)", StringUtils.removeEndIgnoreCase("domain.com", null), "domain.com");
|
assertEquals(StringUtils.removeEndIgnoreCase("domain.com", null), "domain.com", "removeEndIgnoreCase(\"domain.com\", null)");
|
||||||
|
|
||||||
// Case insensitive:
|
// Case insensitive:
|
||||||
assertEquals("removeEndIgnoreCase(\"www.domain.com\", \".COM\")", StringUtils.removeEndIgnoreCase("www.domain.com", ".COM"), "www.domain");
|
assertEquals(StringUtils.removeEndIgnoreCase("www.domain.com", ".COM"), "www.domain", "removeEndIgnoreCase(\"www.domain.com\", \".COM\")");
|
||||||
assertEquals("removeEndIgnoreCase(\"www.domain.COM\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain.COM", ".com"), "www.domain");
|
assertEquals(StringUtils.removeEndIgnoreCase("www.domain.COM", ".com"), "www.domain", "removeEndIgnoreCase(\"www.domain.COM\", \".com\")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -3028,23 +2999,23 @@ public class StringUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAppendIfMissing() {
|
public void testAppendIfMissing() {
|
||||||
assertEquals("appendIfMissing(null,null)", null, StringUtils.appendIfMissing(null, null));
|
assertEquals(null, StringUtils.appendIfMissing(null, null), "appendIfMissing(null,null)");
|
||||||
assertEquals("appendIfMissing(abc,null)", "abc", StringUtils.appendIfMissing("abc", null));
|
assertEquals("abc", StringUtils.appendIfMissing("abc", null), "appendIfMissing(abc,null)");
|
||||||
assertEquals("appendIfMissing(\"\",xyz)", "xyz", StringUtils.appendIfMissing("", "xyz"));
|
assertEquals("xyz", StringUtils.appendIfMissing("", "xyz"), "appendIfMissing(\"\",xyz)");
|
||||||
assertEquals("appendIfMissing(abc,xyz)", "abcxyz", StringUtils.appendIfMissing("abc", "xyz"));
|
assertEquals("abcxyz", StringUtils.appendIfMissing("abc", "xyz"), "appendIfMissing(abc,xyz)");
|
||||||
assertEquals("appendIfMissing(abcxyz,xyz)", "abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz"));
|
assertEquals("abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz"), "appendIfMissing(abcxyz,xyz)");
|
||||||
assertEquals("appendIfMissing(aXYZ,xyz)", "aXYZxyz", StringUtils.appendIfMissing("aXYZ", "xyz"));
|
assertEquals("aXYZxyz", StringUtils.appendIfMissing("aXYZ", "xyz"), "appendIfMissing(aXYZ,xyz)");
|
||||||
|
|
||||||
assertEquals("appendIfMissing(null,null,null)", null, StringUtils.appendIfMissing(null, null, (CharSequence[]) null));
|
assertEquals(null, StringUtils.appendIfMissing(null, null, (CharSequence[]) null), "appendIfMissing(null,null,null)");
|
||||||
assertEquals("appendIfMissing(abc,null,null)", "abc", StringUtils.appendIfMissing("abc", null, (CharSequence[]) null));
|
assertEquals("abc", StringUtils.appendIfMissing("abc", null, (CharSequence[]) null), "appendIfMissing(abc,null,null)");
|
||||||
assertEquals("appendIfMissing(\"\",xyz,null))", "xyz", StringUtils.appendIfMissing("", "xyz", (CharSequence[]) null));
|
assertEquals("xyz", StringUtils.appendIfMissing("", "xyz", (CharSequence[]) null), "appendIfMissing(\"\",xyz,null))");
|
||||||
assertEquals("appendIfMissing(abc,xyz,{null})", "abcxyz", StringUtils.appendIfMissing("abc", "xyz", new CharSequence[]{null}));
|
assertEquals("abcxyz", StringUtils.appendIfMissing("abc", "xyz", new CharSequence[]{null}), "appendIfMissing(abc,xyz,{null})");
|
||||||
assertEquals("appendIfMissing(abc,xyz,\"\")", "abc", StringUtils.appendIfMissing("abc", "xyz", ""));
|
assertEquals("abc", StringUtils.appendIfMissing("abc", "xyz", ""), "appendIfMissing(abc,xyz,\"\")");
|
||||||
assertEquals("appendIfMissing(abc,xyz,mno)", "abcxyz", StringUtils.appendIfMissing("abc", "xyz", "mno"));
|
assertEquals("abcxyz", StringUtils.appendIfMissing("abc", "xyz", "mno"), "appendIfMissing(abc,xyz,mno)");
|
||||||
assertEquals("appendIfMissing(abcxyz,xyz,mno)", "abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz", "mno"));
|
assertEquals("abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz", "mno"), "appendIfMissing(abcxyz,xyz,mno)");
|
||||||
assertEquals("appendIfMissing(abcmno,xyz,mno)", "abcmno", StringUtils.appendIfMissing("abcmno", "xyz", "mno"));
|
assertEquals("abcmno", StringUtils.appendIfMissing("abcmno", "xyz", "mno"), "appendIfMissing(abcmno,xyz,mno)");
|
||||||
assertEquals("appendIfMissing(abcXYZ,xyz,mno)", "abcXYZxyz", StringUtils.appendIfMissing("abcXYZ", "xyz", "mno"));
|
assertEquals("abcXYZxyz", StringUtils.appendIfMissing("abcXYZ", "xyz", "mno"), "appendIfMissing(abcXYZ,xyz,mno)");
|
||||||
assertEquals("appendIfMissing(abcMNO,xyz,mno)", "abcMNOxyz", StringUtils.appendIfMissing("abcMNO", "xyz", "mno"));
|
assertEquals("abcMNOxyz", StringUtils.appendIfMissing("abcMNO", "xyz", "mno"), "appendIfMissing(abcMNO,xyz,mno)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3052,23 +3023,23 @@ public class StringUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAppendIfMissingIgnoreCase() {
|
public void testAppendIfMissingIgnoreCase() {
|
||||||
assertEquals("appendIfMissingIgnoreCase(null,null)", null, StringUtils.appendIfMissingIgnoreCase(null, null));
|
assertEquals(null, StringUtils.appendIfMissingIgnoreCase(null, null), "appendIfMissingIgnoreCase(null,null)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abc,null)", "abc", StringUtils.appendIfMissingIgnoreCase("abc", null));
|
assertEquals("abc", StringUtils.appendIfMissingIgnoreCase("abc", null), "appendIfMissingIgnoreCase(abc,null)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(\"\",xyz)", "xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz"));
|
assertEquals("xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz"), "appendIfMissingIgnoreCase(\"\",xyz)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz"));
|
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz"), "appendIfMissingIgnoreCase(abc,xyz)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abcxyz,xyz)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz"));
|
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz"), "appendIfMissingIgnoreCase(abcxyz,xyz)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abcXYZ,xyz)", "abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz"));
|
assertEquals("abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz"), "appendIfMissingIgnoreCase(abcXYZ,xyz)");
|
||||||
|
|
||||||
assertEquals("appendIfMissingIgnoreCase(null,null,null)", null, StringUtils.appendIfMissingIgnoreCase(null, null, (CharSequence[]) null));
|
assertEquals(null, StringUtils.appendIfMissingIgnoreCase(null, null, (CharSequence[]) null), "appendIfMissingIgnoreCase(null,null,null)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abc,null,null)", "abc", StringUtils.appendIfMissingIgnoreCase("abc", null, (CharSequence[]) null));
|
assertEquals("abc", StringUtils.appendIfMissingIgnoreCase("abc", null, (CharSequence[]) null), "appendIfMissingIgnoreCase(abc,null,null)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(\"\",xyz,null)", "xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz", (CharSequence[]) null));
|
assertEquals("xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz", (CharSequence[]) null), "appendIfMissingIgnoreCase(\"\",xyz,null)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz,{null})", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}));
|
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}), "appendIfMissingIgnoreCase(abc,xyz,{null})");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz,\"\")", "abc", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", ""));
|
assertEquals("abc", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", ""), "appendIfMissingIgnoreCase(abc,xyz,\"\")");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz,mno)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "mno"));
|
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "mno"), "appendIfMissingIgnoreCase(abc,xyz,mno)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abcxyz,xyz,mno)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno"));
|
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno"), "appendIfMissingIgnoreCase(abcxyz,xyz,mno)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abcmno,xyz,mno)", "abcmno", StringUtils.appendIfMissingIgnoreCase("abcmno", "xyz", "mno"));
|
assertEquals("abcmno", StringUtils.appendIfMissingIgnoreCase("abcmno", "xyz", "mno"), "appendIfMissingIgnoreCase(abcmno,xyz,mno)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abcXYZ,xyz,mno)", "abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno"));
|
assertEquals("abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno"), "appendIfMissingIgnoreCase(abcXYZ,xyz,mno)");
|
||||||
assertEquals("appendIfMissingIgnoreCase(abcMNO,xyz,mno)", "abcMNO", StringUtils.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno"));
|
assertEquals("abcMNO", StringUtils.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno"), "appendIfMissingIgnoreCase(abcMNO,xyz,mno)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3076,23 +3047,23 @@ public class StringUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPrependIfMissing() {
|
public void testPrependIfMissing() {
|
||||||
assertEquals("prependIfMissing(null,null)", null, StringUtils.prependIfMissing(null, null));
|
assertEquals(null, StringUtils.prependIfMissing(null, null), "prependIfMissing(null,null)");
|
||||||
assertEquals("prependIfMissing(abc,null)", "abc", StringUtils.prependIfMissing("abc", null));
|
assertEquals("abc", StringUtils.prependIfMissing("abc", null), "prependIfMissing(abc,null)");
|
||||||
assertEquals("prependIfMissing(\"\",xyz)", "xyz", StringUtils.prependIfMissing("", "xyz"));
|
assertEquals("xyz", StringUtils.prependIfMissing("", "xyz"), "prependIfMissing(\"\",xyz)");
|
||||||
assertEquals("prependIfMissing(abc,xyz)", "xyzabc", StringUtils.prependIfMissing("abc", "xyz"));
|
assertEquals("xyzabc", StringUtils.prependIfMissing("abc", "xyz"), "prependIfMissing(abc,xyz)");
|
||||||
assertEquals("prependIfMissing(xyzabc,xyz)", "xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz"));
|
assertEquals("xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz"), "prependIfMissing(xyzabc,xyz)");
|
||||||
assertEquals("prependIfMissing(XYZabc,xyz)", "xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz"));
|
assertEquals("xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz"), "prependIfMissing(XYZabc,xyz)");
|
||||||
|
|
||||||
assertEquals("prependIfMissing(null,null null)", null, StringUtils.prependIfMissing(null, null, (CharSequence[]) null));
|
assertEquals(null, StringUtils.prependIfMissing(null, null, (CharSequence[]) null), "prependIfMissing(null,null null)");
|
||||||
assertEquals("prependIfMissing(abc,null,null)", "abc", StringUtils.prependIfMissing("abc", null, (CharSequence[]) null));
|
assertEquals("abc", StringUtils.prependIfMissing("abc", null, (CharSequence[]) null), "prependIfMissing(abc,null,null)");
|
||||||
assertEquals("prependIfMissing(\"\",xyz,null)", "xyz", StringUtils.prependIfMissing("", "xyz", (CharSequence[]) null));
|
assertEquals("xyz", StringUtils.prependIfMissing("", "xyz", (CharSequence[]) null), "prependIfMissing(\"\",xyz,null)");
|
||||||
assertEquals("prependIfMissing(abc,xyz,{null})", "xyzabc", StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null}));
|
assertEquals("xyzabc", StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null}), "prependIfMissing(abc,xyz,{null})");
|
||||||
assertEquals("prependIfMissing(abc,xyz,\"\")", "abc", StringUtils.prependIfMissing("abc", "xyz", ""));
|
assertEquals("abc", StringUtils.prependIfMissing("abc", "xyz", ""), "prependIfMissing(abc,xyz,\"\")");
|
||||||
assertEquals("prependIfMissing(abc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("abc", "xyz", "mno"));
|
assertEquals("xyzabc", StringUtils.prependIfMissing("abc", "xyz", "mno"), "prependIfMissing(abc,xyz,mno)");
|
||||||
assertEquals("prependIfMissing(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz", "mno"));
|
assertEquals("xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz", "mno"), "prependIfMissing(xyzabc,xyz,mno)");
|
||||||
assertEquals("prependIfMissing(mnoabc,xyz,mno)", "mnoabc", StringUtils.prependIfMissing("mnoabc", "xyz", "mno"));
|
assertEquals("mnoabc", StringUtils.prependIfMissing("mnoabc", "xyz", "mno"), "prependIfMissing(mnoabc,xyz,mno)");
|
||||||
assertEquals("prependIfMissing(XYZabc,xyz,mno)", "xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz", "mno"));
|
assertEquals("xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz", "mno"), "prependIfMissing(XYZabc,xyz,mno)");
|
||||||
assertEquals("prependIfMissing(MNOabc,xyz,mno)", "xyzMNOabc", StringUtils.prependIfMissing("MNOabc", "xyz", "mno"));
|
assertEquals("xyzMNOabc", StringUtils.prependIfMissing("MNOabc", "xyz", "mno"), "prependIfMissing(MNOabc,xyz,mno)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3100,23 +3071,23 @@ public class StringUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPrependIfMissingIgnoreCase() {
|
public void testPrependIfMissingIgnoreCase() {
|
||||||
assertEquals("prependIfMissingIgnoreCase(null,null)", null, StringUtils.prependIfMissingIgnoreCase(null, null));
|
assertEquals(null, StringUtils.prependIfMissingIgnoreCase(null, null), "prependIfMissingIgnoreCase(null,null)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(abc,null)", "abc", StringUtils.prependIfMissingIgnoreCase("abc", null));
|
assertEquals("abc", StringUtils.prependIfMissingIgnoreCase("abc", null), "prependIfMissingIgnoreCase(abc,null)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(\"\",xyz)", "xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz"));
|
assertEquals("xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz"), "prependIfMissingIgnoreCase(\"\",xyz)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz"));
|
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz"), "prependIfMissingIgnoreCase(abc,xyz)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(xyzabc,xyz)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz"));
|
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz"), "prependIfMissingIgnoreCase(xyzabc,xyz)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(XYZabc,xyz)", "XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz"));
|
assertEquals("XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz"), "prependIfMissingIgnoreCase(XYZabc,xyz)");
|
||||||
|
|
||||||
assertEquals("prependIfMissingIgnoreCase(null,null null)", null, StringUtils.prependIfMissingIgnoreCase(null, null, (CharSequence[]) null));
|
assertEquals(null, StringUtils.prependIfMissingIgnoreCase(null, null, (CharSequence[]) null), "prependIfMissingIgnoreCase(null,null null)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(abc,null,null)", "abc", StringUtils.prependIfMissingIgnoreCase("abc", null, (CharSequence[]) null));
|
assertEquals("abc", StringUtils.prependIfMissingIgnoreCase("abc", null, (CharSequence[]) null), "prependIfMissingIgnoreCase(abc,null,null)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(\"\",xyz,null)", "xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz", (CharSequence[]) null));
|
assertEquals("xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz", (CharSequence[]) null), "prependIfMissingIgnoreCase(\"\",xyz,null)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz,{null})", "xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}));
|
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}), "prependIfMissingIgnoreCase(abc,xyz,{null})");
|
||||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz,\"\")", "abc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", ""));
|
assertEquals("abc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", ""), "prependIfMissingIgnoreCase(abc,xyz,\"\")");
|
||||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz,mno)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "mno"));
|
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "mno"), "prependIfMissingIgnoreCase(abc,xyz,mno)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno"));
|
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno"), "prependIfMissingIgnoreCase(xyzabc,xyz,mno)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(mnoabc,xyz,mno)", "mnoabc", StringUtils.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno"));
|
assertEquals("mnoabc", StringUtils.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno"), "prependIfMissingIgnoreCase(mnoabc,xyz,mno)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(XYZabc,xyz,mno)", "XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno"));
|
assertEquals("XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno"), "prependIfMissingIgnoreCase(XYZabc,xyz,mno)");
|
||||||
assertEquals("prependIfMissingIgnoreCase(MNOabc,xyz,mno)", "MNOabc", StringUtils.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno"));
|
assertEquals("MNOabc", StringUtils.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno"), "prependIfMissingIgnoreCase(MNOabc,xyz,mno)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Trim/Strip methods
|
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Trim/Strip methods
|
||||||
|
@ -220,19 +220,19 @@ public class StringUtilsTrimStripTest {
|
||||||
@Test
|
@Test
|
||||||
public void testStripAccents() {
|
public void testStripAccents() {
|
||||||
final String cue = "\u00C7\u00FA\u00EA";
|
final String cue = "\u00C7\u00FA\u00EA";
|
||||||
assertEquals( "Failed to strip accents from " + cue, "Cue", StringUtils.stripAccents(cue));
|
assertEquals("Cue", StringUtils.stripAccents(cue), "Failed to strip accents from " + cue);
|
||||||
|
|
||||||
final String lots = "\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C7\u00C8\u00C9" +
|
final String lots = "\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C7\u00C8\u00C9" +
|
||||||
"\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D1\u00D2\u00D3" +
|
"\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D1\u00D2\u00D3" +
|
||||||
"\u00D4\u00D5\u00D6\u00D9\u00DA\u00DB\u00DC\u00DD";
|
"\u00D4\u00D5\u00D6\u00D9\u00DA\u00DB\u00DC\u00DD";
|
||||||
assertEquals( "Failed to strip accents from " + lots,
|
assertEquals("AAAAAACEEEEIIIINOOOOOUUUUY",
|
||||||
"AAAAAACEEEEIIIINOOOOOUUUUY",
|
StringUtils.stripAccents(lots),
|
||||||
StringUtils.stripAccents(lots));
|
"Failed to strip accents from " + lots);
|
||||||
|
|
||||||
assertNull( "Failed null safety", StringUtils.stripAccents(null) );
|
assertNull(StringUtils.stripAccents(null), "Failed null safety");
|
||||||
assertEquals( "Failed empty String", "", StringUtils.stripAccents("") );
|
assertEquals("", StringUtils.stripAccents(""), "Failed empty String");
|
||||||
assertEquals( "Failed to handle non-accented text", "control", StringUtils.stripAccents("control") );
|
assertEquals("control", StringUtils.stripAccents("control"), "Failed to handle non-accented text");
|
||||||
assertEquals( "Failed to handle easy example", "eclair", StringUtils.stripAccents("\u00E9clair") );
|
assertEquals("eclair", StringUtils.stripAccents("\u00E9clair"), "Failed to handle easy example");
|
||||||
assertEquals("ALOSZZCN aloszzcn", StringUtils.stripAccents("\u0104\u0141\u00D3\u015A\u017B\u0179\u0106\u0143 "
|
assertEquals("ALOSZZCN aloszzcn", StringUtils.stripAccents("\u0104\u0141\u00D3\u015A\u017B\u0179\u0106\u0143 "
|
||||||
+ "\u0105\u0142\u00F3\u015B\u017C\u017A\u0107\u0144"));
|
+ "\u0105\u0142\u00F3\u015B\u017C\u017A\u0107\u0144"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,18 +30,18 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
|
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.SystemUtils}.
|
* Unit tests {@link org.apache.commons.lang3.SystemUtils}.
|
||||||
|
@ -64,7 +64,7 @@ public class SystemUtilsTest {
|
||||||
public void testGetEnvironmentVariableAbsent() {
|
public void testGetEnvironmentVariableAbsent() {
|
||||||
final String name = "THIS_ENV_VAR_SHOULD_NOT_EXIST_FOR_THIS_TEST_TO_PASS";
|
final String name = "THIS_ENV_VAR_SHOULD_NOT_EXIST_FOR_THIS_TEST_TO_PASS";
|
||||||
final String expected = System.getenv(name);
|
final String expected = System.getenv(name);
|
||||||
Assert.assertNull(expected);
|
assertNull(expected);
|
||||||
final String value = SystemUtils.getEnvironmentVariable(name, "DEFAULT");
|
final String value = SystemUtils.getEnvironmentVariable(name, "DEFAULT");
|
||||||
assertEquals("DEFAULT", value);
|
assertEquals("DEFAULT", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
|
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -32,76 +33,78 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.ThreadUtils}.
|
* Unit tests {@link org.apache.commons.lang3.ThreadUtils}.
|
||||||
*/
|
*/
|
||||||
public class ThreadUtilsTest {
|
public class ThreadUtilsTest {
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadName() throws InterruptedException {
|
public void testNullThreadName() {
|
||||||
ThreadUtils.findThreadsByName(null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadGroupName() throws InterruptedException {
|
public void testNullThreadGroupName() {
|
||||||
ThreadUtils.findThreadGroupsByName(null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadGroupsByName(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadThreadGroupName1() throws InterruptedException {
|
public void testNullThreadThreadGroupName1() {
|
||||||
ThreadUtils.findThreadsByName(null, "tgname");
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null, "tgname"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadThreadGroupName2() throws InterruptedException {
|
public void testNullThreadThreadGroupName2() {
|
||||||
ThreadUtils.findThreadsByName("tname", (String) null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName("tname", (String) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadThreadGroupName3() throws InterruptedException {
|
public void testNullThreadThreadGroupName3() {
|
||||||
ThreadUtils.findThreadsByName(null, (String) null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null, (String) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadThreadGroup1() throws InterruptedException {
|
public void testNullThreadThreadGroup1() {
|
||||||
ThreadUtils.findThreadsByName("tname", (ThreadGroup) null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName("tname", (ThreadGroup) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadThreadGroup2() throws InterruptedException {
|
public void testNullThreadThreadGroup2() {
|
||||||
ThreadUtils.findThreadById(1L, (ThreadGroup) null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadById(1L, (ThreadGroup) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testNullThreadThreadGroup3() throws InterruptedException {
|
public void testNullThreadThreadGroup3() {
|
||||||
ThreadUtils.findThreadsByName(null, (ThreadGroup) null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null, (ThreadGroup) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidThreadId() throws InterruptedException {
|
public void testInvalidThreadId() {
|
||||||
ThreadUtils.findThreadById(-5L);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadById(-5L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testThreadGroupsByIdFail() throws InterruptedException {
|
public void testThreadGroupsByIdFail() {
|
||||||
ThreadUtils.findThreadById(Thread.currentThread().getId(), (String) null);
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> ThreadUtils.findThreadById(Thread.currentThread().getId(), (String) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testThreadgroupsNullParent() throws InterruptedException {
|
public void testThreadgroupsNullParent() {
|
||||||
ThreadUtils.findThreadGroups(null, true, ThreadUtils.ALWAYS_TRUE_PREDICATE);
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> ThreadUtils.findThreadGroups(null, true, ThreadUtils.ALWAYS_TRUE_PREDICATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testThreadgroupsNullPredicate() throws InterruptedException {
|
public void testThreadgroupsNullPredicate() {
|
||||||
ThreadUtils.findThreadGroups(null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadGroups(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test
|
||||||
public void testThreadsNullPredicate() throws InterruptedException {
|
public void testThreadsNullPredicate() {
|
||||||
ThreadUtils.findThreads(null);
|
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreads(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.commons.lang3.test;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Annotation used with {@link SystemDefaults} that specifies the
|
|
||||||
* system default Locale and TimeZone to be used in a test method.
|
|
||||||
*/
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface SystemDefaults {
|
|
||||||
/**
|
|
||||||
* The name of the Locale to be used while running a test method
|
|
||||||
*/
|
|
||||||
String locale() default "";
|
|
||||||
/**
|
|
||||||
* The name of the TimeZone to be used while running a test method
|
|
||||||
*/
|
|
||||||
String timezone() default "";
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.commons.lang3.test;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.LocaleUtils;
|
|
||||||
import org.junit.rules.TestRule;
|
|
||||||
import org.junit.runner.Description;
|
|
||||||
import org.junit.runners.model.Statement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test Rule used with {@link SystemDefaults} annotation that sets and restores the system default Locale and TimeZone.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* Set up tests to use alternate system default Locale and/or TimeZone by creating an instance of this rule
|
|
||||||
* and annotating the test method with {@link SystemDefaults}
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* public class SystemDefaultsDependentTest {
|
|
||||||
*
|
|
||||||
* {@literal @}Rule
|
|
||||||
* public SystemDefaultsSwitch locale = new SystemDefaultsSwitch();
|
|
||||||
*
|
|
||||||
* {@literal @}Test
|
|
||||||
* public void testThatWillExecuteWithTheDefaultLocaleAndTimeZone() {
|
|
||||||
* // nothing to do, just implement the test
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* {@literal @}Test
|
|
||||||
* {@literal @}SystemDefaults(locale="zh_CN")
|
|
||||||
* public void testWithSimplifiedChinaDefaultLocale() {
|
|
||||||
* // Locale.getDefault() will return Locale.CHINA until the end of this test method
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* {@literal @}Test
|
|
||||||
* {@literal @}SystemDefaults(timezone="America/New_York")
|
|
||||||
* public void testWithNorthAmericaEasternTimeZone() {
|
|
||||||
* // TimeZone.getDefault() will equal TimeZone.getTimeZone("America/New_York") until the end of this method
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public class SystemDefaultsSwitch implements TestRule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Statement apply(final Statement stmt, final Description description) {
|
|
||||||
final SystemDefaults defaults = description.getAnnotation(SystemDefaults.class);
|
|
||||||
if (defaults == null) {
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
return applyTimeZone(defaults, applyLocale(defaults, stmt));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Statement applyTimeZone(final SystemDefaults defaults, final Statement stmt) {
|
|
||||||
if (defaults.timezone().isEmpty()) {
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TimeZone newTimeZone = TimeZone.getTimeZone(defaults.timezone());
|
|
||||||
|
|
||||||
return new Statement() {
|
|
||||||
@Override
|
|
||||||
public void evaluate() throws Throwable {
|
|
||||||
final TimeZone save = TimeZone.getDefault();
|
|
||||||
try {
|
|
||||||
TimeZone.setDefault(newTimeZone);
|
|
||||||
stmt.evaluate();
|
|
||||||
} finally {
|
|
||||||
TimeZone.setDefault(save);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Statement applyLocale(final SystemDefaults defaults, final Statement stmt) {
|
|
||||||
if (defaults.locale().isEmpty()) {
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Locale newLocale = LocaleUtils.toLocale(defaults.locale());
|
|
||||||
|
|
||||||
return new Statement() {
|
|
||||||
@Override
|
|
||||||
public void evaluate() throws Throwable {
|
|
||||||
final Locale save = Locale.getDefault();
|
|
||||||
try {
|
|
||||||
Locale.setDefault(newLocale);
|
|
||||||
stmt.evaluate();
|
|
||||||
} finally {
|
|
||||||
Locale.setDefault(save);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.commons.lang3.test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.time.FastTimeZone;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class SystemDefaultsSwitchTest {
|
|
||||||
|
|
||||||
private static Locale TEST_DEFAULT_LOCALE;
|
|
||||||
private static Locale DEFAULT_LOCALE_BEFORE_TEST;
|
|
||||||
|
|
||||||
private static TimeZone DEFAULT_TIMEZONE_BEFORE_TEST;
|
|
||||||
private static TimeZone TEST_DEFAULT_TIMEZONE;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void classSetUp() {
|
|
||||||
DEFAULT_LOCALE_BEFORE_TEST = Locale.getDefault();
|
|
||||||
if (!DEFAULT_LOCALE_BEFORE_TEST.equals(Locale.CANADA)) {
|
|
||||||
Locale.setDefault(Locale.CANADA);
|
|
||||||
} else {
|
|
||||||
// you seem to be from Canada...
|
|
||||||
Locale.setDefault(Locale.CHINESE);
|
|
||||||
}
|
|
||||||
TEST_DEFAULT_LOCALE = Locale.getDefault();
|
|
||||||
|
|
||||||
DEFAULT_TIMEZONE_BEFORE_TEST = TimeZone.getDefault();
|
|
||||||
final TimeZone utc = FastTimeZone.getGmtTimeZone();
|
|
||||||
if (!DEFAULT_TIMEZONE_BEFORE_TEST.equals(utc)) {
|
|
||||||
TimeZone.setDefault(utc);
|
|
||||||
} else {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
|
||||||
}
|
|
||||||
TEST_DEFAULT_TIMEZONE = TimeZone.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemDefaultsSwitch defaultsSwitch = new SystemDefaultsSwitch();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDefaultLocaleNoAnnotation() throws Exception {
|
|
||||||
assertEquals(TEST_DEFAULT_LOCALE, Locale.getDefault());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SystemDefaults(locale = "en_EN")
|
|
||||||
public void testUseDifferentLocale() throws Exception {
|
|
||||||
assertEquals(new Locale("en", "EN"), Locale.getDefault());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDefaultTimeZoneNoAnnotation() throws Exception {
|
|
||||||
assertEquals(TEST_DEFAULT_TIMEZONE, TimeZone.getDefault());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SystemDefaults(timezone = "CET")
|
|
||||||
public void testUseDifferentTimeZone() throws Exception {
|
|
||||||
assertEquals(TimeZone.getTimeZone("CET"), TimeZone.getDefault());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void classTearDown() {
|
|
||||||
Locale.setDefault(DEFAULT_LOCALE_BEFORE_TEST);
|
|
||||||
TimeZone.setDefault(DEFAULT_TIMEZONE_BEFORE_TEST);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue