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>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
<groupId>org.junit-pioneer</groupId>
|
||||
<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.MOE;
|
||||
import static org.apache.commons.lang3.AnnotationUtilsTest.Stooge.SHEMP;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
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.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -377,6 +380,17 @@ public class AnnotationUtilsTest {
|
|||
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 {
|
||||
MOE, LARRY, CURLY, JOE, SHEMP
|
||||
}
|
||||
|
@ -386,7 +400,7 @@ public class AnnotationUtilsTest {
|
|||
private Field field3;
|
||||
private Field field4;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
field1 = getClass().getDeclaredField("dummy1");
|
||||
field2 = getClass().getDeclaredField("dummy2");
|
||||
|
@ -444,8 +458,9 @@ public class AnnotationUtilsTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 666000)
|
||||
public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
|
||||
@Test
|
||||
public void testGeneratedAnnotationEquivalentToRealAnnotation() {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
|
||||
final Test real = getClass().getDeclaredMethod(
|
||||
"testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
|
||||
|
||||
|
@ -481,28 +496,35 @@ public class AnnotationUtilsTest {
|
|||
assertFalse(generated2.equals(generated));
|
||||
assertTrue(AnnotationUtils.equals(generated, generated2));
|
||||
assertTrue(AnnotationUtils.equals(generated2, generated));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 666000)
|
||||
public void testHashCode() throws Exception {
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
|
||||
final Test test = getClass().getDeclaredMethod("testHashCode").getAnnotation(Test.class);
|
||||
assertEquals(test.hashCode(), AnnotationUtils.hashCode(test));
|
||||
final TestAnnotation testAnnotation1 = field1.getAnnotation(TestAnnotation.class);
|
||||
assertEquals(testAnnotation1.hashCode(), AnnotationUtils.hashCode(testAnnotation1));
|
||||
final TestAnnotation testAnnotation3 = field3.getAnnotation(TestAnnotation.class);
|
||||
assertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 666000)
|
||||
public void testToString() throws Exception {
|
||||
final Test testAnnotation = getClass().getDeclaredMethod("testToString")
|
||||
.getAnnotation(Test.class);
|
||||
@Test
|
||||
@TestMethodAnnotation(timeout = 666000)
|
||||
public void testToString() {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
|
||||
final TestMethodAnnotation testAnnotation =
|
||||
getClass().getDeclaredMethod("testToString").getAnnotation(TestMethodAnnotation.class);
|
||||
|
||||
final String annotationString = AnnotationUtils.toString(testAnnotation);
|
||||
assertTrue(annotationString.startsWith("@org.junit.Test("));
|
||||
assertTrue(annotationString.startsWith("@org.apache.commons.lang3.AnnotationUtilsTest$TestMethodAnnotation("));
|
||||
assertTrue(annotationString.endsWith(")"));
|
||||
assertTrue(annotationString.contains("expected=class org.junit.Test$None"));
|
||||
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;
|
||||
|
||||
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.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Test class for {@link ArchUtils}.
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests ArrayUtils add methods.
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests ArrayUtils insert methods.
|
||||
|
|
|
@ -17,15 +17,16 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests ArrayUtils remove and removeElement methods.
|
||||
|
@ -90,19 +91,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(Object.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.remove((Object[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((Object[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -206,19 +207,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(boolean.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((boolean[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((boolean[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -283,19 +284,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(byte.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((byte[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((byte[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -360,19 +361,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(char.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((char[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((char[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -437,19 +438,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(double.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((double[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((double[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -514,19 +515,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(float.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((float[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((float[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -597,19 +598,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(int.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((int[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((int[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -674,19 +675,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(long.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((long[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((long[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -751,19 +752,19 @@ public class ArrayUtilsRemoveMultipleTest {
|
|||
assertEquals(short.class, array2.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
ArrayUtils.removeAll((short[]) null, 0);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.removeAll((short[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Class to test BitField functionality
|
||||
|
|
|
@ -16,17 +16,18 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
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.Modifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.BooleanUtils}.
|
||||
|
@ -131,9 +132,9 @@ public class BooleanUtilsTest {
|
|||
assertFalse(BooleanUtils.toBoolean(7, 6, 7));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBoolean_int_int_int_noMatch() {
|
||||
BooleanUtils.toBoolean(8, 6, 7);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.toBoolean(8, 6, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -148,14 +149,16 @@ public class BooleanUtilsTest {
|
|||
assertFalse(BooleanUtils.toBoolean(Integer.valueOf(7), six, seven));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBoolean_Integer_Integer_Integer_nullValue() {
|
||||
BooleanUtils.toBoolean(null, Integer.valueOf(6), Integer.valueOf(7));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> BooleanUtils.toBoolean(null, Integer.valueOf(6), Integer.valueOf(7)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBoolean_Integer_Integer_Integer_noMatch() {
|
||||
BooleanUtils.toBoolean(Integer.valueOf(8), Integer.valueOf(6), Integer.valueOf(7));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> BooleanUtils.toBoolean(Integer.valueOf(8), Integer.valueOf(6), Integer.valueOf(7)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -166,9 +169,9 @@ public class BooleanUtilsTest {
|
|||
assertNull(BooleanUtils.toBooleanObject(8, 6, 7, 8));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBooleanObject_int_int_int_noMatch() {
|
||||
BooleanUtils.toBooleanObject(9, 6, 7, 8);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.toBooleanObject(9, 6, 7, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -186,14 +189,16 @@ public class BooleanUtilsTest {
|
|||
assertNull(BooleanUtils.toBooleanObject(Integer.valueOf(8), six, seven, eight));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBooleanObject_Integer_Integer_Integer_Integer_nullValue() {
|
||||
BooleanUtils.toBooleanObject(null, Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> BooleanUtils.toBooleanObject(null, Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBooleanObject_Integer_Integer_Integer_Integer_noMatch() {
|
||||
BooleanUtils.toBooleanObject(Integer.valueOf(9), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> BooleanUtils.toBooleanObject(Integer.valueOf(9), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -298,14 +303,14 @@ public class BooleanUtilsTest {
|
|||
assertNull(BooleanUtils.toBooleanObject("U", "Y", "N", "U"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBooleanObject_String_String_String_String_nullValue() {
|
||||
BooleanUtils.toBooleanObject(null, "Y", "N", "U");
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.toBooleanObject(null, "Y", "N", "U"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBooleanObject_String_String_String_String_noMatch() {
|
||||
BooleanUtils.toBooleanObject("X", "Y", "N", "U");
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.toBooleanObject("X", "Y", "N", "U"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -369,14 +374,14 @@ public class BooleanUtilsTest {
|
|||
assertTrue(BooleanUtils.toBoolean("Y", new String("Y"), new String("Y")));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBoolean_String_String_String_nullValue() {
|
||||
BooleanUtils.toBoolean(null, "Y", "N");
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.toBoolean(null, "Y", "N"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toBoolean_String_String_String_noMatch() {
|
||||
BooleanUtils.toBoolean("X", "Y", "N");
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.toBoolean("X", "Y", "N"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -435,142 +440,133 @@ public class BooleanUtilsTest {
|
|||
|
||||
// testXor
|
||||
// -----------------------------------------------------------------------
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testXor_primitive_nullInput() {
|
||||
BooleanUtils.xor((boolean[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor((boolean[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testXor_primitive_emptyInput() {
|
||||
BooleanUtils.xor(new boolean[] {});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor(new boolean[] {}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXor_primitive_validInput_2items() {
|
||||
assertEquals(
|
||||
"true ^ true",
|
||||
true ^ true,
|
||||
BooleanUtils.xor(new boolean[] { true, true }));
|
||||
BooleanUtils.xor(new boolean[] { true, true }),
|
||||
"true ^ true");
|
||||
|
||||
assertEquals(
|
||||
"false ^ false",
|
||||
false ^ false,
|
||||
BooleanUtils.xor(new boolean[] { false, false }));
|
||||
BooleanUtils.xor(new boolean[] { false, false }),
|
||||
"false ^ false");
|
||||
|
||||
assertEquals(
|
||||
"true ^ false",
|
||||
true ^ false,
|
||||
BooleanUtils.xor(new boolean[] { true, false }));
|
||||
BooleanUtils.xor(new boolean[] { true, false }),
|
||||
"true ^ false");
|
||||
|
||||
assertEquals(
|
||||
"false ^ true",
|
||||
false ^ true,
|
||||
BooleanUtils.xor(new boolean[] { false, true }));
|
||||
BooleanUtils.xor(new boolean[] { false, true }),
|
||||
"false ^ true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXor_primitive_validInput_3items() {
|
||||
assertEquals(
|
||||
"false ^ false ^ false",
|
||||
false ^ false ^ false,
|
||||
BooleanUtils.xor(new boolean[] { false, false, false }));
|
||||
BooleanUtils.xor(new boolean[] { false, false, false }),
|
||||
"false ^ false ^ false");
|
||||
|
||||
assertEquals(
|
||||
"false ^ false ^ true",
|
||||
false ^ false ^ true,
|
||||
BooleanUtils.xor(new boolean[] { false, false, true }));
|
||||
BooleanUtils.xor(new boolean[] { false, false, true }),
|
||||
"false ^ false ^ true");
|
||||
|
||||
assertEquals(
|
||||
"false ^ true ^ false",
|
||||
false ^ true ^ false,
|
||||
BooleanUtils.xor(new boolean[] { false, true, false }));
|
||||
BooleanUtils.xor(new boolean[] { false, true, false }),
|
||||
"false ^ true ^ false");
|
||||
|
||||
assertEquals(
|
||||
"false ^ true ^ true",
|
||||
false ^ true ^ true,
|
||||
BooleanUtils.xor(new boolean[] { false, true, true }));
|
||||
BooleanUtils.xor(new boolean[] { false, true, true }),
|
||||
"false ^ true ^ true");
|
||||
|
||||
assertEquals(
|
||||
"true ^ false ^ false",
|
||||
true ^ false ^ false,
|
||||
BooleanUtils.xor(new boolean[] { true, false, false }));
|
||||
BooleanUtils.xor(new boolean[] { true, false, false }),
|
||||
"true ^ false ^ false");
|
||||
|
||||
assertEquals(
|
||||
"true ^ false ^ true",
|
||||
true ^ false ^ true,
|
||||
BooleanUtils.xor(new boolean[] { true, false, true }));
|
||||
BooleanUtils.xor(new boolean[] { true, false, true }),
|
||||
"true ^ false ^ true");
|
||||
|
||||
assertEquals(
|
||||
"true ^ true ^ false",
|
||||
true ^ true ^ false,
|
||||
BooleanUtils.xor(new boolean[] { true, true, false }));
|
||||
BooleanUtils.xor(new boolean[] { true, true, false }),
|
||||
"true ^ true ^ false");
|
||||
|
||||
assertEquals(
|
||||
"true ^ true ^ true",
|
||||
true ^ true ^ true,
|
||||
BooleanUtils.xor(new boolean[] { true, true, true }));
|
||||
BooleanUtils.xor(new boolean[] { true, true, true }),
|
||||
"true ^ true ^ true");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testXor_object_nullInput() {
|
||||
BooleanUtils.xor((Boolean[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor((Boolean[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testXor_object_emptyInput() {
|
||||
BooleanUtils.xor(new Boolean[] {});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor(new Boolean[] {}));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testXor_object_nullElementInput() {
|
||||
BooleanUtils.xor(new Boolean[] {null});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor(new Boolean[] {null}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXor_object_validInput_2items() {
|
||||
assertEquals(
|
||||
"false ^ false",
|
||||
false ^ false,
|
||||
BooleanUtils
|
||||
.xor(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
||||
.booleanValue());
|
||||
BooleanUtils.xor(new Boolean[] { Boolean.FALSE, Boolean.FALSE }).booleanValue(),
|
||||
"false ^ false");
|
||||
|
||||
assertEquals(
|
||||
"false ^ true",
|
||||
false ^ true,
|
||||
BooleanUtils
|
||||
.xor(new Boolean[] { Boolean.FALSE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
BooleanUtils.xor(new Boolean[] { Boolean.FALSE, Boolean.TRUE }).booleanValue(),
|
||||
"false ^ true");
|
||||
|
||||
assertEquals(
|
||||
"true ^ false",
|
||||
true ^ false,
|
||||
BooleanUtils
|
||||
.xor(new Boolean[] { Boolean.TRUE, Boolean.FALSE })
|
||||
.booleanValue());
|
||||
BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.FALSE }).booleanValue(),
|
||||
"true ^ false");
|
||||
|
||||
assertEquals(
|
||||
"true ^ true",
|
||||
true ^ true,
|
||||
BooleanUtils
|
||||
.xor(new Boolean[] { Boolean.TRUE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.TRUE }).booleanValue(),
|
||||
"true ^ true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXor_object_validInput_3items() {
|
||||
assertEquals(
|
||||
"false ^ false ^ false",
|
||||
false ^ false ^ false,
|
||||
BooleanUtils.xor(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"false ^ false ^ false");
|
||||
|
||||
assertEquals(
|
||||
"false ^ false ^ true",
|
||||
false ^ false ^ true,
|
||||
BooleanUtils
|
||||
.xor(
|
||||
|
@ -578,10 +574,10 @@ public class BooleanUtilsTest {
|
|||
Boolean.FALSE,
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"false ^ false ^ true");
|
||||
|
||||
assertEquals(
|
||||
"false ^ true ^ false",
|
||||
false ^ true ^ false,
|
||||
BooleanUtils
|
||||
.xor(
|
||||
|
@ -589,10 +585,10 @@ public class BooleanUtilsTest {
|
|||
Boolean.FALSE,
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"false ^ true ^ false");
|
||||
|
||||
assertEquals(
|
||||
"true ^ false ^ false",
|
||||
true ^ false ^ false,
|
||||
BooleanUtils
|
||||
.xor(
|
||||
|
@ -600,410 +596,414 @@ public class BooleanUtilsTest {
|
|||
Boolean.TRUE,
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"true ^ false ^ false");
|
||||
|
||||
assertEquals(
|
||||
"true ^ false ^ true",
|
||||
true ^ false ^ true,
|
||||
BooleanUtils.xor(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"true ^ false ^ true");
|
||||
|
||||
assertEquals(
|
||||
"true ^ true ^ false",
|
||||
true ^ true ^ false,
|
||||
BooleanUtils.xor(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"true ^ true ^ false");
|
||||
|
||||
assertEquals(
|
||||
"false ^ true ^ true",
|
||||
false ^ true ^ true,
|
||||
BooleanUtils.xor(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"false ^ true ^ true");
|
||||
|
||||
assertEquals(
|
||||
"true ^ true ^ true",
|
||||
true ^ true ^ true,
|
||||
BooleanUtils
|
||||
.xor(new Boolean[] { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
BooleanUtils.xor(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue(),
|
||||
"true ^ true ^ true");
|
||||
}
|
||||
|
||||
// testAnd
|
||||
// -----------------------------------------------------------------------
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testAnd_primitive_nullInput() {
|
||||
BooleanUtils.and((boolean[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and((boolean[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testAnd_primitive_emptyInput() {
|
||||
BooleanUtils.and(new boolean[] {});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and(new boolean[] {}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnd_primitive_validInput_2items() {
|
||||
assertTrue(
|
||||
"False result for (true, true)",
|
||||
BooleanUtils.and(new boolean[] { true, true }));
|
||||
BooleanUtils.and(new boolean[] { true, true }),
|
||||
"False result for (true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils.and(new boolean[] { false, false }));
|
||||
! BooleanUtils.and(new boolean[] { false, false }),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, false)",
|
||||
! BooleanUtils.and(new boolean[] { true, false }));
|
||||
! BooleanUtils.and(new boolean[] { true, false }),
|
||||
"True result for (true, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, true)",
|
||||
! BooleanUtils.and(new boolean[] { false, true }));
|
||||
! BooleanUtils.and(new boolean[] { false, true }),
|
||||
"True result for (false, true)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnd_primitive_validInput_3items() {
|
||||
assertTrue(
|
||||
"True result for (false, false, true)",
|
||||
! BooleanUtils.and(new boolean[] { false, false, true }));
|
||||
! BooleanUtils.and(new boolean[] { false, false, true }),
|
||||
"True result for (false, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, true, false)",
|
||||
! BooleanUtils.and(new boolean[] { false, true, false }));
|
||||
! BooleanUtils.and(new boolean[] { false, true, false }),
|
||||
"True result for (false, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, false, false)",
|
||||
! BooleanUtils.and(new boolean[] { true, false, false }));
|
||||
! BooleanUtils.and(new boolean[] { true, false, false }),
|
||||
"True result for (true, false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, true, true)",
|
||||
BooleanUtils.and(new boolean[] { true, true, true }));
|
||||
BooleanUtils.and(new boolean[] { true, true, true }),
|
||||
"False result for (true, true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils.and(new boolean[] { false, false, false }));
|
||||
! BooleanUtils.and(new boolean[] { false, false, false }),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, true, false)",
|
||||
! BooleanUtils.and(new boolean[] { true, true, false }));
|
||||
! BooleanUtils.and(new boolean[] { true, true, false }),
|
||||
"True result for (true, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, false, true)",
|
||||
! BooleanUtils.and(new boolean[] { true, false, true }));
|
||||
! BooleanUtils.and(new boolean[] { true, false, true }),
|
||||
"True result for (true, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, true, true)",
|
||||
! BooleanUtils.and(new boolean[] { false, true, true }));
|
||||
! BooleanUtils.and(new boolean[] { false, true, true }),
|
||||
"True result for (false, true, true)");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testAnd_object_nullInput() {
|
||||
BooleanUtils.and((Boolean[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and((Boolean[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testAnd_object_emptyInput() {
|
||||
BooleanUtils.and(new Boolean[] {});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and(new Boolean[] {}));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testAnd_object_nullElementInput() {
|
||||
BooleanUtils.and(new Boolean[] {null});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and(new Boolean[] {null}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnd_object_validInput_2items() {
|
||||
assertTrue(
|
||||
"False result for (true, true)",
|
||||
BooleanUtils
|
||||
.and(new Boolean[] { Boolean.TRUE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils
|
||||
.and(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, false)",
|
||||
! BooleanUtils
|
||||
.and(new Boolean[] { Boolean.TRUE, Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (true, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, true)",
|
||||
! BooleanUtils
|
||||
.and(new Boolean[] { Boolean.FALSE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, true)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnd_object_validInput_3items() {
|
||||
assertTrue(
|
||||
"True result for (false, false, true)",
|
||||
! BooleanUtils
|
||||
.and(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, true, false)",
|
||||
! BooleanUtils
|
||||
.and(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, false, false)",
|
||||
! BooleanUtils
|
||||
.and(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (true, false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, true, true)",
|
||||
BooleanUtils
|
||||
.and(new Boolean[] { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils.and(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, true, false)",
|
||||
! BooleanUtils.and(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (true, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (true, false, true)",
|
||||
! BooleanUtils.and(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (true, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, true, true)",
|
||||
! BooleanUtils.and(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, true, true)");
|
||||
}
|
||||
|
||||
// testOr
|
||||
// -----------------------------------------------------------------------
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testOr_primitive_nullInput() {
|
||||
BooleanUtils.or((boolean[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or((boolean[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testOr_primitive_emptyInput() {
|
||||
BooleanUtils.or(new boolean[] {});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or(new boolean[] {}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOr_primitive_validInput_2items() {
|
||||
assertTrue(
|
||||
"False result for (true, true)",
|
||||
BooleanUtils.or(new boolean[] { true, true }));
|
||||
BooleanUtils.or(new boolean[] { true, true }),
|
||||
"False result for (true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils.or(new boolean[] { false, false }));
|
||||
! BooleanUtils.or(new boolean[] { false, false }),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, false)",
|
||||
BooleanUtils.or(new boolean[] { true, false }));
|
||||
BooleanUtils.or(new boolean[] { true, false }),
|
||||
"False result for (true, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (false, true)",
|
||||
BooleanUtils.or(new boolean[] { false, true }));
|
||||
BooleanUtils.or(new boolean[] { false, true }),
|
||||
"False result for (false, true)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOr_primitive_validInput_3items() {
|
||||
assertTrue(
|
||||
"False result for (false, false, true)",
|
||||
BooleanUtils.or(new boolean[] { false, false, true }));
|
||||
BooleanUtils.or(new boolean[] { false, false, true }),
|
||||
"False result for (false, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (false, true, false)",
|
||||
BooleanUtils.or(new boolean[] { false, true, false }));
|
||||
BooleanUtils.or(new boolean[] { false, true, false }),
|
||||
"False result for (false, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, false, false)",
|
||||
BooleanUtils.or(new boolean[] { true, false, false }));
|
||||
BooleanUtils.or(new boolean[] { true, false, false }),
|
||||
"False result for (true, false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, true, true)",
|
||||
BooleanUtils.or(new boolean[] { true, true, true }));
|
||||
BooleanUtils.or(new boolean[] { true, true, true }),
|
||||
"False result for (true, true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils.or(new boolean[] { false, false, false }));
|
||||
! BooleanUtils.or(new boolean[] { false, false, false }),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, true, false)",
|
||||
BooleanUtils.or(new boolean[] { true, true, false }));
|
||||
BooleanUtils.or(new boolean[] { true, true, false }),
|
||||
"False result for (true, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, false, true)",
|
||||
BooleanUtils.or(new boolean[] { true, false, true }));
|
||||
BooleanUtils.or(new boolean[] { true, false, true }),
|
||||
"False result for (true, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (false, true, true)",
|
||||
BooleanUtils.or(new boolean[] { false, true, true }));
|
||||
BooleanUtils.or(new boolean[] { false, true, true }),
|
||||
"False result for (false, true, true)");
|
||||
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testOr_object_nullInput() {
|
||||
BooleanUtils.or((Boolean[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or((Boolean[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testOr_object_emptyInput() {
|
||||
BooleanUtils.or(new Boolean[] {});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or(new Boolean[] {}));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testOr_object_nullElementInput() {
|
||||
BooleanUtils.or(new Boolean[] {null});
|
||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or(new Boolean[] {null}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOr_object_validInput_2items() {
|
||||
assertTrue(
|
||||
"False result for (true, true)",
|
||||
BooleanUtils
|
||||
.or(new Boolean[] { Boolean.TRUE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils
|
||||
.or(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, false)",
|
||||
BooleanUtils
|
||||
.or(new Boolean[] { Boolean.TRUE, Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (false, true)",
|
||||
BooleanUtils
|
||||
.or(new Boolean[] { Boolean.FALSE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (false, true)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOr_object_validInput_3items() {
|
||||
assertTrue(
|
||||
"False result for (false, false, true)",
|
||||
BooleanUtils
|
||||
.or(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (false, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (false, true, false)",
|
||||
BooleanUtils
|
||||
.or(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (false, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, false, false)",
|
||||
BooleanUtils
|
||||
.or(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, true, true)",
|
||||
BooleanUtils
|
||||
.or(new Boolean[] { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, true, true)");
|
||||
|
||||
assertTrue(
|
||||
"True result for (false, false)",
|
||||
! BooleanUtils.or(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"True result for (false, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, true, false)",
|
||||
BooleanUtils.or(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, true, false)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (true, false, true)",
|
||||
BooleanUtils.or(
|
||||
new Boolean[] {
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (true, false, true)");
|
||||
|
||||
assertTrue(
|
||||
"False result for (false, true, true)",
|
||||
BooleanUtils.or(
|
||||
new Boolean[] {
|
||||
Boolean.FALSE,
|
||||
Boolean.TRUE,
|
||||
Boolean.TRUE })
|
||||
.booleanValue());
|
||||
.booleanValue(),
|
||||
"False result for (false, true, true)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets;
|
|||
public class CharEncodingTest {
|
||||
|
||||
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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharRange}.
|
||||
|
@ -398,10 +399,10 @@ public class CharRangeTest {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void testIteratorRemove() {
|
||||
final CharRange a = CharRange.is('a');
|
||||
final Iterator<Character> aIt = a.iterator();
|
||||
aIt.remove();
|
||||
assertThrows(UnsupportedOperationException.class, aIt::remove);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,18 +16,19 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
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.Modifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests CharSequenceUtils
|
||||
|
@ -64,14 +65,14 @@ public class CharSequenceUtilsTest {
|
|||
assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3));
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
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() {
|
||||
assertNull(CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
|
||||
}
|
||||
|
||||
static class TestData{
|
||||
|
@ -154,7 +155,7 @@ public class CharSequenceUtilsTest {
|
|||
}
|
||||
} else {
|
||||
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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharSet}.
|
||||
|
|
|
@ -16,16 +16,16 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharSetUtils}.
|
||||
|
|
|
@ -16,18 +16,18 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
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.Modifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.CharUtils}.
|
||||
|
|
|
@ -16,15 +16,16 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
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.Modifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -40,14 +41,15 @@ public class ClassPathUtilsTest {
|
|||
assertFalse(Modifier.isFinal(ClassPathUtils.class.getModifiers()));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedNameNullClassString() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties");
|
||||
@Test
|
||||
public void testToFullyQualifiedNameNullClassString() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedNameClassNull() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, null);
|
||||
@Test
|
||||
public void testToFullyQualifiedNameClassNull() {
|
||||
assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -58,14 +60,16 @@ public class ClassPathUtilsTest {
|
|||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedNameNullPackageString() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties");
|
||||
@Test
|
||||
public void testToFullyQualifiedNameNullPackageString() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedNamePackageNull() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null);
|
||||
@Test
|
||||
public void testToFullyQualifiedNamePackageNull() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -76,14 +80,15 @@ public class ClassPathUtilsTest {
|
|||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedPathClassNullString() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties");
|
||||
@Test
|
||||
public void testToFullyQualifiedPathClassNullString() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedPathClassNull() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, null);
|
||||
@Test
|
||||
public void testToFullyQualifiedPathClassNull() {
|
||||
assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -94,14 +99,16 @@ public class ClassPathUtilsTest {
|
|||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedPathPackageNullString() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties");
|
||||
@Test
|
||||
public void testToFullyQualifiedPathPackageNullString() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testToFullyQualifiedPathPackageNull() throws Exception {
|
||||
ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null);
|
||||
@Test
|
||||
public void testToFullyQualifiedPathPackageNull() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,15 +16,16 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
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.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.GenericParent;
|
||||
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}.
|
||||
|
@ -175,14 +176,14 @@ public class ClassUtilsTest {
|
|||
assertEquals("java.lang.String", ClassUtils.getAbbreviatedName(String.class, 20));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
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() {
|
||||
ClassUtils.getAbbreviatedName(String.class, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> ClassUtils.getAbbreviatedName(String.class, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -813,84 +814,84 @@ public class ClassUtilsTest {
|
|||
@Test
|
||||
public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
|
||||
// test byte conversions
|
||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE));
|
||||
assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.class, Byte.TYPE));
|
||||
assertTrue("byte -> short", ClassUtils.isAssignable(Byte.class, Short.TYPE));
|
||||
assertTrue("byte -> int", ClassUtils.isAssignable(Byte.class, Integer.TYPE));
|
||||
assertTrue("byte -> long", ClassUtils.isAssignable(Byte.class, Long.TYPE));
|
||||
assertTrue("byte -> float", ClassUtils.isAssignable(Byte.class, Float.TYPE));
|
||||
assertTrue("byte -> double", ClassUtils.isAssignable(Byte.class, Double.TYPE));
|
||||
assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Byte.class, Character.TYPE), "byte -> char");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Byte.TYPE), "byte -> byte");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Short.TYPE), "byte -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Integer.TYPE), "byte -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Long.TYPE), "byte -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Float.TYPE), "byte -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Double.TYPE), "byte -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Byte.class, Boolean.TYPE), "byte -> boolean");
|
||||
|
||||
// test short conversions
|
||||
assertFalse("short -> char", ClassUtils.isAssignable(Short.class, Character.TYPE));
|
||||
assertFalse("short -> byte", ClassUtils.isAssignable(Short.class, Byte.TYPE));
|
||||
assertTrue("short -> short", ClassUtils.isAssignable(Short.class, Short.TYPE));
|
||||
assertTrue("short -> int", ClassUtils.isAssignable(Short.class, Integer.TYPE));
|
||||
assertTrue("short -> long", ClassUtils.isAssignable(Short.class, Long.TYPE));
|
||||
assertTrue("short -> float", ClassUtils.isAssignable(Short.class, Float.TYPE));
|
||||
assertTrue("short -> double", ClassUtils.isAssignable(Short.class, Double.TYPE));
|
||||
assertFalse("short -> boolean", ClassUtils.isAssignable(Short.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Short.class, Character.TYPE), "short -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Short.class, Byte.TYPE), "short -> byte");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Short.TYPE), "short -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Integer.TYPE), "short -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Long.TYPE), "short -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Float.TYPE), "short -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Double.TYPE), "short -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Short.class, Boolean.TYPE), "short -> boolean");
|
||||
|
||||
// test char conversions
|
||||
assertTrue("char -> char", ClassUtils.isAssignable(Character.class, Character.TYPE));
|
||||
assertFalse("char -> byte", ClassUtils.isAssignable(Character.class, Byte.TYPE));
|
||||
assertFalse("char -> short", ClassUtils.isAssignable(Character.class, Short.TYPE));
|
||||
assertTrue("char -> int", ClassUtils.isAssignable(Character.class, Integer.TYPE));
|
||||
assertTrue("char -> long", ClassUtils.isAssignable(Character.class, Long.TYPE));
|
||||
assertTrue("char -> float", ClassUtils.isAssignable(Character.class, Float.TYPE));
|
||||
assertTrue("char -> double", ClassUtils.isAssignable(Character.class, Double.TYPE));
|
||||
assertFalse("char -> boolean", ClassUtils.isAssignable(Character.class, Boolean.TYPE));
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Character.TYPE), "char -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Character.class, Byte.TYPE), "char -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Character.class, Short.TYPE), "char -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Integer.TYPE), "char -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Long.TYPE), "char -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Float.TYPE), "char -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Double.TYPE), "char -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Character.class, Boolean.TYPE), "char -> boolean");
|
||||
|
||||
// test int conversions
|
||||
assertFalse("int -> char", ClassUtils.isAssignable(Integer.class, Character.TYPE));
|
||||
assertFalse("int -> byte", ClassUtils.isAssignable(Integer.class, Byte.TYPE));
|
||||
assertFalse("int -> short", ClassUtils.isAssignable(Integer.class, Short.TYPE));
|
||||
assertTrue("int -> int", ClassUtils.isAssignable(Integer.class, Integer.TYPE));
|
||||
assertTrue("int -> long", ClassUtils.isAssignable(Integer.class, Long.TYPE));
|
||||
assertTrue("int -> float", ClassUtils.isAssignable(Integer.class, Float.TYPE));
|
||||
assertTrue("int -> double", ClassUtils.isAssignable(Integer.class, Double.TYPE));
|
||||
assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Character.TYPE), "int -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Byte.TYPE), "int -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Short.TYPE), "int -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Integer.TYPE), "int -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Long.TYPE), "int -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Float.TYPE), "int -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Double.TYPE), "int -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Boolean.TYPE), "int -> boolean");
|
||||
|
||||
// test long conversions
|
||||
assertFalse("long -> char", ClassUtils.isAssignable(Long.class, Character.TYPE));
|
||||
assertFalse("long -> byte", ClassUtils.isAssignable(Long.class, Byte.TYPE));
|
||||
assertFalse("long -> short", ClassUtils.isAssignable(Long.class, Short.TYPE));
|
||||
assertFalse("long -> int", ClassUtils.isAssignable(Long.class, Integer.TYPE));
|
||||
assertTrue("long -> long", ClassUtils.isAssignable(Long.class, Long.TYPE));
|
||||
assertTrue("long -> float", ClassUtils.isAssignable(Long.class, Float.TYPE));
|
||||
assertTrue("long -> double", ClassUtils.isAssignable(Long.class, Double.TYPE));
|
||||
assertFalse("long -> boolean", ClassUtils.isAssignable(Long.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Character.TYPE), "long -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Byte.TYPE), "long -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Short.TYPE), "long -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Integer.TYPE), "long -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Long.class, Long.TYPE), "long -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Long.class, Float.TYPE), "long -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Long.class, Double.TYPE), "long -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Boolean.TYPE), "long -> boolean");
|
||||
|
||||
// test float conversions
|
||||
assertFalse("float -> char", ClassUtils.isAssignable(Float.class, Character.TYPE));
|
||||
assertFalse("float -> byte", ClassUtils.isAssignable(Float.class, Byte.TYPE));
|
||||
assertFalse("float -> short", ClassUtils.isAssignable(Float.class, Short.TYPE));
|
||||
assertFalse("float -> int", ClassUtils.isAssignable(Float.class, Integer.TYPE));
|
||||
assertFalse("float -> long", ClassUtils.isAssignable(Float.class, Long.TYPE));
|
||||
assertTrue("float -> float", ClassUtils.isAssignable(Float.class, Float.TYPE));
|
||||
assertTrue("float -> double", ClassUtils.isAssignable(Float.class, Double.TYPE));
|
||||
assertFalse("float -> boolean", ClassUtils.isAssignable(Float.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Character.TYPE), "float -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Byte.TYPE), "float -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Short.TYPE), "float -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Integer.TYPE), "float -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Long.TYPE), "float -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Float.class, Float.TYPE), "float -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Float.class, Double.TYPE), "float -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Boolean.TYPE), "float -> boolean");
|
||||
|
||||
// test double conversions
|
||||
assertFalse("double -> char", ClassUtils.isAssignable(Double.class, Character.TYPE));
|
||||
assertFalse("double -> byte", ClassUtils.isAssignable(Double.class, Byte.TYPE));
|
||||
assertFalse("double -> short", ClassUtils.isAssignable(Double.class, Short.TYPE));
|
||||
assertFalse("double -> int", ClassUtils.isAssignable(Double.class, Integer.TYPE));
|
||||
assertFalse("double -> long", ClassUtils.isAssignable(Double.class, Long.TYPE));
|
||||
assertFalse("double -> float", ClassUtils.isAssignable(Double.class, Float.TYPE));
|
||||
assertTrue("double -> double", ClassUtils.isAssignable(Double.class, Double.TYPE));
|
||||
assertFalse("double -> boolean", ClassUtils.isAssignable(Double.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Character.TYPE), "double -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Byte.TYPE), "double -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Short.TYPE), "double -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Integer.TYPE), "double -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Long.TYPE), "double -> long");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Float.TYPE), "double -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Double.class, Double.TYPE), "double -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Boolean.TYPE), "double -> boolean");
|
||||
|
||||
// test boolean conversions
|
||||
assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.class, Character.TYPE));
|
||||
assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.class, Byte.TYPE));
|
||||
assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.class, Short.TYPE));
|
||||
assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.class, Integer.TYPE));
|
||||
assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.class, Long.TYPE));
|
||||
assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.class, Float.TYPE));
|
||||
assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.class, Double.TYPE));
|
||||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Character.TYPE), "boolean -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Byte.TYPE), "boolean -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Short.TYPE), "boolean -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Integer.TYPE), "boolean -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Long.TYPE), "boolean -> long");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Float.TYPE), "boolean -> float");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Double.TYPE), "boolean -> double");
|
||||
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.TYPE), "boolean -> boolean");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -920,167 +921,167 @@ public class ClassUtilsTest {
|
|||
@Test
|
||||
public void test_isAssignable_Unboxing_Widening() throws Exception {
|
||||
// test byte conversions
|
||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE, true));
|
||||
assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.class, Byte.TYPE, true));
|
||||
assertTrue("byte -> short", ClassUtils.isAssignable(Byte.class, Short.TYPE, true));
|
||||
assertTrue("byte -> int", ClassUtils.isAssignable(Byte.class, Integer.TYPE, true));
|
||||
assertTrue("byte -> long", ClassUtils.isAssignable(Byte.class, Long.TYPE, true));
|
||||
assertTrue("byte -> float", ClassUtils.isAssignable(Byte.class, Float.TYPE, true));
|
||||
assertTrue("byte -> double", ClassUtils.isAssignable(Byte.class, Double.TYPE, true));
|
||||
assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Byte.class, Character.TYPE, true), "byte -> char");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Byte.TYPE, true), "byte -> byte");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Short.TYPE, true), "byte -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Integer.TYPE, true), "byte -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Long.TYPE, true), "byte -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Float.TYPE, true), "byte -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.class, Double.TYPE, true), "byte -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Byte.class, Boolean.TYPE, true), "byte -> boolean");
|
||||
|
||||
// test short conversions
|
||||
assertFalse("short -> char", ClassUtils.isAssignable(Short.class, Character.TYPE, true));
|
||||
assertFalse("short -> byte", ClassUtils.isAssignable(Short.class, Byte.TYPE, true));
|
||||
assertTrue("short -> short", ClassUtils.isAssignable(Short.class, Short.TYPE, true));
|
||||
assertTrue("short -> int", ClassUtils.isAssignable(Short.class, Integer.TYPE, true));
|
||||
assertTrue("short -> long", ClassUtils.isAssignable(Short.class, Long.TYPE, true));
|
||||
assertTrue("short -> float", ClassUtils.isAssignable(Short.class, Float.TYPE, true));
|
||||
assertTrue("short -> double", ClassUtils.isAssignable(Short.class, Double.TYPE, true));
|
||||
assertFalse("short -> boolean", ClassUtils.isAssignable(Short.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Short.class, Character.TYPE, true), "short -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Short.class, Byte.TYPE, true), "short -> byte");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Short.TYPE, true), "short -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Integer.TYPE, true), "short -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Long.TYPE, true), "short -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Float.TYPE, true), "short -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Short.class, Double.TYPE, true), "short -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Short.class, Boolean.TYPE, true), "short -> boolean");
|
||||
|
||||
// test char conversions
|
||||
assertTrue("char -> char", ClassUtils.isAssignable(Character.class, Character.TYPE, true));
|
||||
assertFalse("char -> byte", ClassUtils.isAssignable(Character.class, Byte.TYPE, true));
|
||||
assertFalse("char -> short", ClassUtils.isAssignable(Character.class, Short.TYPE, true));
|
||||
assertTrue("char -> int", ClassUtils.isAssignable(Character.class, Integer.TYPE, true));
|
||||
assertTrue("char -> long", ClassUtils.isAssignable(Character.class, Long.TYPE, true));
|
||||
assertTrue("char -> float", ClassUtils.isAssignable(Character.class, Float.TYPE, true));
|
||||
assertTrue("char -> double", ClassUtils.isAssignable(Character.class, Double.TYPE, true));
|
||||
assertFalse("char -> boolean", ClassUtils.isAssignable(Character.class, Boolean.TYPE, true));
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Character.TYPE, true), "char -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Character.class, Byte.TYPE, true), "char -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Character.class, Short.TYPE, true), "char -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Integer.TYPE, true), "char -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Long.TYPE, true), "char -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Float.TYPE, true), "char -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Character.class, Double.TYPE, true), "char -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Character.class, Boolean.TYPE, true), "char -> boolean");
|
||||
|
||||
// test int conversions
|
||||
assertFalse("int -> char", ClassUtils.isAssignable(Integer.class, Character.TYPE, true));
|
||||
assertFalse("int -> byte", ClassUtils.isAssignable(Integer.class, Byte.TYPE, true));
|
||||
assertFalse("int -> short", ClassUtils.isAssignable(Integer.class, Short.TYPE, true));
|
||||
assertTrue("int -> int", ClassUtils.isAssignable(Integer.class, Integer.TYPE, true));
|
||||
assertTrue("int -> long", ClassUtils.isAssignable(Integer.class, Long.TYPE, true));
|
||||
assertTrue("int -> float", ClassUtils.isAssignable(Integer.class, Float.TYPE, true));
|
||||
assertTrue("int -> double", ClassUtils.isAssignable(Integer.class, Double.TYPE, true));
|
||||
assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Character.TYPE, true), "int -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Byte.TYPE, true), "int -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Short.TYPE, true), "int -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Integer.TYPE, true), "int -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Long.TYPE, true), "int -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Float.TYPE, true), "int -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.class, Double.TYPE, true), "int -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.class, Boolean.TYPE, true), "int -> boolean");
|
||||
|
||||
// test long conversions
|
||||
assertFalse("long -> char", ClassUtils.isAssignable(Long.class, Character.TYPE, true));
|
||||
assertFalse("long -> byte", ClassUtils.isAssignable(Long.class, Byte.TYPE, true));
|
||||
assertFalse("long -> short", ClassUtils.isAssignable(Long.class, Short.TYPE, true));
|
||||
assertFalse("long -> int", ClassUtils.isAssignable(Long.class, Integer.TYPE, true));
|
||||
assertTrue("long -> long", ClassUtils.isAssignable(Long.class, Long.TYPE, true));
|
||||
assertTrue("long -> float", ClassUtils.isAssignable(Long.class, Float.TYPE, true));
|
||||
assertTrue("long -> double", ClassUtils.isAssignable(Long.class, Double.TYPE, true));
|
||||
assertFalse("long -> boolean", ClassUtils.isAssignable(Long.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Character.TYPE, true), "long -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Byte.TYPE, true), "long -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Short.TYPE, true), "long -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Integer.TYPE, true), "long -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Long.class, Long.TYPE, true), "long -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Long.class, Float.TYPE, true), "long -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Long.class, Double.TYPE, true), "long -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Long.class, Boolean.TYPE, true), "long -> boolean");
|
||||
|
||||
// test float conversions
|
||||
assertFalse("float -> char", ClassUtils.isAssignable(Float.class, Character.TYPE, true));
|
||||
assertFalse("float -> byte", ClassUtils.isAssignable(Float.class, Byte.TYPE, true));
|
||||
assertFalse("float -> short", ClassUtils.isAssignable(Float.class, Short.TYPE, true));
|
||||
assertFalse("float -> int", ClassUtils.isAssignable(Float.class, Integer.TYPE, true));
|
||||
assertFalse("float -> long", ClassUtils.isAssignable(Float.class, Long.TYPE, true));
|
||||
assertTrue("float -> float", ClassUtils.isAssignable(Float.class, Float.TYPE, true));
|
||||
assertTrue("float -> double", ClassUtils.isAssignable(Float.class, Double.TYPE, true));
|
||||
assertFalse("float -> boolean", ClassUtils.isAssignable(Float.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Character.TYPE, true), "float -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Byte.TYPE, true), "float -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Short.TYPE, true), "float -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Integer.TYPE, true), "float -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Long.TYPE, true), "float -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Float.class, Float.TYPE, true), "float -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Float.class, Double.TYPE, true), "float -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Float.class, Boolean.TYPE, true), "float -> boolean");
|
||||
|
||||
// test double conversions
|
||||
assertFalse("double -> char", ClassUtils.isAssignable(Double.class, Character.TYPE, true));
|
||||
assertFalse("double -> byte", ClassUtils.isAssignable(Double.class, Byte.TYPE, true));
|
||||
assertFalse("double -> short", ClassUtils.isAssignable(Double.class, Short.TYPE, true));
|
||||
assertFalse("double -> int", ClassUtils.isAssignable(Double.class, Integer.TYPE, true));
|
||||
assertFalse("double -> long", ClassUtils.isAssignable(Double.class, Long.TYPE, true));
|
||||
assertFalse("double -> float", ClassUtils.isAssignable(Double.class, Float.TYPE, true));
|
||||
assertTrue("double -> double", ClassUtils.isAssignable(Double.class, Double.TYPE, true));
|
||||
assertFalse("double -> boolean", ClassUtils.isAssignable(Double.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Character.TYPE, true), "double -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Byte.TYPE, true), "double -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Short.TYPE, true), "double -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Integer.TYPE, true), "double -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Long.TYPE, true), "double -> long");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Float.TYPE, true), "double -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Double.class, Double.TYPE, true), "double -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Double.class, Boolean.TYPE, true), "double -> boolean");
|
||||
|
||||
// test boolean conversions
|
||||
assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.class, Character.TYPE, true));
|
||||
assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.class, Byte.TYPE, true));
|
||||
assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.class, Short.TYPE, true));
|
||||
assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.class, Integer.TYPE, true));
|
||||
assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.class, Long.TYPE, true));
|
||||
assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.class, Float.TYPE, true));
|
||||
assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.class, Double.TYPE, true));
|
||||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true));
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Character.TYPE, true), "boolean -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Byte.TYPE, true), "boolean -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Short.TYPE, true), "boolean -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Integer.TYPE, true), "boolean -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Long.TYPE, true), "boolean -> long");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Float.TYPE, true), "boolean -> float");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.class, Double.TYPE, true), "boolean -> double");
|
||||
assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true), "boolean -> boolean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAssignable_Widening() throws Exception {
|
||||
// test byte conversions
|
||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.TYPE, Character.TYPE));
|
||||
assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.TYPE, Byte.TYPE));
|
||||
assertTrue("byte -> short", ClassUtils.isAssignable(Byte.TYPE, Short.TYPE));
|
||||
assertTrue("byte -> int", ClassUtils.isAssignable(Byte.TYPE, Integer.TYPE));
|
||||
assertTrue("byte -> long", ClassUtils.isAssignable(Byte.TYPE, Long.TYPE));
|
||||
assertTrue("byte -> float", ClassUtils.isAssignable(Byte.TYPE, Float.TYPE));
|
||||
assertTrue("byte -> double", ClassUtils.isAssignable(Byte.TYPE, Double.TYPE));
|
||||
assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Byte.TYPE, Character.TYPE), "byte -> char");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Byte.TYPE), "byte -> byte");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Short.TYPE), "byte -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Integer.TYPE), "byte -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Long.TYPE), "byte -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Float.TYPE), "byte -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Byte.TYPE, Double.TYPE), "byte -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Byte.TYPE, Boolean.TYPE), "byte -> boolean");
|
||||
|
||||
// test short conversions
|
||||
assertFalse("short -> char", ClassUtils.isAssignable(Short.TYPE, Character.TYPE));
|
||||
assertFalse("short -> byte", ClassUtils.isAssignable(Short.TYPE, Byte.TYPE));
|
||||
assertTrue("short -> short", ClassUtils.isAssignable(Short.TYPE, Short.TYPE));
|
||||
assertTrue("short -> int", ClassUtils.isAssignable(Short.TYPE, Integer.TYPE));
|
||||
assertTrue("short -> long", ClassUtils.isAssignable(Short.TYPE, Long.TYPE));
|
||||
assertTrue("short -> float", ClassUtils.isAssignable(Short.TYPE, Float.TYPE));
|
||||
assertTrue("short -> double", ClassUtils.isAssignable(Short.TYPE, Double.TYPE));
|
||||
assertFalse("short -> boolean", ClassUtils.isAssignable(Short.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Short.TYPE, Character.TYPE), "short -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Short.TYPE, Byte.TYPE), "short -> byte");
|
||||
assertTrue(ClassUtils.isAssignable(Short.TYPE, Short.TYPE), "short -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Short.TYPE, Integer.TYPE), "short -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Short.TYPE, Long.TYPE), "short -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Short.TYPE, Float.TYPE), "short -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Short.TYPE, Double.TYPE), "short -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Short.TYPE, Boolean.TYPE), "short -> boolean");
|
||||
|
||||
// test char conversions
|
||||
assertTrue("char -> char", ClassUtils.isAssignable(Character.TYPE, Character.TYPE));
|
||||
assertFalse("char -> byte", ClassUtils.isAssignable(Character.TYPE, Byte.TYPE));
|
||||
assertFalse("char -> short", ClassUtils.isAssignable(Character.TYPE, Short.TYPE));
|
||||
assertTrue("char -> int", ClassUtils.isAssignable(Character.TYPE, Integer.TYPE));
|
||||
assertTrue("char -> long", ClassUtils.isAssignable(Character.TYPE, Long.TYPE));
|
||||
assertTrue("char -> float", ClassUtils.isAssignable(Character.TYPE, Float.TYPE));
|
||||
assertTrue("char -> double", ClassUtils.isAssignable(Character.TYPE, Double.TYPE));
|
||||
assertFalse("char -> boolean", ClassUtils.isAssignable(Character.TYPE, Boolean.TYPE));
|
||||
assertTrue(ClassUtils.isAssignable(Character.TYPE, Character.TYPE), "char -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Character.TYPE, Byte.TYPE), "char -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Character.TYPE, Short.TYPE), "char -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Character.TYPE, Integer.TYPE), "char -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Character.TYPE, Long.TYPE), "char -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Character.TYPE, Float.TYPE), "char -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Character.TYPE, Double.TYPE), "char -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Character.TYPE, Boolean.TYPE), "char -> boolean");
|
||||
|
||||
// test int conversions
|
||||
assertFalse("int -> char", ClassUtils.isAssignable(Integer.TYPE, Character.TYPE));
|
||||
assertFalse("int -> byte", ClassUtils.isAssignable(Integer.TYPE, Byte.TYPE));
|
||||
assertFalse("int -> short", ClassUtils.isAssignable(Integer.TYPE, Short.TYPE));
|
||||
assertTrue("int -> int", ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE));
|
||||
assertTrue("int -> long", ClassUtils.isAssignable(Integer.TYPE, Long.TYPE));
|
||||
assertTrue("int -> float", ClassUtils.isAssignable(Integer.TYPE, Float.TYPE));
|
||||
assertTrue("int -> double", ClassUtils.isAssignable(Integer.TYPE, Double.TYPE));
|
||||
assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Character.TYPE), "int -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Byte.TYPE), "int -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Short.TYPE), "int -> short");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE), "int -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Long.TYPE), "int -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Float.TYPE), "int -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Integer.TYPE, Double.TYPE), "int -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Integer.TYPE, Boolean.TYPE), "int -> boolean");
|
||||
|
||||
// test long conversions
|
||||
assertFalse("long -> char", ClassUtils.isAssignable(Long.TYPE, Character.TYPE));
|
||||
assertFalse("long -> byte", ClassUtils.isAssignable(Long.TYPE, Byte.TYPE));
|
||||
assertFalse("long -> short", ClassUtils.isAssignable(Long.TYPE, Short.TYPE));
|
||||
assertFalse("long -> int", ClassUtils.isAssignable(Long.TYPE, Integer.TYPE));
|
||||
assertTrue("long -> long", ClassUtils.isAssignable(Long.TYPE, Long.TYPE));
|
||||
assertTrue("long -> float", ClassUtils.isAssignable(Long.TYPE, Float.TYPE));
|
||||
assertTrue("long -> double", ClassUtils.isAssignable(Long.TYPE, Double.TYPE));
|
||||
assertFalse("long -> boolean", ClassUtils.isAssignable(Long.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Long.TYPE, Character.TYPE), "long -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Long.TYPE, Byte.TYPE), "long -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Long.TYPE, Short.TYPE), "long -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Long.TYPE, Integer.TYPE), "long -> int");
|
||||
assertTrue(ClassUtils.isAssignable(Long.TYPE, Long.TYPE), "long -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Long.TYPE, Float.TYPE), "long -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Long.TYPE, Double.TYPE), "long -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Long.TYPE, Boolean.TYPE), "long -> boolean");
|
||||
|
||||
// test float conversions
|
||||
assertFalse("float -> char", ClassUtils.isAssignable(Float.TYPE, Character.TYPE));
|
||||
assertFalse("float -> byte", ClassUtils.isAssignable(Float.TYPE, Byte.TYPE));
|
||||
assertFalse("float -> short", ClassUtils.isAssignable(Float.TYPE, Short.TYPE));
|
||||
assertFalse("float -> int", ClassUtils.isAssignable(Float.TYPE, Integer.TYPE));
|
||||
assertFalse("float -> long", ClassUtils.isAssignable(Float.TYPE, Long.TYPE));
|
||||
assertTrue("float -> float", ClassUtils.isAssignable(Float.TYPE, Float.TYPE));
|
||||
assertTrue("float -> double", ClassUtils.isAssignable(Float.TYPE, Double.TYPE));
|
||||
assertFalse("float -> boolean", ClassUtils.isAssignable(Float.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Float.TYPE, Character.TYPE), "float -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Float.TYPE, Byte.TYPE), "float -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Float.TYPE, Short.TYPE), "float -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Float.TYPE, Integer.TYPE), "float -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Float.TYPE, Long.TYPE), "float -> long");
|
||||
assertTrue(ClassUtils.isAssignable(Float.TYPE, Float.TYPE), "float -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Float.TYPE, Double.TYPE), "float -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Float.TYPE, Boolean.TYPE), "float -> boolean");
|
||||
|
||||
// test double conversions
|
||||
assertFalse("double -> char", ClassUtils.isAssignable(Double.TYPE, Character.TYPE));
|
||||
assertFalse("double -> byte", ClassUtils.isAssignable(Double.TYPE, Byte.TYPE));
|
||||
assertFalse("double -> short", ClassUtils.isAssignable(Double.TYPE, Short.TYPE));
|
||||
assertFalse("double -> int", ClassUtils.isAssignable(Double.TYPE, Integer.TYPE));
|
||||
assertFalse("double -> long", ClassUtils.isAssignable(Double.TYPE, Long.TYPE));
|
||||
assertFalse("double -> float", ClassUtils.isAssignable(Double.TYPE, Float.TYPE));
|
||||
assertTrue("double -> double", ClassUtils.isAssignable(Double.TYPE, Double.TYPE));
|
||||
assertFalse("double -> boolean", ClassUtils.isAssignable(Double.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Character.TYPE), "double -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Byte.TYPE), "double -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Short.TYPE), "double -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Integer.TYPE), "double -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Long.TYPE), "double -> long");
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Float.TYPE), "double -> float");
|
||||
assertTrue(ClassUtils.isAssignable(Double.TYPE, Double.TYPE), "double -> double");
|
||||
assertFalse(ClassUtils.isAssignable(Double.TYPE, Boolean.TYPE), "double -> boolean");
|
||||
|
||||
// test boolean conversions
|
||||
assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.TYPE, Character.TYPE));
|
||||
assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.TYPE, Byte.TYPE));
|
||||
assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.TYPE, Short.TYPE));
|
||||
assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.TYPE, Integer.TYPE));
|
||||
assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.TYPE, Long.TYPE));
|
||||
assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.TYPE, Float.TYPE));
|
||||
assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.TYPE, Double.TYPE));
|
||||
assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Character.TYPE), "boolean -> char");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Byte.TYPE), "boolean -> byte");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Short.TYPE), "boolean -> short");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Integer.TYPE), "boolean -> int");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Long.TYPE), "boolean -> long");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Float.TYPE), "boolean -> float");
|
||||
assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Double.TYPE), "boolean -> double");
|
||||
assertTrue(ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE), "boolean -> boolean");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -1244,76 +1245,76 @@ public class ClassUtilsTest {
|
|||
public void testIsPrimitiveOrWrapper() {
|
||||
|
||||
// test primitive wrapper classes
|
||||
assertTrue("Boolean.class", ClassUtils.isPrimitiveOrWrapper(Boolean.class));
|
||||
assertTrue("Byte.class", ClassUtils.isPrimitiveOrWrapper(Byte.class));
|
||||
assertTrue("Character.class", ClassUtils.isPrimitiveOrWrapper(Character.class));
|
||||
assertTrue("Short.class", ClassUtils.isPrimitiveOrWrapper(Short.class));
|
||||
assertTrue("Integer.class", ClassUtils.isPrimitiveOrWrapper(Integer.class));
|
||||
assertTrue("Long.class", ClassUtils.isPrimitiveOrWrapper(Long.class));
|
||||
assertTrue("Double.class", ClassUtils.isPrimitiveOrWrapper(Double.class));
|
||||
assertTrue("Float.class", ClassUtils.isPrimitiveOrWrapper(Float.class));
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.class), "Boolean.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Byte.class), "Byte.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Character.class), "Character.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Short.class), "Short.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Integer.class), "Integer.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Long.class), "Long.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Double.class), "Double.class");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Float.class), "Float.class");
|
||||
|
||||
// test primitive classes
|
||||
assertTrue("boolean", ClassUtils.isPrimitiveOrWrapper(Boolean.TYPE));
|
||||
assertTrue("byte", ClassUtils.isPrimitiveOrWrapper(Byte.TYPE));
|
||||
assertTrue("char", ClassUtils.isPrimitiveOrWrapper(Character.TYPE));
|
||||
assertTrue("short", ClassUtils.isPrimitiveOrWrapper(Short.TYPE));
|
||||
assertTrue("int", ClassUtils.isPrimitiveOrWrapper(Integer.TYPE));
|
||||
assertTrue("long", ClassUtils.isPrimitiveOrWrapper(Long.TYPE));
|
||||
assertTrue("double", ClassUtils.isPrimitiveOrWrapper(Double.TYPE));
|
||||
assertTrue("float", ClassUtils.isPrimitiveOrWrapper(Float.TYPE));
|
||||
assertTrue("Void.TYPE", ClassUtils.isPrimitiveOrWrapper(Void.TYPE));
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.TYPE), "boolean");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Byte.TYPE), "byte");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Character.TYPE), "char");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Short.TYPE), "short");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Integer.TYPE), "int");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Long.TYPE), "long");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Double.TYPE), "double");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Float.TYPE), "float");
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Void.TYPE), "Void.TYPE");
|
||||
|
||||
// others
|
||||
assertFalse("null", ClassUtils.isPrimitiveOrWrapper(null));
|
||||
assertFalse("Void.class", ClassUtils.isPrimitiveOrWrapper(Void.class));
|
||||
assertFalse("String.class", ClassUtils.isPrimitiveOrWrapper(String.class));
|
||||
assertFalse("this.getClass()", ClassUtils.isPrimitiveOrWrapper(this.getClass()));
|
||||
assertFalse(ClassUtils.isPrimitiveOrWrapper(null), "null");
|
||||
assertFalse(ClassUtils.isPrimitiveOrWrapper(Void.class), "Void.class");
|
||||
assertFalse(ClassUtils.isPrimitiveOrWrapper(String.class), "String.class");
|
||||
assertFalse(ClassUtils.isPrimitiveOrWrapper(this.getClass()), "this.getClass()");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPrimitiveWrapper() {
|
||||
|
||||
// test primitive wrapper classes
|
||||
assertTrue("Boolean.class", ClassUtils.isPrimitiveWrapper(Boolean.class));
|
||||
assertTrue("Byte.class", ClassUtils.isPrimitiveWrapper(Byte.class));
|
||||
assertTrue("Character.class", ClassUtils.isPrimitiveWrapper(Character.class));
|
||||
assertTrue("Short.class", ClassUtils.isPrimitiveWrapper(Short.class));
|
||||
assertTrue("Integer.class", ClassUtils.isPrimitiveWrapper(Integer.class));
|
||||
assertTrue("Long.class", ClassUtils.isPrimitiveWrapper(Long.class));
|
||||
assertTrue("Double.class", ClassUtils.isPrimitiveWrapper(Double.class));
|
||||
assertTrue("Float.class", ClassUtils.isPrimitiveWrapper(Float.class));
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Boolean.class), "Boolean.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Byte.class), "Byte.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Character.class), "Character.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Short.class), "Short.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Integer.class), "Integer.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Long.class), "Long.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Double.class), "Double.class");
|
||||
assertTrue(ClassUtils.isPrimitiveWrapper(Float.class), "Float.class");
|
||||
|
||||
// test primitive classes
|
||||
assertFalse("boolean", ClassUtils.isPrimitiveWrapper(Boolean.TYPE));
|
||||
assertFalse("byte", ClassUtils.isPrimitiveWrapper(Byte.TYPE));
|
||||
assertFalse("char", ClassUtils.isPrimitiveWrapper(Character.TYPE));
|
||||
assertFalse("short", ClassUtils.isPrimitiveWrapper(Short.TYPE));
|
||||
assertFalse("int", ClassUtils.isPrimitiveWrapper(Integer.TYPE));
|
||||
assertFalse("long", ClassUtils.isPrimitiveWrapper(Long.TYPE));
|
||||
assertFalse("double", ClassUtils.isPrimitiveWrapper(Double.TYPE));
|
||||
assertFalse("float", ClassUtils.isPrimitiveWrapper(Float.TYPE));
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Boolean.TYPE), "boolean");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Byte.TYPE), "byte");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Character.TYPE), "char");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Short.TYPE), "short");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Integer.TYPE), "int");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Long.TYPE), "long");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Double.TYPE), "double");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Float.TYPE), "float");
|
||||
|
||||
// others
|
||||
assertFalse("null", ClassUtils.isPrimitiveWrapper(null));
|
||||
assertFalse("Void.class", ClassUtils.isPrimitiveWrapper(Void.class));
|
||||
assertFalse("Void.TYPE", ClassUtils.isPrimitiveWrapper(Void.TYPE));
|
||||
assertFalse("String.class", ClassUtils.isPrimitiveWrapper(String.class));
|
||||
assertFalse("this.getClass()", ClassUtils.isPrimitiveWrapper(this.getClass()));
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(null), "null");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Void.class), "Void.class");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(Void.TYPE), "Void.TYPE");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(String.class), "String.class");
|
||||
assertFalse(ClassUtils.isPrimitiveWrapper(this.getClass()), "this.getClass()");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitivesToWrappers() {
|
||||
// test null
|
||||
// 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
|
||||
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}
|
||||
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
|
||||
assertArrayEquals("empty -> empty",
|
||||
ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY));
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY),
|
||||
"empty -> empty");
|
||||
|
||||
// test an array of various classes
|
||||
final Class<?>[] primitives = new Class[] {
|
||||
|
@ -1328,7 +1329,7 @@ public class ClassUtilsTest {
|
|||
final Class<?> primitive = primitives[i];
|
||||
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
|
||||
|
@ -1336,42 +1337,30 @@ public class ClassUtilsTest {
|
|||
String.class, ClassUtils.class, Void.TYPE
|
||||
};
|
||||
// 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
|
||||
public void testPrimitiveToWrapper() {
|
||||
|
||||
// test primitive classes
|
||||
assertEquals("boolean -> Boolean.class",
|
||||
Boolean.class, ClassUtils.primitiveToWrapper(Boolean.TYPE));
|
||||
assertEquals("byte -> Byte.class",
|
||||
Byte.class, ClassUtils.primitiveToWrapper(Byte.TYPE));
|
||||
assertEquals("char -> Character.class",
|
||||
Character.class, ClassUtils.primitiveToWrapper(Character.TYPE));
|
||||
assertEquals("short -> Short.class",
|
||||
Short.class, ClassUtils.primitiveToWrapper(Short.TYPE));
|
||||
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));
|
||||
assertEquals(Boolean.class, ClassUtils.primitiveToWrapper(Boolean.TYPE), "boolean -> Boolean.class");
|
||||
assertEquals(Byte.class, ClassUtils.primitiveToWrapper(Byte.TYPE), "byte -> Byte.class");
|
||||
assertEquals(Character.class, ClassUtils.primitiveToWrapper(Character.TYPE), "char -> Character.class");
|
||||
assertEquals(Short.class, ClassUtils.primitiveToWrapper(Short.TYPE), "short -> Short.class");
|
||||
assertEquals(Integer.class, ClassUtils.primitiveToWrapper(Integer.TYPE), "int -> Integer.class");
|
||||
assertEquals(Long.class, ClassUtils.primitiveToWrapper(Long.TYPE), "long -> Long.class");
|
||||
assertEquals(Double.class, ClassUtils.primitiveToWrapper(Double.TYPE), "double -> Double.class");
|
||||
assertEquals(Float.class, ClassUtils.primitiveToWrapper(Float.TYPE), "float -> Float.class");
|
||||
|
||||
// test a few other classes
|
||||
assertEquals("String.class -> String.class",
|
||||
String.class, ClassUtils.primitiveToWrapper(String.class));
|
||||
assertEquals("ClassUtils.class -> ClassUtils.class",
|
||||
org.apache.commons.lang3.ClassUtils.class,
|
||||
ClassUtils.primitiveToWrapper(org.apache.commons.lang3.ClassUtils.class));
|
||||
assertEquals("Void.TYPE -> Void.TYPE",
|
||||
Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE));
|
||||
assertEquals(String.class, ClassUtils.primitiveToWrapper(String.class), "String.class -> String.class");
|
||||
assertEquals(ClassUtils.class, ClassUtils.primitiveToWrapper(ClassUtils.class),
|
||||
"ClassUtils.class -> ClassUtils.class");
|
||||
assertEquals(Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE), "Void.TYPE -> Void.TYPE");
|
||||
|
||||
// test null
|
||||
assertNull("null -> null",
|
||||
ClassUtils.primitiveToWrapper(null));
|
||||
assertNull(ClassUtils.primitiveToWrapper(null), "null -> null");
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// 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}
|
||||
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));
|
||||
|
||||
|
@ -1427,28 +1416,27 @@ public class ClassUtilsTest {
|
|||
|
||||
final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
|
||||
// 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++) {
|
||||
final Class<?> expectedPrimitive = ClassUtils.wrapperToPrimitive(classes[i]);
|
||||
assertEquals(classes[i] + " -> " + expectedPrimitive, expectedPrimitive,
|
||||
primitives[i]);
|
||||
assertEquals(expectedPrimitive, primitives[i], classes[i] + " -> " + expectedPrimitive);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappersToPrimitivesEmpty() {
|
||||
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
|
||||
public void testWrappersToPrimitivesNull() {
|
||||
// assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives(null)); // generates warning
|
||||
assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives((Class<?>[]) null)); // equivalent cast
|
||||
assertNull(ClassUtils.wrappersToPrimitives((Class<?>[]) null), "Wrong result for null input"); // equivalent cast
|
||||
// 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}
|
||||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
||||
assertTrue(Arrays.equals(new Class<?>[]{null}, castNull), "(Class<?>)null -> [null]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1460,19 +1448,18 @@ public class ClassUtilsTest {
|
|||
};
|
||||
for (final Class<?> primitive : primitives) {
|
||||
final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
|
||||
assertFalse("Still primitive", wrapperCls.isPrimitive());
|
||||
assertEquals(wrapperCls + " -> " + primitive, primitive,
|
||||
ClassUtils.wrapperToPrimitive(wrapperCls));
|
||||
assertFalse(wrapperCls.isPrimitive(), "Still primitive");
|
||||
assertEquals(primitive, ClassUtils.wrapperToPrimitive(wrapperCls), wrapperCls + " -> " + primitive);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
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;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
assertEquals(expected.length, actual.length);
|
||||
for (int i = 0; i < expected.length; i++ ) {
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -29,8 +30,8 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -46,7 +47,7 @@ public class EnumUtilsTest {
|
|||
@Test
|
||||
public void test_getEnumMap() {
|
||||
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());
|
||||
assertTrue(test.containsKey("RED"));
|
||||
assertEquals(Traffic.RED, test.get("RED"));
|
||||
|
@ -75,9 +76,9 @@ public class EnumUtilsTest {
|
|||
assertFalse(EnumUtils.isValidEnum(Traffic.class, null));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
@Test
|
||||
public void test_isValidEnum_nullClass() {
|
||||
EnumUtils.isValidEnum(null, "PURPLE");
|
||||
assertThrows(NullPointerException.class, () -> EnumUtils.isValidEnum(null, "PURPLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,9 +90,9 @@ public class EnumUtilsTest {
|
|||
assertFalse(EnumUtils.isValidEnumIgnoreCase(Traffic.class, null));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
@Test
|
||||
public void test_isValidEnumIgnoreCase_nullClass() {
|
||||
EnumUtils.isValidEnumIgnoreCase(null, "PURPLE");
|
||||
assertThrows(NullPointerException.class, () -> EnumUtils.isValidEnumIgnoreCase(null, "PURPLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -109,9 +110,9 @@ public class EnumUtilsTest {
|
|||
assertNull(EnumUtils.getEnum(rawType, "rawType"));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
@Test
|
||||
public void test_getEnum_nullClass() {
|
||||
EnumUtils.getEnum((Class<Traffic>) null, "PURPLE");
|
||||
assertThrows(NullPointerException.class, () -> EnumUtils.getEnum((Class<Traffic>) null, "PURPLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,83 +130,89 @@ public class EnumUtilsTest {
|
|||
assertNull(EnumUtils.getEnumIgnoreCase(rawType, "rawType"));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
EnumUtils.generateBitVector(null, Traffic.RED);
|
||||
assertThrows(NullPointerException.class, () -> EnumUtils.generateBitVector(null, Traffic.RED));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
@Test
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
EnumUtils.generateBitVector(TooMany.class, TooMany.A1);
|
||||
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVector(TooMany.class, TooMany.A1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_generateBitVector_nonEnumClass() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
|
@ -213,11 +220,11 @@ public class EnumUtilsTest {
|
|||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
List rawList = new ArrayList();
|
||||
EnumUtils.generateBitVector(rawType, rawList);
|
||||
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVector(rawType, rawList));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_generateBitVectors_nonEnumClass() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
|
@ -225,25 +232,25 @@ public class EnumUtilsTest {
|
|||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
List rawList = new ArrayList();
|
||||
EnumUtils.generateBitVectors(rawType, rawList);
|
||||
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVectors(rawType, rawList));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_generateBitVector_nonEnumClassWithArray() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
Class rawType = Object.class;
|
||||
EnumUtils.generateBitVector(rawType);
|
||||
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVector(rawType));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_generateBitVectors_nonEnumClassWithArray() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
Class rawType = Object.class;
|
||||
EnumUtils.generateBitVectors(rawType);
|
||||
assertThrows(IllegalArgumentException.class, () -> EnumUtils.generateBitVectors(rawType));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -332,19 +339,19 @@ public class EnumUtilsTest {
|
|||
}
|
||||
|
||||
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() {
|
||||
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() {
|
||||
final Class<Traffic> empty = null;
|
||||
EnumUtils.processBitVectors(empty, 0L);
|
||||
assertThrows(NullPointerException.class, () -> EnumUtils.processBitVectors(empty, 0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -402,9 +409,9 @@ public class EnumUtilsTest {
|
|||
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, Long.MIN_VALUE));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_processBitVector_longClass() {
|
||||
EnumUtils.processBitVector(TooMany.class, 0L);
|
||||
assertThrows(IllegalArgumentException.class, () -> EnumUtils.processBitVector(TooMany.class, 0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
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_1_1;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||
|
@ -45,32 +45,32 @@ public class JavaVersionTest {
|
|||
|
||||
@Test
|
||||
public void testGetJavaVersion() {
|
||||
assertEquals("0.9 failed", JAVA_0_9, get("0.9"));
|
||||
assertEquals("1.1 failed", JAVA_1_1, get("1.1"));
|
||||
assertEquals("1.2 failed", JAVA_1_2, get("1.2"));
|
||||
assertEquals("1.3 failed", JAVA_1_3, get("1.3"));
|
||||
assertEquals("1.4 failed", JAVA_1_4, get("1.4"));
|
||||
assertEquals("1.5 failed", JAVA_1_5, get("1.5"));
|
||||
assertEquals("1.6 failed", JAVA_1_6, get("1.6"));
|
||||
assertEquals("1.7 failed", JAVA_1_7, get("1.7"));
|
||||
assertEquals("1.8 failed", JAVA_1_8, get("1.8"));
|
||||
assertEquals("9 failed", JAVA_9, get("9"));
|
||||
assertEquals("10 failed", JAVA_10, get("10"));
|
||||
assertEquals("11 failed", JavaVersion.JAVA_11, get("11"));
|
||||
assertEquals("1.10 failed", JAVA_RECENT, get("1.10"));
|
||||
assertEquals(JAVA_0_9, get("0.9"), "0.9 failed");
|
||||
assertEquals(JAVA_1_1, get("1.1"), "1.1 failed");
|
||||
assertEquals(JAVA_1_2, get("1.2"), "1.2 failed");
|
||||
assertEquals(JAVA_1_3, get("1.3"), "1.3 failed");
|
||||
assertEquals(JAVA_1_4, get("1.4"), "1.4 failed");
|
||||
assertEquals(JAVA_1_5, get("1.5"), "1.5 failed");
|
||||
assertEquals(JAVA_1_6, get("1.6"), "1.6 failed");
|
||||
assertEquals(JAVA_1_7, get("1.7"), "1.7 failed");
|
||||
assertEquals(JAVA_1_8, get("1.8"), "1.8 failed");
|
||||
assertEquals(JAVA_9, get("9"), "9 failed");
|
||||
assertEquals(JAVA_10, get("10"), "10 failed");
|
||||
assertEquals(JavaVersion.JAVA_11, get("11"), "11 failed");
|
||||
assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed");
|
||||
// assertNull("2.10 unexpectedly worked", get("2.10"));
|
||||
assertEquals("Wrapper method failed", get("1.5"), getJavaVersion("1.5"));
|
||||
assertEquals("Unhandled", JAVA_RECENT, get("12")); // LANG-1384
|
||||
assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed");
|
||||
assertEquals(JAVA_RECENT, get("12"), "Unhandled"); // LANG-1384
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtLeast() {
|
||||
assertFalse("1.2 at least 1.5 passed", JAVA_1_2.atLeast(JAVA_1_5));
|
||||
assertTrue("1.5 at least 1.2 failed", JAVA_1_5.atLeast(JAVA_1_2));
|
||||
assertFalse("1.6 at least 1.7 passed", JAVA_1_6.atLeast(JAVA_1_7));
|
||||
assertFalse(JAVA_1_2.atLeast(JAVA_1_5), "1.2 at least 1.5 passed");
|
||||
assertTrue(JAVA_1_5.atLeast(JAVA_1_2), "1.5 at least 1.2 failed");
|
||||
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));
|
||||
assertFalse("0.9 at least 1.6 passed", JAVA_0_9.atLeast(JAVA_1_6));
|
||||
assertTrue(JAVA_0_9.atLeast(JAVA_1_5), "0.9 at least 1.5 failed");
|
||||
assertFalse(JAVA_0_9.atLeast(JAVA_1_6), "0.9 at least 1.6 passed");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
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.Modifier;
|
||||
|
@ -35,8 +35,8 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 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_ZZ = new Locale("qq", "ZZ");
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
// Testing #LANG-304. Must be called before availableLocaleSet is called.
|
||||
LocaleUtils.isAvailableLocale(Locale.getDefault());
|
||||
|
@ -79,7 +79,7 @@ public class LocaleUtilsTest {
|
|||
*/
|
||||
private static void assertValidToLocale(final String language) {
|
||||
final Locale locale = LocaleUtils.toLocale(language);
|
||||
assertNotNull("valid locale", locale);
|
||||
assertNotNull(locale, "valid locale");
|
||||
assertEquals(language, locale.getLanguage());
|
||||
//country and variant are empty
|
||||
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) {
|
||||
final Locale locale = LocaleUtils.toLocale(localeString);
|
||||
assertNotNull("valid locale", locale);
|
||||
assertNotNull(locale, "valid locale");
|
||||
assertEquals(language, locale.getLanguage());
|
||||
assertEquals(country, locale.getCountry());
|
||||
//variant is empty
|
||||
|
@ -114,7 +114,7 @@ public class LocaleUtilsTest {
|
|||
final String localeString, final String language,
|
||||
final String country, final String variant) {
|
||||
final Locale locale = LocaleUtils.toLocale(localeString);
|
||||
assertNotNull("valid locale", locale);
|
||||
assertNotNull(locale, "valid locale");
|
||||
assertEquals(language, locale.getLanguage());
|
||||
assertEquals(country, locale.getCountry());
|
||||
assertEquals(variant, locale.getVariant());
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
assertNotNull(assertMessage + ": target is null", nie);
|
||||
assertEquals(assertMessage + ": Message not equal", message, nie.getMessage());
|
||||
assertEquals(assertMessage + ": Nested throwable not equal", nested, nie.getCause());
|
||||
assertEquals(assertMessage + ": Code not equal", code, nie.getCode());
|
||||
assertNotNull(nie, assertMessage + ": target is null");
|
||||
assertEquals(message, nie.getMessage(), assertMessage + ": Message not equal");
|
||||
assertEquals(nested, nie.getCause(), assertMessage + ": Nested throwable not equal");
|
||||
assertEquals(code, nie.getCode(), assertMessage + ": Code not equal");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
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.mutable.MutableObject;
|
||||
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}.
|
||||
|
@ -111,8 +112,8 @@ public class ObjectUtilsTest {
|
|||
public void testIsNull() {
|
||||
final Object o = FOO;
|
||||
final Object dflt = BAR;
|
||||
assertSame("dflt was not returned when o was null", dflt, ObjectUtils.defaultIfNull(null, dflt));
|
||||
assertSame("dflt was returned when o was not null", o, ObjectUtils.defaultIfNull(o, dflt));
|
||||
assertSame(dflt, ObjectUtils.defaultIfNull(null, dflt), "dflt was not returned when o was null");
|
||||
assertSame(o, ObjectUtils.defaultIfNull(o, dflt), "dflt was returned when o was not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -168,20 +169,20 @@ public class ObjectUtilsTest {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertTrue("ObjectUtils.equals(null, null) returned false", ObjectUtils.equals(null, null));
|
||||
assertTrue("ObjectUtils.equals(\"foo\", null) returned true", !ObjectUtils.equals(FOO, null));
|
||||
assertTrue("ObjectUtils.equals(null, \"bar\") returned true", !ObjectUtils.equals(null, BAR));
|
||||
assertTrue("ObjectUtils.equals(\"foo\", \"bar\") returned true", !ObjectUtils.equals(FOO, BAR));
|
||||
assertTrue("ObjectUtils.equals(\"foo\", \"foo\") returned false", ObjectUtils.equals(FOO, FOO));
|
||||
assertTrue(ObjectUtils.equals(null, null), "ObjectUtils.equals(null, null) returned false");
|
||||
assertTrue(!ObjectUtils.equals(FOO, null), "ObjectUtils.equals(\"foo\", null) returned true");
|
||||
assertTrue(!ObjectUtils.equals(null, BAR), "ObjectUtils.equals(null, \"bar\") returned true");
|
||||
assertTrue(!ObjectUtils.equals(FOO, BAR), "ObjectUtils.equals(\"foo\", \"bar\") returned true");
|
||||
assertTrue(ObjectUtils.equals(FOO, FOO), "ObjectUtils.equals(\"foo\", \"foo\") returned false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEqual() {
|
||||
assertFalse("ObjectUtils.notEqual(null, null) returned false", ObjectUtils.notEqual(null, null));
|
||||
assertTrue("ObjectUtils.notEqual(\"foo\", null) returned true", ObjectUtils.notEqual(FOO, null));
|
||||
assertTrue("ObjectUtils.notEqual(null, \"bar\") returned true", ObjectUtils.notEqual(null, BAR));
|
||||
assertTrue("ObjectUtils.notEqual(\"foo\", \"bar\") returned true", ObjectUtils.notEqual(FOO, BAR));
|
||||
assertFalse("ObjectUtils.notEqual(\"foo\", \"foo\") returned false", ObjectUtils.notEqual(FOO, FOO));
|
||||
assertFalse(ObjectUtils.notEqual(null, null), "ObjectUtils.notEqual(null, null) returned false");
|
||||
assertTrue(ObjectUtils.notEqual(FOO, null), "ObjectUtils.notEqual(\"foo\", null) returned true");
|
||||
assertTrue(ObjectUtils.notEqual(null, BAR), "ObjectUtils.notEqual(null, \"bar\") returned true");
|
||||
assertTrue(ObjectUtils.notEqual(FOO, BAR), "ObjectUtils.notEqual(\"foo\", \"bar\") returned true");
|
||||
assertFalse(ObjectUtils.notEqual(FOO, FOO), "ObjectUtils.notEqual(\"foo\", \"foo\") returned false");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -430,17 +431,17 @@ public class ObjectUtilsTest {
|
|||
final Integer two = Integer.valueOf(2);
|
||||
final Integer nullValue = null;
|
||||
|
||||
assertEquals("Null Null false", 0, ObjectUtils.compare(nullValue, nullValue));
|
||||
assertEquals("Null Null true", 0, ObjectUtils.compare(nullValue, nullValue, true));
|
||||
assertEquals(0, ObjectUtils.compare(nullValue, nullValue), "Null Null false");
|
||||
assertEquals(0, ObjectUtils.compare(nullValue, nullValue, true), "Null Null true");
|
||||
|
||||
assertEquals("Null one false", -1, ObjectUtils.compare(nullValue, one));
|
||||
assertEquals("Null one true", 1, ObjectUtils.compare(nullValue, one, true));
|
||||
assertEquals(-1, ObjectUtils.compare(nullValue, one), "Null one false");
|
||||
assertEquals(1, ObjectUtils.compare(nullValue, one, true), "Null one true");
|
||||
|
||||
assertEquals("one Null false", 1, ObjectUtils.compare(one, nullValue));
|
||||
assertEquals("one Null true", -1, ObjectUtils.compare(one, nullValue, true));
|
||||
assertEquals(1, ObjectUtils.compare(one, nullValue), "one Null false");
|
||||
assertEquals(-1, ObjectUtils.compare(one, nullValue, true), "one Null true");
|
||||
|
||||
assertEquals("one two false", -1, ObjectUtils.compare(one, two));
|
||||
assertEquals("one two true", -1, ObjectUtils.compare(one, two, true));
|
||||
assertEquals(-1, ObjectUtils.compare(one, two), "one two false");
|
||||
assertEquals(-1, ObjectUtils.compare(one, two, true), "one two true");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -460,14 +461,14 @@ public class ObjectUtilsTest {
|
|||
ObjectUtils.median(Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8)));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testMedian_nullItems() {
|
||||
ObjectUtils.median((String[]) null);
|
||||
assertThrows(NullPointerException.class, () -> ObjectUtils.median((String[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testMedian_emptyItems() {
|
||||
ObjectUtils.<String> median();
|
||||
assertThrows(IllegalArgumentException.class, ObjectUtils::<String>median);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -485,19 +486,21 @@ public class ObjectUtilsTest {
|
|||
assertSame(blah, ObjectUtils.median(cmp, foo, bar, baz, blah, wah));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
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() {
|
||||
ObjectUtils.median(new CharSequenceComparator(), (CharSequence[]) null);
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ObjectUtils.median(new CharSequenceComparator(), (CharSequence[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testComparatorMedian_emptyItems() {
|
||||
ObjectUtils.median(new CharSequenceComparator());
|
||||
assertThrows(IllegalArgumentException.class, () -> ObjectUtils.median(new CharSequenceComparator()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -532,18 +535,12 @@ public class ObjectUtilsTest {
|
|||
|
||||
/**
|
||||
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
|
||||
*
|
||||
* @throws java.lang.Throwable because we expect this to fail
|
||||
*/
|
||||
@Test(expected = NoSuchMethodException.class)
|
||||
public void testCloneOfUncloneable() throws Throwable {
|
||||
@Test
|
||||
public void testCloneOfUncloneable() {
|
||||
final UncloneableString string = new UncloneableString("apache");
|
||||
try {
|
||||
ObjectUtils.clone(string);
|
||||
fail("Thrown " + CloneFailedException.class.getName() + " expected");
|
||||
} catch (final CloneFailedException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.clone(string));
|
||||
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -584,18 +581,12 @@ public class ObjectUtilsTest {
|
|||
|
||||
/**
|
||||
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
|
||||
*
|
||||
* @throws java.lang.Throwable because we expect this to fail
|
||||
*/
|
||||
@Test(expected = NoSuchMethodException.class)
|
||||
public void testPossibleCloneOfUncloneable() throws Throwable {
|
||||
@Test
|
||||
public void testPossibleCloneOfUncloneable() {
|
||||
final UncloneableString string = new UncloneableString("apache");
|
||||
try {
|
||||
ObjectUtils.cloneIfPossible(string);
|
||||
fail("Thrown " + CloneFailedException.class.getName() + " expected");
|
||||
} catch (final CloneFailedException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string));
|
||||
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -605,15 +596,18 @@ public class ObjectUtilsTest {
|
|||
// bytecode to see if the literals were folded into the
|
||||
// class, or if the bytecode kept the method call.
|
||||
|
||||
assertTrue("CONST(boolean)", ObjectUtils.CONST(true));
|
||||
assertEquals("CONST(byte)", (byte) 3, ObjectUtils.CONST((byte) 3));
|
||||
assertEquals("CONST(char)", (char) 3, ObjectUtils.CONST((char) 3));
|
||||
assertEquals("CONST(short)", (short) 3, ObjectUtils.CONST((short) 3));
|
||||
assertEquals("CONST(int)", 3, ObjectUtils.CONST(3));
|
||||
assertEquals("CONST(long)", 3L, ObjectUtils.CONST(3L));
|
||||
assertEquals("CONST(float)", 3f, ObjectUtils.CONST(3f), 0);
|
||||
assertEquals("CONST(double)", 3.0, ObjectUtils.CONST(3.0), 0);
|
||||
assertEquals("CONST(Object)", "abc", ObjectUtils.CONST("abc"));
|
||||
// TODO: JUnit Jupiter 5.3.1 doesn't support delta=0.
|
||||
// This should be replaced when it is supported in JUnit Jupiter 5.4.
|
||||
// See https://github.com/junit-team/junit5/pull/1613 for details.
|
||||
assertTrue(ObjectUtils.CONST(true), "CONST(boolean)");
|
||||
assertEquals((byte) 3, ObjectUtils.CONST((byte) 3), "CONST(byte)");
|
||||
assertEquals((char) 3, ObjectUtils.CONST((char) 3), "CONST(char)");
|
||||
assertEquals((short) 3, ObjectUtils.CONST((short) 3), "CONST(short)");
|
||||
assertEquals(3, ObjectUtils.CONST(3), "CONST(int)");
|
||||
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
|
||||
// (this fixed a lot of my bugs when I these!)
|
||||
|
@ -644,8 +638,8 @@ public class ObjectUtilsTest {
|
|||
assertEquals(123, MAGIC_INT);
|
||||
assertEquals(123, MAGIC_LONG1);
|
||||
assertEquals(3, MAGIC_LONG2);
|
||||
assertEquals(1.0f, MAGIC_FLOAT, 0.0f);
|
||||
assertEquals(1.0, MAGIC_DOUBLE, 0.0);
|
||||
assertTrue(1.0f == MAGIC_FLOAT);
|
||||
assertTrue(1.0 == MAGIC_DOUBLE);
|
||||
assertEquals("abc", MAGIC_STRING);
|
||||
|
||||
try {
|
||||
|
|
|
@ -16,23 +16,23 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
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.Modifier;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.RandomStringUtils}.
|
||||
|
@ -57,96 +57,96 @@ public class RandomStringUtilsTest {
|
|||
@Test
|
||||
public void testRandomStringUtils() {
|
||||
String r1 = RandomStringUtils.random(50);
|
||||
assertEquals("random(50) length", 50, r1.length());
|
||||
assertEquals(50, r1.length(), "random(50) length");
|
||||
String r2 = RandomStringUtils.random(50);
|
||||
assertEquals("random(50) length", 50, r2.length());
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertEquals(50, r2.length(), "random(50) length");
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
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++) {
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
r1 = RandomStringUtils.randomAlphabetic(50);
|
||||
assertEquals("randomAlphabetic(50)", 50, r1.length());
|
||||
assertEquals(50, r1.length(), "randomAlphabetic(50)");
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
r1 = RandomStringUtils.randomAlphanumeric(50);
|
||||
assertEquals("randomAlphanumeric(50)", 50, r1.length());
|
||||
assertEquals(50, r1.length(), "randomAlphanumeric(50)");
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
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++) {
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
r1 = RandomStringUtils.randomNumeric(50);
|
||||
assertEquals("randomNumeric(50)", 50, r1.length());
|
||||
assertEquals(50, r1.length(), "randomNumeric(50)");
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
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++) {
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
String set = "abcdefg";
|
||||
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++) {
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
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);
|
||||
assertEquals("random(50) length", 50, r2.length());
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertEquals(50, r2.length(), "random(50) length");
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
set = "stuvwxyz";
|
||||
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++) {
|
||||
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);
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
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);
|
||||
assertEquals("random(50) length", 50, r2.length());
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
assertEquals(50, r2.length(), "random(50) length");
|
||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
||||
|
||||
final long seed = System.currentTimeMillis();
|
||||
r1 = 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);
|
||||
assertEquals("random(0).equals(\"\")", "", r1);
|
||||
assertEquals("", r1, "random(0).equals(\"\")");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -162,8 +162,8 @@ public class RandomStringUtilsTest {
|
|||
fail("Expected IllegalArgumentException");
|
||||
} catch (final IllegalArgumentException ex) { // distinguish from Random#nextInt message
|
||||
final String msg = ex.getMessage();
|
||||
assertTrue("Message (" + msg + ") must contain 'start'", msg.contains("start"));
|
||||
assertTrue("Message (" + msg + ") must contain 'end'", msg.contains("end"));
|
||||
assertTrue(msg.contains("start"), "Message (" + msg + ") must contain 'start'");
|
||||
assertTrue(msg.contains("end"), "Message (" + msg + ") must contain 'end'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ public class RandomStringUtilsTest {
|
|||
for (int i = 0; i < 1000; i++) {
|
||||
final String s = RandomStringUtils.randomAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
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) {
|
||||
minCreatedLength = s.length();
|
||||
|
@ -349,7 +349,7 @@ public class RandomStringUtilsTest {
|
|||
for (int i = 0; i < 1000; i++) {
|
||||
final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
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) {
|
||||
minCreatedLength = s.length();
|
||||
|
@ -374,7 +374,7 @@ public class RandomStringUtilsTest {
|
|||
for (int i = 0; i < 1000; i++) {
|
||||
final String s = RandomStringUtils.randomAlphanumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
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) {
|
||||
minCreatedLength = s.length();
|
||||
|
@ -399,7 +399,7 @@ public class RandomStringUtilsTest {
|
|||
for (int i = 0; i < 1000; i++) {
|
||||
final String s = RandomStringUtils.randomGraph(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
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) {
|
||||
minCreatedLength = s.length();
|
||||
|
@ -424,7 +424,7 @@ public class RandomStringUtilsTest {
|
|||
for (int i = 0; i < 1000; i++) {
|
||||
final String s = RandomStringUtils.randomNumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
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) {
|
||||
minCreatedLength = s.length();
|
||||
|
@ -449,7 +449,7 @@ public class RandomStringUtilsTest {
|
|||
for (int i = 0; i < 1000; i++) {
|
||||
final String s = RandomStringUtils.randomPrint(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
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) {
|
||||
minCreatedLength = s.length();
|
||||
|
@ -488,8 +488,7 @@ public class RandomStringUtilsTest {
|
|||
}
|
||||
}
|
||||
// Perform chi-square test with df = 3-1 = 2, testing at .001 level
|
||||
assertTrue("test homogeneity -- will fail about 1 in 1000 times",
|
||||
chiSquare(expected,counts) < 13.82);
|
||||
assertTrue(chiSquare(expected,counts) < 13.82, "test homogeneity -- will fail about 1 in 1000 times");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -525,8 +524,9 @@ public class RandomStringUtilsTest {
|
|||
for (int i=0; i < orig.length() && i < copy.length(); i++) {
|
||||
final char o = orig.charAt(i);
|
||||
final char c = copy.charAt(i);
|
||||
assertEquals("differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," +
|
||||
Integer.toHexString(new Character(c).hashCode()) + ")", o, c);
|
||||
assertEquals(o, c,
|
||||
"differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," +
|
||||
Integer.toHexString(new Character(c).hashCode()) + ")");
|
||||
}
|
||||
// compare length also
|
||||
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 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;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
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.Modifier;
|
||||
|
@ -47,49 +48,49 @@ public class RandomUtilsTest {
|
|||
assertFalse(Modifier.isFinal(RandomUtils.class.getModifiers()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextBytesNegative() throws Exception {
|
||||
RandomUtils.nextBytes(-1);
|
||||
@Test
|
||||
public void testNextBytesNegative() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextBytes(-1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextIntNegative() throws Exception {
|
||||
RandomUtils.nextInt(-1, 1);
|
||||
@Test
|
||||
public void testNextIntNegative() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextInt(-1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextLongNegative() throws Exception {
|
||||
RandomUtils.nextLong(-1, 1);
|
||||
@Test
|
||||
public void testNextLongNegative() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextLong(-1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextDoubleNegative() throws Exception {
|
||||
RandomUtils.nextDouble(-1, 1);
|
||||
@Test
|
||||
public void testNextDoubleNegative() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextDouble(-1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextFloatNegative() throws Exception {
|
||||
RandomUtils.nextFloat(-1, 1);
|
||||
@Test
|
||||
public void testNextFloatNegative() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextFloat(-1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextIntLowerGreaterUpper() throws Exception {
|
||||
RandomUtils.nextInt(2, 1);
|
||||
@Test
|
||||
public void testNextIntLowerGreaterUpper() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextInt(2, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextLongLowerGreaterUpper() throws Exception {
|
||||
RandomUtils.nextLong(2, 1);
|
||||
@Test
|
||||
public void testNextLongLowerGreaterUpper() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextLong(2, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextDoubleLowerGreaterUpper() throws Exception {
|
||||
RandomUtils.nextDouble(2, 1);
|
||||
@Test
|
||||
public void testNextDoubleLowerGreaterUpper() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextDouble(2, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNextFloatLowerGreaterUpper() throws Exception {
|
||||
RandomUtils.nextFloat(2, 1);
|
||||
@Test
|
||||
public void testNextFloatLowerGreaterUpper() {
|
||||
assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextFloat(2, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,17 +17,18 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -47,7 +48,7 @@ public class RangeTest {
|
|||
private Range<Double> doubleRange;
|
||||
|
||||
@SuppressWarnings("cast") // intRange
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
byteRange = 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);
|
||||
assertFalse("should not contain null", ri.contains(null));
|
||||
assertTrue("should contain 10", ri.contains(10));
|
||||
assertFalse("should not contain 11", ri.contains(11));
|
||||
assertFalse(ri.contains(null), "should not contain null");
|
||||
assertTrue(ri.contains(10), "should contain 10");
|
||||
assertFalse(ri.contains(11), "should not contain 11");
|
||||
ri = Range.is(10, c);
|
||||
assertFalse("should not contain null", ri.contains(null));
|
||||
assertTrue("should contain 10", ri.contains(10));
|
||||
assertTrue("should contain 11", ri.contains(11));
|
||||
assertFalse(ri.contains(null), "should not contain null");
|
||||
assertTrue(ri.contains(10), "should contain 10");
|
||||
assertTrue(ri.contains(11), "should contain 11");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -108,29 +109,29 @@ public class RangeTest {
|
|||
}
|
||||
};
|
||||
Range<Integer> rb = Range.between(-10, 20);
|
||||
assertFalse("should not contain null", rb.contains(null));
|
||||
assertTrue("should contain 10", rb.contains(10));
|
||||
assertTrue("should contain -10", rb.contains(-10));
|
||||
assertFalse("should not contain 21", rb.contains(21));
|
||||
assertFalse("should not contain -11", rb.contains(-11));
|
||||
assertFalse(rb.contains(null), "should not contain null");
|
||||
assertTrue(rb.contains(10), "should contain 10");
|
||||
assertTrue(rb.contains(-10), "should contain -10");
|
||||
assertFalse(rb.contains(21), "should not contain 21");
|
||||
assertFalse(rb.contains(-11), "should not contain -11");
|
||||
rb = Range.between(-10, 20, c);
|
||||
assertFalse("should not contain null", rb.contains(null));
|
||||
assertTrue("should contain 10", rb.contains(10));
|
||||
assertTrue("should contain -10", rb.contains(-10));
|
||||
assertTrue("should contain 21", rb.contains(21));
|
||||
assertTrue("should contain -11", rb.contains(-11));
|
||||
assertFalse(rb.contains(null), "should not contain null");
|
||||
assertTrue(rb.contains(10), "should contain 10");
|
||||
assertTrue(rb.contains(-10), "should contain -10");
|
||||
assertTrue(rb.contains(21), "should contain 21");
|
||||
assertTrue(rb.contains(-11), "should contain -11");
|
||||
Range<String> rbstr = Range.between("house", "i");
|
||||
assertFalse("should not contain null", rbstr.contains(null));
|
||||
assertTrue("should contain house", rbstr.contains("house"));
|
||||
assertTrue("should contain i", rbstr.contains("i"));
|
||||
assertFalse("should not contain hose", rbstr.contains("hose"));
|
||||
assertFalse("should not contain ice", rbstr.contains("ice"));
|
||||
assertFalse(rbstr.contains(null), "should not contain null");
|
||||
assertTrue(rbstr.contains("house"), "should contain house");
|
||||
assertTrue(rbstr.contains("i"), "should contain i");
|
||||
assertFalse(rbstr.contains("hose"), "should not contain hose");
|
||||
assertFalse(rbstr.contains("ice"), "should not contain ice");
|
||||
rbstr = Range.between("house", "i", lengthComp);
|
||||
assertFalse("should not contain null", rbstr.contains(null));
|
||||
assertTrue("should contain house", rbstr.contains("house"));
|
||||
assertTrue("should contain i", rbstr.contains("i"));
|
||||
assertFalse("should not contain houses", rbstr.contains("houses"));
|
||||
assertFalse("should not contain ''", rbstr.contains(""));
|
||||
assertFalse(rbstr.contains(null), "should not contain null");
|
||||
assertTrue(rbstr.contains("house"), "should contain house");
|
||||
assertTrue(rbstr.contains("i"), "should contain i");
|
||||
assertFalse(rbstr.contains("houses"), "should not contain houses");
|
||||
assertFalse(rbstr.contains(""), "should not contain ''");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
@ -375,14 +376,14 @@ public class RangeTest {
|
|||
assertEquals(Range.between(10, 15), intRange.intersectionWith(Range.between(5, 15)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIntersectionWithNull() {
|
||||
intRange.intersectionWith(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> intRange.intersectionWith(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
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.
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -37,8 +38,8 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.SerializationUtils}.
|
||||
|
@ -52,7 +53,7 @@ public class SerializationUtilsTest {
|
|||
private Integer iInteger;
|
||||
private HashMap<Object, Object> iMap;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
iString = "foo";
|
||||
iInteger = Integer.valueOf(7);
|
||||
|
@ -114,11 +115,11 @@ public class SerializationUtilsTest {
|
|||
assertArrayEquals(realBytes, testBytes);
|
||||
}
|
||||
|
||||
@Test(expected = SerializationException.class)
|
||||
public void testSerializeStreamUnserializable() throws Exception {
|
||||
@Test
|
||||
public void testSerializeStreamUnserializable() {
|
||||
final ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
iMap.put(new Object(), new Object());
|
||||
SerializationUtils.serialize(iMap, streamTest);
|
||||
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap, streamTest));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -138,14 +139,14 @@ public class SerializationUtilsTest {
|
|||
assertArrayEquals(realBytes, testBytes);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSerializeStreamObjNull() throws Exception {
|
||||
SerializationUtils.serialize(iMap, null);
|
||||
@Test
|
||||
public void testSerializeStreamObjNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.serialize(iMap, null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSerializeStreamNullNull() throws Exception {
|
||||
SerializationUtils.serialize(null, null);
|
||||
@Test
|
||||
public void testSerializeStreamNullNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.serialize(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -188,14 +189,16 @@ public class SerializationUtilsTest {
|
|||
assertEquals(iMap, testMap);
|
||||
}
|
||||
|
||||
@Test(expected=ClassCastException.class)
|
||||
@Test
|
||||
public void testDeserializeClassCastException() {
|
||||
final String value = "Hello";
|
||||
final byte[] serialized = SerializationUtils.serialize(value);
|
||||
assertEquals(value, SerializationUtils.deserialize(serialized));
|
||||
assertThrows(ClassCastException.class, () -> {
|
||||
// Causes ClassCastException in call site, not in SerializationUtils.deserialize
|
||||
@SuppressWarnings("unused") // needed to cause Exception
|
||||
final Integer i = SerializationUtils.deserialize(serialized);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -211,14 +214,15 @@ public class SerializationUtilsTest {
|
|||
assertNull(test);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeserializeStreamNull() throws Exception {
|
||||
SerializationUtils.deserialize((InputStream) null);
|
||||
@Test
|
||||
public void testDeserializeStreamNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.deserialize((InputStream) null));
|
||||
}
|
||||
|
||||
@Test(expected = SerializationException.class)
|
||||
public void testDeserializeStreamBadStream() throws Exception {
|
||||
SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0]));
|
||||
@Test
|
||||
public void testDeserializeStreamBadStream() {
|
||||
assertThrows(SerializationException.class,
|
||||
() -> SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0])));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -262,10 +266,10 @@ public class SerializationUtilsTest {
|
|||
assertArrayEquals(realBytes, testBytes);
|
||||
}
|
||||
|
||||
@Test(expected = SerializationException.class)
|
||||
public void testSerializeBytesUnserializable() throws Exception {
|
||||
@Test
|
||||
public void testSerializeBytesUnserializable() {
|
||||
iMap.put(new Object(), new Object());
|
||||
SerializationUtils.serialize(iMap);
|
||||
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -317,14 +321,14 @@ public class SerializationUtilsTest {
|
|||
assertNull(test);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeserializeBytesNull() throws Exception {
|
||||
SerializationUtils.deserialize((byte[]) null);
|
||||
@Test
|
||||
public void testDeserializeBytesNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> SerializationUtils.deserialize((byte[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = SerializationException.class)
|
||||
public void testDeserializeBytesBadStream() throws Exception {
|
||||
SerializationUtils.deserialize(new byte[0]);
|
||||
@Test
|
||||
public void testDeserializeBytesBadStream() {
|
||||
assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(new byte[0]));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -349,10 +353,10 @@ public class SerializationUtilsTest {
|
|||
assertNull(test);
|
||||
}
|
||||
|
||||
@Test(expected = SerializationException.class)
|
||||
public void testCloneUnserializable() throws Exception {
|
||||
@Test
|
||||
public void testCloneUnserializable() {
|
||||
iMap.put(new Object(), new Object());
|
||||
SerializationUtils.clone(iMap);
|
||||
assertThrows(SerializationException.class, () -> SerializationUtils.clone(iMap));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
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.NumericEntityEscaper;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
final String converted = StringEscapeUtils.escapeJava(original);
|
||||
message = "escapeJava(String) failed" + (message == null ? "" : (": " + message));
|
||||
assertEquals(message, expected, converted);
|
||||
assertEquals(expected, converted, message);
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
StringEscapeUtils.ESCAPE_JAVA.translate(original, writer);
|
||||
|
@ -165,12 +166,12 @@ public class StringEscapeUtilsTest {
|
|||
final String expected = unescaped;
|
||||
final String actual = StringEscapeUtils.unescapeJava(original);
|
||||
|
||||
assertEquals("unescape(String) failed" +
|
||||
assertEquals(expected, actual,
|
||||
"unescape(String) failed" +
|
||||
(message == null ? "" : (": " + message)) +
|
||||
": expected '" + StringEscapeUtils.escapeJava(expected) +
|
||||
// we escape this so we can see it in the error message
|
||||
"' actual '" + StringEscapeUtils.escapeJava(actual) + "'",
|
||||
expected, actual);
|
||||
"' actual '" + StringEscapeUtils.escapeJava(actual) + "'");
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
StringEscapeUtils.UNESCAPE_JAVA.translate(original, writer);
|
||||
|
@ -248,14 +249,14 @@ public class StringEscapeUtilsTest {
|
|||
final String message = element[0];
|
||||
final String expected = element[1];
|
||||
final String original = element[2];
|
||||
assertEquals(message, expected, StringEscapeUtils.escapeHtml4(original));
|
||||
assertEquals(expected, StringEscapeUtils.escapeHtml4(original), message);
|
||||
final StringWriter sw = new StringWriter();
|
||||
try {
|
||||
StringEscapeUtils.ESCAPE_HTML4.translate(original, sw);
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
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 expected = element[2];
|
||||
final String original = element[1];
|
||||
assertEquals(message, expected, StringEscapeUtils.unescapeHtml4(original));
|
||||
assertEquals(expected, StringEscapeUtils.unescapeHtml4(original), message);
|
||||
|
||||
final StringWriter sw = new StringWriter();
|
||||
try {
|
||||
|
@ -273,12 +274,12 @@ public class StringEscapeUtilsTest {
|
|||
} catch (final IOException e) {
|
||||
}
|
||||
final String actual = original == null ? null : sw.toString();
|
||||
assertEquals(message, expected, actual);
|
||||
assertEquals(expected, actual, message);
|
||||
}
|
||||
// \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
|
||||
// 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"));
|
||||
|
@ -289,8 +290,8 @@ public class StringEscapeUtilsTest {
|
|||
@Test
|
||||
public void testUnescapeHexCharsHtml() {
|
||||
// Simple easy to grok test
|
||||
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
|
||||
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
|
||||
assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape");
|
||||
assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape");
|
||||
// Test all Character values:
|
||||
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
|
||||
final Character c1 = new Character(i);
|
||||
|
@ -298,7 +299,7 @@ public class StringEscapeUtilsTest {
|
|||
final String expected = c1.toString() + c2.toString();
|
||||
final String escapedC1 = "&#x" + Integer.toHexString((c1.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.unescapeXml("<abc>"));
|
||||
|
||||
assertEquals("XML should not escape >0x7f values",
|
||||
"\u00A1", StringEscapeUtils.escapeXml("\u00A1"));
|
||||
assertEquals("XML should be able to unescape >0x7f values",
|
||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
||||
assertEquals("XML should be able to unescape >0x7f values with one leading 0",
|
||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
||||
assertEquals("XML should be able to unescape >0x7f values with two leading 0s",
|
||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
||||
assertEquals("XML should be able to unescape >0x7f values with three leading 0s",
|
||||
"\u00A0", StringEscapeUtils.unescapeXml(" "));
|
||||
assertEquals("\u00A1", StringEscapeUtils.escapeXml("\u00A1"), "XML should not escape >0x7f values");
|
||||
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "), "XML should be able to unescape >0x7f values");
|
||||
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "),
|
||||
"XML should be able to unescape >0x7f values with one leading 0");
|
||||
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "),
|
||||
"XML should be able to unescape >0x7f values with two leading 0s");
|
||||
assertEquals("\u00A0", StringEscapeUtils.unescapeXml(" "),
|
||||
"XML should be able to unescape >0x7f values with three leading 0s");
|
||||
|
||||
assertEquals("ain't", StringEscapeUtils.unescapeXml("ain't"));
|
||||
assertEquals("ain't", StringEscapeUtils.escapeXml("ain't"));
|
||||
|
@ -342,46 +341,46 @@ public class StringEscapeUtilsTest {
|
|||
StringEscapeUtils.ESCAPE_XML.translate("<abc>", sw);
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
assertEquals("XML was escaped incorrectly", "<abc>", sw.toString() );
|
||||
assertEquals("<abc>", sw.toString(), "XML was escaped incorrectly");
|
||||
|
||||
sw = new StringWriter();
|
||||
try {
|
||||
StringEscapeUtils.UNESCAPE_XML.translate("<abc>", sw);
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
assertEquals("XML was unescaped incorrectly", "<abc>", sw.toString() );
|
||||
assertEquals("<abc>", sw.toString(), "XML was unescaped incorrectly");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapeXml10() throws Exception {
|
||||
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",
|
||||
"a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd"));
|
||||
assertEquals("XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19",
|
||||
"ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb"));
|
||||
assertEquals("XML 1.0 should omit #xd800-#xdfff",
|
||||
"a\ud7ff \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b"));
|
||||
assertEquals("XML 1.0 should omit #xfffe | #xffff",
|
||||
"a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb"));
|
||||
assertEquals("XML 1.0 should escape #x7f-#x84 | #x86 - #x9f, for XML 1.1 compatibility",
|
||||
"a\u007e„\u0085†Ÿ\u00a0b", StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"));
|
||||
assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd"), "XML 1.0 should not escape \t \n \r");
|
||||
assertEquals("ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb"),
|
||||
"XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19");
|
||||
assertEquals("a\ud7ff \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b"),
|
||||
"XML 1.0 should omit #xd800-#xdfff");
|
||||
assertEquals("a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb"),
|
||||
"XML 1.0 should omit #xfffe | #xffff");
|
||||
assertEquals("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
|
||||
public void testEscapeXml11() throws Exception {
|
||||
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",
|
||||
"a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"));
|
||||
assertEquals("XML 1.1 should omit #x0",
|
||||
"ab", StringEscapeUtils.escapeXml11("a\u0000b"));
|
||||
assertEquals("XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19",
|
||||
"ab", StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"));
|
||||
assertEquals("XML 1.1 should escape #x7F-#x84 | #x86-#x9F",
|
||||
"a\u007e„\u0085†Ÿ\u00a0b", StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"));
|
||||
assertEquals("XML 1.1 should omit #xd800-#xdfff",
|
||||
"a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"));
|
||||
assertEquals("XML 1.1 should omit #xfffe | #xffff",
|
||||
"a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb"));
|
||||
assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"), "XML 1.1 should not escape \t \n \r");
|
||||
assertEquals("ab", StringEscapeUtils.escapeXml11("a\u0000b"), "XML 1.1 should omit #x0");
|
||||
assertEquals("ab",
|
||||
StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"),
|
||||
"XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19");
|
||||
assertEquals("a\u007e„\u0085†Ÿ\u00a0b",
|
||||
StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"),
|
||||
"XML 1.1 should escape #x7F-#x84 | #x86-#x9F");
|
||||
assertEquals("a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"),
|
||||
"XML 1.1 should omit #xd800-#xdfff");
|
||||
assertEquals("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 =
|
||||
StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );
|
||||
|
||||
assertEquals("Supplementary character must be represented using a single escape", "𣎴",
|
||||
escapeXml.translate("\uD84C\uDFB4"));
|
||||
assertEquals("𣎴", 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 𣎴",
|
||||
escapeXml.translate("a b c \uD84C\uDFB4"));
|
||||
assertEquals("a b c 𣎴", escapeXml.translate("a b c \uD84C\uDFB4"),
|
||||
"Supplementary characters mixed with basic characters should be encoded correctly");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -436,11 +435,11 @@ public class StringEscapeUtilsTest {
|
|||
*/
|
||||
@Test
|
||||
public void testUnescapeXmlSupplementaryCharacters() {
|
||||
assertEquals("Supplementary character must be represented using a single escape", "\uD84C\uDFB4",
|
||||
StringEscapeUtils.unescapeXml("𣎴") );
|
||||
assertEquals("\uD84C\uDFB4", 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",
|
||||
StringEscapeUtils.unescapeXml("a b c 𣎴") );
|
||||
assertEquals("a b c \uD84C\uDFB4", StringEscapeUtils.unescapeXml("a b c 𣎴"),
|
||||
"Supplementary characters mixed with basic characters should be decoded correctly");
|
||||
}
|
||||
|
||||
// Tests issue #38569
|
||||
|
@ -492,10 +491,10 @@ public class StringEscapeUtilsTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testEscapeCsvIllegalStateException() throws IOException {
|
||||
@Test
|
||||
public void testEscapeCsvIllegalStateException() {
|
||||
final StringWriter writer = new StringWriter();
|
||||
StringEscapeUtils.ESCAPE_CSV.translate("foo", -1, writer);
|
||||
assertThrows(IllegalStateException.class, () -> StringEscapeUtils.ESCAPE_CSV.translate("foo", -1, writer));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -536,10 +535,10 @@ public class StringEscapeUtilsTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testUnescapeCsvIllegalStateException() throws IOException {
|
||||
@Test
|
||||
public void testUnescapeCsvIllegalStateException() {
|
||||
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 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 );
|
||||
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
|
||||
// String unescapedFromEntity = StringEscapeUtils.unescapeHtml4( "𝍢" );
|
||||
|
@ -574,12 +573,12 @@ public class StringEscapeUtilsTest {
|
|||
// Some random Japanese Unicode characters
|
||||
final String original = "\u304B\u304C\u3068";
|
||||
final String escaped = StringEscapeUtils.escapeHtml4(original);
|
||||
assertEquals( "Hiragana character Unicode behaviour should not be being escaped by escapeHtml4",
|
||||
original, escaped);
|
||||
assertEquals(original, escaped,
|
||||
"Hiragana character Unicode behaviour should not be being escaped by escapeHtml4");
|
||||
|
||||
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 escaped = StringEscapeUtils.escapeEcmaScript(input);
|
||||
// just the end:
|
||||
assertTrue(escaped, escaped.endsWith("}]"));
|
||||
assertTrue(escaped.endsWith("}]"), escaped);
|
||||
// a little more:
|
||||
assertTrue(escaped, escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"));
|
||||
assertTrue(escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"), escaped);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,25 +16,19 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
||||
import org.apache.commons.lang3.test.SystemDefaults;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junitpioneer.jupiter.DefaultLocale;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Contains methods
|
||||
*/
|
||||
public class StringUtilsContainsTest {
|
||||
|
||||
@Rule
|
||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
||||
|
||||
/**
|
||||
* Supplementary character U+20000
|
||||
* See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html
|
||||
|
@ -233,7 +227,7 @@ public class StringUtilsContainsTest {
|
|||
assertTrue(StringUtils.containsAny("abc", "d", "abc"));
|
||||
}
|
||||
|
||||
@SystemDefaults(locale="de_DE")
|
||||
@DefaultLocale(language = "de", country = "DE")
|
||||
@Test
|
||||
public void testContainsIgnoreCase_LocaleIndependence() {
|
||||
final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
|
||||
|
@ -253,12 +247,12 @@ public class StringUtilsContainsTest {
|
|||
for (final Locale testLocale : locales) {
|
||||
Locale.setDefault(testLocale);
|
||||
for (int j = 0; j < tdata.length; j++) {
|
||||
assertTrue(Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1], StringUtils
|
||||
.containsIgnoreCase(tdata[j][0], tdata[j][1]));
|
||||
assertTrue(StringUtils.containsIgnoreCase(tdata[j][0], tdata[j][1]),
|
||||
Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1]);
|
||||
}
|
||||
for (int j = 0; j < fdata.length; j++) {
|
||||
assertFalse(Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1], StringUtils
|
||||
.containsIgnoreCase(fdata[j][0], fdata[j][1]));
|
||||
assertFalse(StringUtils.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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
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
|
||||
|
|
|
@ -16,26 +16,20 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
||||
import org.hamcrest.core.IsNot;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.StringUtils} - Equals/IndexOf methods
|
||||
*/
|
||||
public class StringUtilsEqualsIndexOfTest {
|
||||
|
||||
@Rule
|
||||
public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
|
||||
|
||||
private static final String BAR = "bar";
|
||||
/**
|
||||
* Supplementary character U+20000
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
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
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
*/
|
||||
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.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -40,23 +40,23 @@ public class StringUtilsStartsEndsWithTest {
|
|||
*/
|
||||
@Test
|
||||
public void testStartsWith() {
|
||||
assertTrue("startsWith(null, null)", StringUtils.startsWith(null, null));
|
||||
assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, null));
|
||||
assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null, FOO));
|
||||
assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR, ""));
|
||||
assertTrue(StringUtils.startsWith(null, null), "startsWith(null, null)");
|
||||
assertFalse(StringUtils.startsWith(FOOBAR, null), "startsWith(FOOBAR, null)");
|
||||
assertFalse(StringUtils.startsWith(null, FOO), "startsWith(null, FOO)");
|
||||
assertTrue(StringUtils.startsWith(FOOBAR, ""), "startsWith(FOOBAR, \"\")");
|
||||
|
||||
assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar, foo));
|
||||
assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR, FOO));
|
||||
assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar, FOO));
|
||||
assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR, foo));
|
||||
assertTrue(StringUtils.startsWith(foobar, foo), "startsWith(foobar, foo)");
|
||||
assertTrue(StringUtils.startsWith(FOOBAR, FOO), "startsWith(FOOBAR, FOO)");
|
||||
assertFalse(StringUtils.startsWith(foobar, FOO), "startsWith(foobar, FOO)");
|
||||
assertFalse(StringUtils.startsWith(FOOBAR, foo), "startsWith(FOOBAR, foo)");
|
||||
|
||||
assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo, foobar));
|
||||
assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar, foobar));
|
||||
assertFalse(StringUtils.startsWith(foo, foobar), "startsWith(foo, foobar)");
|
||||
assertFalse(StringUtils.startsWith(bar, foobar), "startsWith(foo, foobar)");
|
||||
|
||||
assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar, bar));
|
||||
assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR, BAR));
|
||||
assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar, BAR));
|
||||
assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR, bar));
|
||||
assertFalse(StringUtils.startsWith(foobar, bar), "startsWith(foobar, bar)");
|
||||
assertFalse(StringUtils.startsWith(FOOBAR, BAR), "startsWith(FOOBAR, BAR)");
|
||||
assertFalse(StringUtils.startsWith(foobar, BAR), "startsWith(foobar, BAR)");
|
||||
assertFalse(StringUtils.startsWith(FOOBAR, bar), "startsWith(FOOBAR, bar)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,23 +64,23 @@ public class StringUtilsStartsEndsWithTest {
|
|||
*/
|
||||
@Test
|
||||
public void testStartsWithIgnoreCase() {
|
||||
assertTrue("startsWithIgnoreCase(null, null)", StringUtils.startsWithIgnoreCase(null, null));
|
||||
assertFalse("startsWithIgnoreCase(FOOBAR, null)", StringUtils.startsWithIgnoreCase(FOOBAR, null));
|
||||
assertFalse("startsWithIgnoreCase(null, FOO)", StringUtils.startsWithIgnoreCase(null, FOO));
|
||||
assertTrue("startsWithIgnoreCase(FOOBAR, \"\")", StringUtils.startsWithIgnoreCase(FOOBAR, ""));
|
||||
assertTrue(StringUtils.startsWithIgnoreCase(null, null), "startsWithIgnoreCase(null, null)");
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(FOOBAR, null), "startsWithIgnoreCase(FOOBAR, null)");
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(null, FOO), "startsWithIgnoreCase(null, FOO)");
|
||||
assertTrue(StringUtils.startsWithIgnoreCase(FOOBAR, ""), "startsWithIgnoreCase(FOOBAR, \"\")");
|
||||
|
||||
assertTrue("startsWithIgnoreCase(foobar, foo)", StringUtils.startsWithIgnoreCase(foobar, foo));
|
||||
assertTrue("startsWithIgnoreCase(FOOBAR, FOO)", StringUtils.startsWithIgnoreCase(FOOBAR, FOO));
|
||||
assertTrue("startsWithIgnoreCase(foobar, FOO)", StringUtils.startsWithIgnoreCase(foobar, FOO));
|
||||
assertTrue("startsWithIgnoreCase(FOOBAR, foo)", StringUtils.startsWithIgnoreCase(FOOBAR, foo));
|
||||
assertTrue(StringUtils.startsWithIgnoreCase(foobar, foo), "startsWithIgnoreCase(foobar, foo)");
|
||||
assertTrue(StringUtils.startsWithIgnoreCase(FOOBAR, FOO), "startsWithIgnoreCase(FOOBAR, FOO)");
|
||||
assertTrue(StringUtils.startsWithIgnoreCase(foobar, FOO), "startsWithIgnoreCase(foobar, FOO)");
|
||||
assertTrue(StringUtils.startsWithIgnoreCase(FOOBAR, foo), "startsWithIgnoreCase(FOOBAR, foo)");
|
||||
|
||||
assertFalse("startsWithIgnoreCase(foo, foobar)", StringUtils.startsWithIgnoreCase(foo, foobar));
|
||||
assertFalse("startsWithIgnoreCase(foo, foobar)", StringUtils.startsWithIgnoreCase(bar, foobar));
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(foo, foobar), "startsWithIgnoreCase(foo, foobar)");
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(bar, foobar), "startsWithIgnoreCase(foo, foobar)");
|
||||
|
||||
assertFalse("startsWithIgnoreCase(foobar, bar)", StringUtils.startsWithIgnoreCase(foobar, bar));
|
||||
assertFalse("startsWithIgnoreCase(FOOBAR, BAR)", StringUtils.startsWithIgnoreCase(FOOBAR, BAR));
|
||||
assertFalse("startsWithIgnoreCase(foobar, BAR)", StringUtils.startsWithIgnoreCase(foobar, BAR));
|
||||
assertFalse("startsWithIgnoreCase(FOOBAR, bar)", StringUtils.startsWithIgnoreCase(FOOBAR, bar));
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(foobar, bar), "startsWithIgnoreCase(foobar, bar)");
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(FOOBAR, BAR), "startsWithIgnoreCase(FOOBAR, BAR)");
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(foobar, BAR), "startsWithIgnoreCase(foobar, BAR)");
|
||||
assertFalse(StringUtils.startsWithIgnoreCase(FOOBAR, bar), "startsWithIgnoreCase(FOOBAR, bar)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,8 +96,8 @@ public class StringUtilsStartsEndsWithTest {
|
|||
assertFalse(StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX"));
|
||||
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(StringBuffer(abcxyz), StringBuilder(xyz), StringBuffer(abc))", StringUtils.startsWithAny(new StringBuffer("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(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
|
||||
public void testEndsWith() {
|
||||
assertTrue("endsWith(null, null)", StringUtils.endsWith(null, null));
|
||||
assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR, null));
|
||||
assertFalse("endsWith(null, FOO)", StringUtils.endsWith(null, FOO));
|
||||
assertTrue("endsWith(FOOBAR, \"\")", StringUtils.endsWith(FOOBAR, ""));
|
||||
assertTrue(StringUtils.endsWith(null, null), "endsWith(null, null)");
|
||||
assertFalse(StringUtils.endsWith(FOOBAR, null), "endsWith(FOOBAR, null)");
|
||||
assertFalse(StringUtils.endsWith(null, FOO), "endsWith(null, FOO)");
|
||||
assertTrue(StringUtils.endsWith(FOOBAR, ""), "endsWith(FOOBAR, \"\")");
|
||||
|
||||
assertFalse("endsWith(foobar, foo)", StringUtils.endsWith(foobar, foo));
|
||||
assertFalse("endsWith(FOOBAR, FOO)", StringUtils.endsWith(FOOBAR, FOO));
|
||||
assertFalse("endsWith(foobar, FOO)", StringUtils.endsWith(foobar, FOO));
|
||||
assertFalse("endsWith(FOOBAR, foo)", StringUtils.endsWith(FOOBAR, foo));
|
||||
assertFalse(StringUtils.endsWith(foobar, foo), "endsWith(foobar, foo)");
|
||||
assertFalse(StringUtils.endsWith(FOOBAR, FOO), "endsWith(FOOBAR, FOO)");
|
||||
assertFalse(StringUtils.endsWith(foobar, FOO), "endsWith(foobar, FOO)");
|
||||
assertFalse(StringUtils.endsWith(FOOBAR, foo), "endsWith(FOOBAR, foo)");
|
||||
|
||||
assertFalse("endsWith(foo, foobar)", StringUtils.endsWith(foo, foobar));
|
||||
assertFalse("endsWith(foo, foobar)", StringUtils.endsWith(bar, foobar));
|
||||
assertFalse(StringUtils.endsWith(foo, foobar), "endsWith(foo, foobar)");
|
||||
assertFalse(StringUtils.endsWith(bar, foobar), "endsWith(foo, foobar)");
|
||||
|
||||
assertTrue("endsWith(foobar, bar)", StringUtils.endsWith(foobar, bar));
|
||||
assertTrue("endsWith(FOOBAR, BAR)", StringUtils.endsWith(FOOBAR, BAR));
|
||||
assertFalse("endsWith(foobar, BAR)", StringUtils.endsWith(foobar, BAR));
|
||||
assertFalse("endsWith(FOOBAR, bar)", StringUtils.endsWith(FOOBAR, bar));
|
||||
assertTrue(StringUtils.endsWith(foobar, bar), "endsWith(foobar, bar)");
|
||||
assertTrue(StringUtils.endsWith(FOOBAR, BAR), "endsWith(FOOBAR, BAR)");
|
||||
assertFalse(StringUtils.endsWith(foobar, BAR), "endsWith(foobar, BAR)");
|
||||
assertFalse(StringUtils.endsWith(FOOBAR, bar), "endsWith(FOOBAR, bar)");
|
||||
|
||||
// "alpha,beta,gamma,delta".endsWith("delta")
|
||||
assertTrue("endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B4)",
|
||||
StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B4"));
|
||||
assertTrue(StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B4"),
|
||||
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B4)");
|
||||
// "alpha,beta,gamma,delta".endsWith("gamma,DELTA")
|
||||
assertFalse("endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B3\u0394)",
|
||||
StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B3\u0394"));
|
||||
assertFalse(StringUtils.endsWith("\u03B1\u03B2\u03B3\u03B4", "\u03B3\u0394"),
|
||||
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u03B3\u0394)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,23 +137,23 @@ public class StringUtilsStartsEndsWithTest {
|
|||
*/
|
||||
@Test
|
||||
public void testEndsWithIgnoreCase() {
|
||||
assertTrue("endsWithIgnoreCase(null, null)", StringUtils.endsWithIgnoreCase(null, null));
|
||||
assertFalse("endsWithIgnoreCase(FOOBAR, null)", StringUtils.endsWithIgnoreCase(FOOBAR, null));
|
||||
assertFalse("endsWithIgnoreCase(null, FOO)", StringUtils.endsWithIgnoreCase(null, FOO));
|
||||
assertTrue("endsWithIgnoreCase(FOOBAR, \"\")", StringUtils.endsWithIgnoreCase(FOOBAR, ""));
|
||||
assertTrue(StringUtils.endsWithIgnoreCase(null, null), "endsWithIgnoreCase(null, null)");
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(FOOBAR, null), "endsWithIgnoreCase(FOOBAR, null)");
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(null, FOO), "endsWithIgnoreCase(null, FOO)");
|
||||
assertTrue(StringUtils.endsWithIgnoreCase(FOOBAR, ""), "endsWithIgnoreCase(FOOBAR, \"\")");
|
||||
|
||||
assertFalse("endsWithIgnoreCase(foobar, foo)", StringUtils.endsWithIgnoreCase(foobar, foo));
|
||||
assertFalse("endsWithIgnoreCase(FOOBAR, FOO)", StringUtils.endsWithIgnoreCase(FOOBAR, FOO));
|
||||
assertFalse("endsWithIgnoreCase(foobar, FOO)", StringUtils.endsWithIgnoreCase(foobar, FOO));
|
||||
assertFalse("endsWithIgnoreCase(FOOBAR, foo)", StringUtils.endsWithIgnoreCase(FOOBAR, foo));
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(foobar, foo), "endsWithIgnoreCase(foobar, foo)");
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(FOOBAR, FOO), "endsWithIgnoreCase(FOOBAR, FOO)");
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(foobar, FOO), "endsWithIgnoreCase(foobar, FOO)");
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(FOOBAR, foo), "endsWithIgnoreCase(FOOBAR, foo)");
|
||||
|
||||
assertFalse("endsWithIgnoreCase(foo, foobar)", StringUtils.endsWithIgnoreCase(foo, foobar));
|
||||
assertFalse("endsWithIgnoreCase(foo, foobar)", StringUtils.endsWithIgnoreCase(bar, foobar));
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(foo, foobar), "endsWithIgnoreCase(foo, foobar)");
|
||||
assertFalse(StringUtils.endsWithIgnoreCase(bar, foobar), "endsWithIgnoreCase(foo, foobar)");
|
||||
|
||||
assertTrue("endsWithIgnoreCase(foobar, bar)", StringUtils.endsWithIgnoreCase(foobar, bar));
|
||||
assertTrue("endsWithIgnoreCase(FOOBAR, BAR)", StringUtils.endsWithIgnoreCase(FOOBAR, BAR));
|
||||
assertTrue("endsWithIgnoreCase(foobar, BAR)", StringUtils.endsWithIgnoreCase(foobar, BAR));
|
||||
assertTrue("endsWithIgnoreCase(FOOBAR, bar)", StringUtils.endsWithIgnoreCase(FOOBAR, bar));
|
||||
assertTrue(StringUtils.endsWithIgnoreCase(foobar, bar), "endsWithIgnoreCase(foobar, bar)");
|
||||
assertTrue(StringUtils.endsWithIgnoreCase(FOOBAR, BAR), "endsWithIgnoreCase(FOOBAR, BAR)");
|
||||
assertTrue(StringUtils.endsWithIgnoreCase(foobar, BAR), "endsWithIgnoreCase(foobar, BAR)");
|
||||
assertTrue(StringUtils.endsWithIgnoreCase(FOOBAR, bar), "endsWithIgnoreCase(FOOBAR, bar)");
|
||||
|
||||
// javadoc
|
||||
assertTrue(StringUtils.endsWithIgnoreCase("abcdef", "def"));
|
||||
|
@ -161,22 +161,22 @@ public class StringUtilsStartsEndsWithTest {
|
|||
assertFalse(StringUtils.endsWithIgnoreCase("ABCDEF", "cde"));
|
||||
|
||||
// "alpha,beta,gamma,delta".endsWith("DELTA")
|
||||
assertTrue("endsWith(\u03B1\u03B2\u03B3\u03B4, \u0394)",
|
||||
StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0394"));
|
||||
assertTrue(StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0394"),
|
||||
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u0394)");
|
||||
// "alpha,beta,gamma,delta".endsWith("GAMMA")
|
||||
assertFalse("endsWith(\u03B1\u03B2\u03B3\u03B4, \u0393)",
|
||||
StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0393"));
|
||||
assertFalse(StringUtils.endsWithIgnoreCase("\u03B1\u03B2\u03B3\u03B4", "\u0393"),
|
||||
"endsWith(\u03B1\u03B2\u03B3\u03B4, \u0393)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndsWithAny() {
|
||||
assertFalse("StringUtils.endsWithAny(null, null)", StringUtils.endsWithAny(null, (String)null));
|
||||
assertFalse("StringUtils.endsWithAny(null, new String[] {abc})", StringUtils.endsWithAny(null, new String[] {"abc"}));
|
||||
assertFalse("StringUtils.endsWithAny(abcxyz, null)", StringUtils.endsWithAny("abcxyz", (String)null));
|
||||
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[] {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(null, (String)null), "StringUtils.endsWithAny(null, null)");
|
||||
assertFalse(StringUtils.endsWithAny(null, new String[] {"abc"}), "StringUtils.endsWithAny(null, new String[] {abc})");
|
||||
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[] {"xyz"}), "StringUtils.endsWithAny(abcxyz, new String[] {xyz})");
|
||||
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})");
|
||||
assertTrue(StringUtils.endsWithAny("abcXYZ", "def", "XYZ"));
|
||||
assertFalse(StringUtils.endsWithAny("abcXYZ", "def", "xyz"));
|
||||
assertTrue(StringUtils.endsWithAny("abcXYZ", "def", "YZ"));
|
||||
|
@ -193,8 +193,8 @@ public class StringUtilsStartsEndsWithTest {
|
|||
assertFalse(StringUtils.endsWithAny("abcXYZ", (CharSequence[]) null));
|
||||
assertTrue(StringUtils.endsWithAny("abcXYZ", ""));
|
||||
|
||||
assertTrue("StringUtils.endsWithAny(abcxyz, StringBuilder(abc), StringBuffer(xyz))", StringUtils.endsWithAny("abcxyz", new StringBuilder("abc"), new 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("abcxyz", new StringBuilder("abc"), new StringBuffer("xyz")), "StringUtils.endsWithAny(abcxyz, StringBuilder(abc), 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
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
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
@ -40,7 +41,7 @@ import java.util.Objects;
|
|||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
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}
|
||||
|
@ -135,45 +136,35 @@ public class StringUtilsTest {
|
|||
public void testUpperCase() {
|
||||
assertNull(StringUtils.upperCase(null));
|
||||
assertNull(StringUtils.upperCase(null, Locale.ENGLISH));
|
||||
assertEquals("upperCase(String) failed",
|
||||
"FOO TEST THING", StringUtils.upperCase("fOo test THING"));
|
||||
assertEquals("upperCase(empty-string) failed",
|
||||
"", StringUtils.upperCase(""));
|
||||
assertEquals("upperCase(String, Locale) failed",
|
||||
"FOO TEST THING", StringUtils.upperCase("fOo test THING", Locale.ENGLISH));
|
||||
assertEquals("upperCase(empty-string, Locale) failed",
|
||||
"", StringUtils.upperCase("", Locale.ENGLISH));
|
||||
assertEquals("FOO TEST THING", StringUtils.upperCase("fOo test THING"), "upperCase(String) failed");
|
||||
assertEquals("", StringUtils.upperCase(""), "upperCase(empty-string) failed");
|
||||
assertEquals("FOO TEST THING", StringUtils.upperCase("fOo test THING", Locale.ENGLISH),
|
||||
"upperCase(String, Locale) failed");
|
||||
assertEquals("", StringUtils.upperCase("", Locale.ENGLISH),
|
||||
"upperCase(empty-string, Locale) failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerCase() {
|
||||
assertNull(StringUtils.lowerCase(null));
|
||||
assertNull(StringUtils.lowerCase(null, Locale.ENGLISH));
|
||||
assertEquals("lowerCase(String) failed",
|
||||
"foo test thing", StringUtils.lowerCase("fOo test THING"));
|
||||
assertEquals("lowerCase(empty-string) failed",
|
||||
"", StringUtils.lowerCase(""));
|
||||
assertEquals("lowerCase(String, Locale) failed",
|
||||
"foo test thing", StringUtils.lowerCase("fOo test THING", Locale.ENGLISH));
|
||||
assertEquals("lowerCase(empty-string, Locale) failed",
|
||||
"", StringUtils.lowerCase("", Locale.ENGLISH));
|
||||
assertEquals("foo test thing", StringUtils.lowerCase("fOo test THING"), "lowerCase(String) failed");
|
||||
assertEquals("", StringUtils.lowerCase(""), "lowerCase(empty-string) failed");
|
||||
assertEquals("foo test thing", StringUtils.lowerCase("fOo test THING", Locale.ENGLISH),
|
||||
"lowerCase(String, Locale) failed");
|
||||
assertEquals("", StringUtils.lowerCase("", Locale.ENGLISH), "lowerCase(empty-string, Locale) failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCapitalize() {
|
||||
assertNull(StringUtils.capitalize(null));
|
||||
|
||||
assertEquals("capitalize(empty-string) failed",
|
||||
"", StringUtils.capitalize(""));
|
||||
assertEquals("capitalize(single-char-string) failed",
|
||||
"X", StringUtils.capitalize("x"));
|
||||
assertEquals("capitalize(String) failed",
|
||||
FOO_CAP, StringUtils.capitalize(FOO_CAP));
|
||||
assertEquals("capitalize(string) failed",
|
||||
FOO_CAP, StringUtils.capitalize(FOO_UNCAP));
|
||||
assertEquals("", StringUtils.capitalize(""), "capitalize(empty-string) failed");
|
||||
assertEquals("X", StringUtils.capitalize("x"), "capitalize(single-char-string) failed");
|
||||
assertEquals(FOO_CAP, StringUtils.capitalize(FOO_CAP), "capitalize(String) failed");
|
||||
assertEquals(FOO_CAP, StringUtils.capitalize(FOO_UNCAP), "capitalize(string) failed");
|
||||
|
||||
assertEquals("capitalize(String) is not using TitleCase",
|
||||
"\u01C8", StringUtils.capitalize("\u01C9"));
|
||||
assertEquals("\u01C8", StringUtils.capitalize("\u01C9"), "capitalize(String) is not using TitleCase");
|
||||
|
||||
// Javadoc examples
|
||||
assertNull(StringUtils.capitalize(null));
|
||||
|
@ -187,14 +178,10 @@ public class StringUtilsTest {
|
|||
public void testUnCapitalize() {
|
||||
assertNull(StringUtils.uncapitalize(null));
|
||||
|
||||
assertEquals("uncapitalize(String) failed",
|
||||
FOO_UNCAP, StringUtils.uncapitalize(FOO_CAP));
|
||||
assertEquals("uncapitalize(string) failed",
|
||||
FOO_UNCAP, StringUtils.uncapitalize(FOO_UNCAP));
|
||||
assertEquals("uncapitalize(empty-string) failed",
|
||||
"", StringUtils.uncapitalize(""));
|
||||
assertEquals("uncapitalize(single-char-string) failed",
|
||||
"x", StringUtils.uncapitalize("X"));
|
||||
assertEquals(FOO_UNCAP, StringUtils.uncapitalize(FOO_CAP), "uncapitalize(String) failed");
|
||||
assertEquals(FOO_UNCAP, StringUtils.uncapitalize(FOO_UNCAP), "uncapitalize(string) failed");
|
||||
assertEquals("", StringUtils.uncapitalize(""), "uncapitalize(empty-string) failed");
|
||||
assertEquals("x", StringUtils.uncapitalize("X"), "uncapitalize(single-char-string) failed");
|
||||
|
||||
// Examples from uncapitalize Javadoc
|
||||
assertEquals("cat", StringUtils.uncapitalize("cat"));
|
||||
|
@ -205,16 +192,16 @@ public class StringUtilsTest {
|
|||
@Test
|
||||
public void testReCapitalize() {
|
||||
// reflection type of tests: Sentences.
|
||||
assertEquals("uncapitalize(capitalize(String)) failed",
|
||||
SENTENCE_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(SENTENCE_UNCAP)));
|
||||
assertEquals("capitalize(uncapitalize(String)) failed",
|
||||
SENTENCE_CAP, StringUtils.capitalize(StringUtils.uncapitalize(SENTENCE_CAP)));
|
||||
assertEquals(SENTENCE_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(SENTENCE_UNCAP)),
|
||||
"uncapitalize(capitalize(String)) failed");
|
||||
assertEquals(SENTENCE_CAP, StringUtils.capitalize(StringUtils.uncapitalize(SENTENCE_CAP)),
|
||||
"capitalize(uncapitalize(String)) failed");
|
||||
|
||||
// reflection type of tests: One word.
|
||||
assertEquals("uncapitalize(capitalize(String)) failed",
|
||||
FOO_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(FOO_UNCAP)));
|
||||
assertEquals("capitalize(uncapitalize(String)) failed",
|
||||
FOO_CAP, StringUtils.capitalize(StringUtils.uncapitalize(FOO_CAP)));
|
||||
assertEquals(FOO_UNCAP, StringUtils.uncapitalize(StringUtils.capitalize(FOO_UNCAP)),
|
||||
"uncapitalize(capitalize(String)) failed");
|
||||
assertEquals(FOO_CAP, StringUtils.capitalize(StringUtils.uncapitalize(FOO_CAP)),
|
||||
"capitalize(uncapitalize(String)) failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -470,9 +457,9 @@ public class StringUtilsTest {
|
|||
assertEquals("ab", StringUtils.joinWith(null, "a", "b"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testJoinWithThrowsException() {
|
||||
StringUtils.joinWith(",", (Object[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.joinWith(",", (Object[]) null));
|
||||
}
|
||||
|
||||
|
||||
|
@ -567,36 +554,36 @@ public class StringUtilsTest {
|
|||
String[] res;
|
||||
// (str, sepStr)
|
||||
res = StringUtils.split(str, sepStr);
|
||||
assertEquals(msg, 3, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, "b", res[1]);
|
||||
assertEquals(msg, noMatch + "c", res[2]);
|
||||
assertEquals(3, res.length, msg);
|
||||
assertEquals("a", res[0]);
|
||||
assertEquals("b", res[1]);
|
||||
assertEquals(noMatch + "c", res[2]);
|
||||
|
||||
final String str2 = separator + "a" + separator;
|
||||
res = StringUtils.split(str2, sepStr);
|
||||
assertEquals(msg, 1, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(1, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
|
||||
res = StringUtils.split(str, sepStr, -1);
|
||||
assertEquals(msg, 3, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, "b", res[1]);
|
||||
assertEquals(msg, noMatch + "c", res[2]);
|
||||
assertEquals(3, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals("b", res[1], msg);
|
||||
assertEquals(noMatch + "c", res[2], msg);
|
||||
|
||||
res = StringUtils.split(str, sepStr, 0);
|
||||
assertEquals(msg, 3, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, "b", res[1]);
|
||||
assertEquals(msg, noMatch + "c", res[2]);
|
||||
assertEquals(3, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals("b", res[1], msg);
|
||||
assertEquals(noMatch + "c", res[2], msg);
|
||||
|
||||
res = StringUtils.split(str, sepStr, 1);
|
||||
assertEquals(msg, 1, res.length);
|
||||
assertEquals(msg, str, res[0]);
|
||||
assertEquals(1, res.length, msg);
|
||||
assertEquals(str, res[0], msg);
|
||||
|
||||
res = StringUtils.split(str, sepStr, 2);
|
||||
assertEquals(msg, 2, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, str.substring(2), res[1]);
|
||||
assertEquals(2, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals(str.substring(2), res[1], msg);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1067,41 +1054,41 @@ public class StringUtilsTest {
|
|||
String[] res;
|
||||
// (str, sepStr)
|
||||
res = StringUtils.splitPreserveAllTokens(str, sepStr);
|
||||
assertEquals(msg, 4, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, "b", res[1]);
|
||||
assertEquals(msg, "", res[2]);
|
||||
assertEquals(msg, noMatch + "c", res[3]);
|
||||
assertEquals(4, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals("b", res[1], msg);
|
||||
assertEquals("", res[2], msg);
|
||||
assertEquals(noMatch + "c", res[3], msg);
|
||||
|
||||
final String str2 = separator + "a" + separator;
|
||||
res = StringUtils.splitPreserveAllTokens(str2, sepStr);
|
||||
assertEquals(msg, 3, res.length);
|
||||
assertEquals(msg, "", res[0]);
|
||||
assertEquals(msg, "a", res[1]);
|
||||
assertEquals(msg, "", res[2]);
|
||||
assertEquals(3, res.length, msg);
|
||||
assertEquals("", res[0], msg);
|
||||
assertEquals("a", res[1], msg);
|
||||
assertEquals("", res[2], msg);
|
||||
|
||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, -1);
|
||||
assertEquals(msg, 4, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, "b", res[1]);
|
||||
assertEquals(msg, "", res[2]);
|
||||
assertEquals(msg, noMatch + "c", res[3]);
|
||||
assertEquals(4, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals("b", res[1], msg);
|
||||
assertEquals("", res[2], msg);
|
||||
assertEquals(noMatch + "c", res[3], msg);
|
||||
|
||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, 0);
|
||||
assertEquals(msg, 4, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, "b", res[1]);
|
||||
assertEquals(msg, "", res[2]);
|
||||
assertEquals(msg, noMatch + "c", res[3]);
|
||||
assertEquals(4, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals("b", res[1], msg);
|
||||
assertEquals("", res[2], msg);
|
||||
assertEquals(noMatch + "c", res[3], msg);
|
||||
|
||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, 1);
|
||||
assertEquals(msg, 1, res.length);
|
||||
assertEquals(msg, str, res[0]);
|
||||
assertEquals(1, res.length, msg);
|
||||
assertEquals(str, res[0], msg);
|
||||
|
||||
res = StringUtils.splitPreserveAllTokens(str, sepStr, 2);
|
||||
assertEquals(msg, 2, res.length);
|
||||
assertEquals(msg, "a", res[0]);
|
||||
assertEquals(msg, str.substring(2), res[1]);
|
||||
assertEquals(2, res.length, msg);
|
||||
assertEquals("a", res[0], msg);
|
||||
assertEquals(str.substring(2), res[1], msg);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1635,8 +1622,7 @@ public class StringUtilsTest {
|
|||
for (final String[] chopCase : chopCases) {
|
||||
final String original = chopCase[0];
|
||||
final String expectedResult = chopCase[1];
|
||||
assertEquals("chop(String) failed",
|
||||
expectedResult, StringUtils.chop(original));
|
||||
assertEquals(expectedResult, StringUtils.chop(original), "chop(String) failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1664,38 +1650,23 @@ public class StringUtilsTest {
|
|||
for (final String[] chompCase : chompCases) {
|
||||
final String original = chompCase[0];
|
||||
final String expectedResult = chompCase[1];
|
||||
assertEquals("chomp(String) failed",
|
||||
expectedResult, StringUtils.chomp(original));
|
||||
assertEquals(expectedResult, StringUtils.chomp(original), "chomp(String) failed");
|
||||
}
|
||||
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"foo", StringUtils.chomp("foobar", "bar"));
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"foobar", StringUtils.chomp("foobar", "baz"));
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"foo", StringUtils.chomp("foo", "foooo"));
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"foobar", StringUtils.chomp("foobar", ""));
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"foobar", StringUtils.chomp("foobar", null));
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"", StringUtils.chomp("", "foo"));
|
||||
assertEquals("chomp(String, String) failed",
|
||||
"", StringUtils.chomp("", null));
|
||||
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"));
|
||||
assertEquals("foo", StringUtils.chomp("foobar", "bar"), "chomp(String, String) failed");
|
||||
assertEquals("foobar", StringUtils.chomp("foobar", "baz"), "chomp(String, String) failed");
|
||||
assertEquals("foo", StringUtils.chomp("foo", "foooo"), "chomp(String, String) failed");
|
||||
assertEquals("foobar", StringUtils.chomp("foobar", ""), "chomp(String, String) failed");
|
||||
assertEquals("foobar", StringUtils.chomp("foobar", null), "chomp(String, String) failed");
|
||||
assertEquals("", StringUtils.chomp("", "foo"), "chomp(String, String) failed");
|
||||
assertEquals("", StringUtils.chomp("", null), "chomp(String, String) failed");
|
||||
assertEquals("", StringUtils.chomp("", ""), "chomp(String, String) failed");
|
||||
assertEquals(null, StringUtils.chomp(null, "foo"), "chomp(String, String) failed");
|
||||
assertEquals(null, StringUtils.chomp(null, null), "chomp(String, String) failed");
|
||||
assertEquals(null, StringUtils.chomp(null, ""), "chomp(String, String) failed");
|
||||
assertEquals("", StringUtils.chomp("foo", "foo"), "chomp(String, String) failed");
|
||||
assertEquals(" ", StringUtils.chomp(" foo", "foo"), "chomp(String, String) failed");
|
||||
assertEquals("foo ", StringUtils.chomp("foo ", "foo"), "chomp(String, String) failed");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -2098,12 +2069,12 @@ public class StringUtilsTest {
|
|||
final String message = "abbreviate(String,int,int) failed";
|
||||
final String actual = StringUtils.abbreviate(abcdefghijklmno, offset, maxWidth);
|
||||
if (offset >= 0 && offset < abcdefghijklmno.length()) {
|
||||
assertTrue(message + " -- should contain offset character",
|
||||
actual.indexOf((char) ('a' + offset)) != -1);
|
||||
assertTrue(actual.indexOf((char) ('a' + offset)) != -1,
|
||||
message + " -- should contain offset character");
|
||||
}
|
||||
assertTrue(message + " -- should not be greater than maxWidth",
|
||||
actual.length() <= maxWidth);
|
||||
assertEquals(message, expected, actual);
|
||||
assertTrue(actual.length() <= maxWidth,
|
||||
message + " -- should not be greater than maxWidth");
|
||||
assertEquals(expected, actual, message);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2157,12 +2128,12 @@ public class StringUtilsTest {
|
|||
final String message = "abbreviate(String,String,int,int) failed";
|
||||
final String actual = StringUtils.abbreviate(abcdefghijklmno, abbrevMarker, offset, maxWidth);
|
||||
if (offset >= 0 && offset < abcdefghijklmno.length()) {
|
||||
assertTrue(message + " -- should contain offset character",
|
||||
actual.indexOf((char) ('a' + offset)) != -1);
|
||||
assertTrue(actual.indexOf((char) ('a' + offset)) != -1,
|
||||
message + " -- should contain offset character");
|
||||
}
|
||||
assertTrue(message + " -- should not be greater than maxWidth",
|
||||
actual.length() <= maxWidth);
|
||||
assertEquals(message, expected, actual);
|
||||
assertTrue(actual.length() <= maxWidth,
|
||||
message + " -- should not be greater than maxWidth");
|
||||
assertEquals(expected, actual, message);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2426,14 +2397,14 @@ public class StringUtilsTest {
|
|||
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetLevenshteinDistance_NullString() throws Exception {
|
||||
StringUtils.getLevenshteinDistance("a", null);
|
||||
@Test
|
||||
public void testGetLevenshteinDistance_NullString() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance("a", null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetLevenshteinDistance_StringNull() throws Exception {
|
||||
StringUtils.getLevenshteinDistance(null, "a");
|
||||
@Test
|
||||
public void testGetLevenshteinDistance_StringNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance(null, "a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2500,47 +2471,47 @@ public class StringUtilsTest {
|
|||
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo", Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetLevenshteinDistance_NullStringInt() throws Exception {
|
||||
StringUtils.getLevenshteinDistance(null, "a", 0);
|
||||
@Test
|
||||
public void testGetLevenshteinDistance_NullStringInt() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance(null, "a", 0));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetLevenshteinDistance_StringNullInt() throws Exception {
|
||||
StringUtils.getLevenshteinDistance("a", null, 0);
|
||||
@Test
|
||||
public void testGetLevenshteinDistance_StringNullInt() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance("a", null, 0));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetLevenshteinDistance_StringStringNegativeInt() throws Exception {
|
||||
StringUtils.getLevenshteinDistance("a", "a", -1);
|
||||
@Test
|
||||
public void testGetLevenshteinDistance_StringStringNegativeInt() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getLevenshteinDistance("a", "a", -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJaroWinklerDistance_StringString() {
|
||||
assertEquals(0.93d, StringUtils.getJaroWinklerDistance("frog", "fog"), 0.0d);
|
||||
assertEquals(0.0d, StringUtils.getJaroWinklerDistance("fly", "ant"), 0.0d);
|
||||
assertEquals(0.44d, StringUtils.getJaroWinklerDistance("elephant", "hippo"), 0.0d);
|
||||
assertEquals(0.84d, StringUtils.getJaroWinklerDistance("dwayne", "duane"), 0.0d);
|
||||
assertEquals(0.93d, StringUtils.getJaroWinklerDistance("ABC Corporation", "ABC Corp"), 0.0d);
|
||||
assertEquals(0.95d, StringUtils.getJaroWinklerDistance("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.0d);
|
||||
assertEquals(0.92d, StringUtils.getJaroWinklerDistance("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d);
|
||||
assertEquals(0.88d, StringUtils.getJaroWinklerDistance("PENNSYLVANIA", "PENNCISYLVNIA"), 0.0d);
|
||||
assertEquals(0.63d, StringUtils.getJaroWinklerDistance("Haus Ingeborg", "Ingeborg Esser"), 0.0d);
|
||||
assertTrue(0.93d == StringUtils.getJaroWinklerDistance("frog", "fog"));
|
||||
assertTrue(0.0d == StringUtils.getJaroWinklerDistance("fly", "ant"));
|
||||
assertTrue(0.44d == StringUtils.getJaroWinklerDistance("elephant", "hippo"));
|
||||
assertTrue(0.84d == StringUtils.getJaroWinklerDistance("dwayne", "duane"));
|
||||
assertTrue(0.93d == StringUtils.getJaroWinklerDistance("ABC Corporation", "ABC Corp"));
|
||||
assertTrue(0.95d == StringUtils.getJaroWinklerDistance("D N H Enterprises Inc", "D & H Enterprises, Inc."));
|
||||
assertTrue(0.92d == StringUtils.getJaroWinklerDistance("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"));
|
||||
assertTrue(0.88d == StringUtils.getJaroWinklerDistance("PENNSYLVANIA", "PENNCISYLVNIA"));
|
||||
assertTrue(0.63d == StringUtils.getJaroWinklerDistance("Haus Ingeborg", "Ingeborg Esser"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetJaroWinklerDistance_NullNull() throws Exception {
|
||||
StringUtils.getJaroWinklerDistance(null, null);
|
||||
@Test
|
||||
public void testGetJaroWinklerDistance_NullNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getJaroWinklerDistance(null, null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetJaroWinklerDistance_StringNull() throws Exception {
|
||||
StringUtils.getJaroWinklerDistance(" ", null);
|
||||
@Test
|
||||
public void testGetJaroWinklerDistance_StringNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getJaroWinklerDistance(" ", null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetJaroWinklerDistance_NullString() throws Exception {
|
||||
StringUtils.getJaroWinklerDistance(null, "clear");
|
||||
@Test
|
||||
public void testGetJaroWinklerDistance_NullString() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getJaroWinklerDistance(null, "clear"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2554,24 +2525,24 @@ public class StringUtilsTest {
|
|||
assertEquals(3, StringUtils.getFuzzyDistance("Apache Software Foundation", "asf", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetFuzzyDistance_NullNullNull() throws Exception {
|
||||
StringUtils.getFuzzyDistance(null, null, null);
|
||||
@Test
|
||||
public void testGetFuzzyDistance_NullNullNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(null, null, null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetFuzzyDistance_StringNullLoclae() throws Exception {
|
||||
StringUtils.getFuzzyDistance(" ", null, Locale.ENGLISH);
|
||||
@Test
|
||||
public void testGetFuzzyDistance_StringNullLoclae() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(" ", null, Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetFuzzyDistance_NullStringLocale() throws Exception {
|
||||
StringUtils.getFuzzyDistance(null, "clear", Locale.ENGLISH);
|
||||
@Test
|
||||
public void testGetFuzzyDistance_NullStringLocale() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(null, "clear", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetFuzzyDistance_StringStringNull() throws Exception {
|
||||
StringUtils.getFuzzyDistance(" ", "clear", null);
|
||||
@Test
|
||||
public void testGetFuzzyDistance_StringStringNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StringUtils.getFuzzyDistance(" ", "clear", null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2663,23 +2634,23 @@ public class StringUtilsTest {
|
|||
@Test
|
||||
public void testRemoveStartIgnoreCase() {
|
||||
// StringUtils.removeStart("", *) = ""
|
||||
assertNull("removeStartIgnoreCase(null, null)", StringUtils.removeStartIgnoreCase(null, null));
|
||||
assertNull("removeStartIgnoreCase(null, \"\")", StringUtils.removeStartIgnoreCase(null, ""));
|
||||
assertNull("removeStartIgnoreCase(null, \"a\")", StringUtils.removeStartIgnoreCase(null, "a"));
|
||||
assertNull(StringUtils.removeStartIgnoreCase(null, null), "removeStartIgnoreCase(null, null)");
|
||||
assertNull(StringUtils.removeStartIgnoreCase(null, ""), "removeStartIgnoreCase(null, \"\")");
|
||||
assertNull(StringUtils.removeStartIgnoreCase(null, "a"), "removeStartIgnoreCase(null, \"a\")");
|
||||
|
||||
// StringUtils.removeStart(*, null) = *
|
||||
assertEquals("removeStartIgnoreCase(\"\", null)", StringUtils.removeStartIgnoreCase("", null), "");
|
||||
assertEquals("removeStartIgnoreCase(\"\", \"\")", StringUtils.removeStartIgnoreCase("", ""), "");
|
||||
assertEquals("removeStartIgnoreCase(\"\", \"a\")", StringUtils.removeStartIgnoreCase("", "a"), "");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("", null), "", "removeStartIgnoreCase(\"\", null)");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("", ""), "", "removeStartIgnoreCase(\"\", \"\")");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("", "a"), "", "removeStartIgnoreCase(\"\", \"a\")");
|
||||
|
||||
// All others:
|
||||
assertEquals("removeStartIgnoreCase(\"www.domain.com\", \"www.\")", StringUtils.removeStartIgnoreCase("www.domain.com", "www."), "domain.com");
|
||||
assertEquals("removeStartIgnoreCase(\"domain.com\", \"www.\")", StringUtils.removeStartIgnoreCase("domain.com", "www."), "domain.com");
|
||||
assertEquals("removeStartIgnoreCase(\"domain.com\", \"\")", StringUtils.removeStartIgnoreCase("domain.com", ""), "domain.com");
|
||||
assertEquals("removeStartIgnoreCase(\"domain.com\", null)", StringUtils.removeStartIgnoreCase("domain.com", null), "domain.com");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("www.domain.com", "www."), "domain.com", "removeStartIgnoreCase(\"www.domain.com\", \"www.\")");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("domain.com", "www."), "domain.com", "removeStartIgnoreCase(\"domain.com\", \"www.\")");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("domain.com", ""), "domain.com", "removeStartIgnoreCase(\"domain.com\", \"\")");
|
||||
assertEquals(StringUtils.removeStartIgnoreCase("domain.com", null), "domain.com", "removeStartIgnoreCase(\"domain.com\", null)");
|
||||
|
||||
// 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
|
||||
|
@ -2705,25 +2676,25 @@ public class StringUtilsTest {
|
|||
@Test
|
||||
public void testRemoveEndIgnoreCase() {
|
||||
// StringUtils.removeEndIgnoreCase("", *) = ""
|
||||
assertNull("removeEndIgnoreCase(null, null)", StringUtils.removeEndIgnoreCase(null, null));
|
||||
assertNull("removeEndIgnoreCase(null, \"\")", StringUtils.removeEndIgnoreCase(null, ""));
|
||||
assertNull("removeEndIgnoreCase(null, \"a\")", StringUtils.removeEndIgnoreCase(null, "a"));
|
||||
assertNull(StringUtils.removeEndIgnoreCase(null, null), "removeEndIgnoreCase(null, null)");
|
||||
assertNull(StringUtils.removeEndIgnoreCase(null, ""), "removeEndIgnoreCase(null, \"\")");
|
||||
assertNull(StringUtils.removeEndIgnoreCase(null, "a"), "removeEndIgnoreCase(null, \"a\")");
|
||||
|
||||
// StringUtils.removeEnd(*, null) = *
|
||||
assertEquals("removeEndIgnoreCase(\"\", null)", StringUtils.removeEndIgnoreCase("", null), "");
|
||||
assertEquals("removeEndIgnoreCase(\"\", \"\")", StringUtils.removeEndIgnoreCase("", ""), "");
|
||||
assertEquals("removeEndIgnoreCase(\"\", \"a\")", StringUtils.removeEndIgnoreCase("", "a"), "");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("", null), "", "removeEndIgnoreCase(\"\", null)");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("", ""), "", "removeEndIgnoreCase(\"\", \"\")");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("", "a"), "", "removeEndIgnoreCase(\"\", \"a\")");
|
||||
|
||||
// All others:
|
||||
assertEquals("removeEndIgnoreCase(\"www.domain.com.\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain.com.", ".com"), "www.domain.com.");
|
||||
assertEquals("removeEndIgnoreCase(\"www.domain.com\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain.com", ".com"), "www.domain");
|
||||
assertEquals("removeEndIgnoreCase(\"www.domain\", \".com\")", StringUtils.removeEndIgnoreCase("www.domain", ".com"), "www.domain");
|
||||
assertEquals("removeEndIgnoreCase(\"domain.com\", \"\")", StringUtils.removeEndIgnoreCase("domain.com", ""), "domain.com");
|
||||
assertEquals("removeEndIgnoreCase(\"domain.com\", null)", StringUtils.removeEndIgnoreCase("domain.com", null), "domain.com");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("www.domain.com.", ".com"), "www.domain.com.", "removeEndIgnoreCase(\"www.domain.com.\", \".com\")");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("www.domain.com", ".com"), "www.domain", "removeEndIgnoreCase(\"www.domain.com\", \".com\")");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("www.domain", ".com"), "www.domain", "removeEndIgnoreCase(\"www.domain\", \".com\")");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("domain.com", ""), "domain.com", "removeEndIgnoreCase(\"domain.com\", \"\")");
|
||||
assertEquals(StringUtils.removeEndIgnoreCase("domain.com", null), "domain.com", "removeEndIgnoreCase(\"domain.com\", null)");
|
||||
|
||||
// Case insensitive:
|
||||
assertEquals("removeEndIgnoreCase(\"www.domain.com\", \".COM\")", StringUtils.removeEndIgnoreCase("www.domain.com", ".COM"), "www.domain");
|
||||
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(StringUtils.removeEndIgnoreCase("www.domain.COM", ".com"), "www.domain", "removeEndIgnoreCase(\"www.domain.COM\", \".com\")");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3028,23 +2999,23 @@ public class StringUtilsTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAppendIfMissing() {
|
||||
assertEquals("appendIfMissing(null,null)", null, StringUtils.appendIfMissing(null, null));
|
||||
assertEquals("appendIfMissing(abc,null)", "abc", StringUtils.appendIfMissing("abc", null));
|
||||
assertEquals("appendIfMissing(\"\",xyz)", "xyz", StringUtils.appendIfMissing("", "xyz"));
|
||||
assertEquals("appendIfMissing(abc,xyz)", "abcxyz", StringUtils.appendIfMissing("abc", "xyz"));
|
||||
assertEquals("appendIfMissing(abcxyz,xyz)", "abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz"));
|
||||
assertEquals("appendIfMissing(aXYZ,xyz)", "aXYZxyz", StringUtils.appendIfMissing("aXYZ", "xyz"));
|
||||
assertEquals(null, StringUtils.appendIfMissing(null, null), "appendIfMissing(null,null)");
|
||||
assertEquals("abc", StringUtils.appendIfMissing("abc", null), "appendIfMissing(abc,null)");
|
||||
assertEquals("xyz", StringUtils.appendIfMissing("", "xyz"), "appendIfMissing(\"\",xyz)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissing("abc", "xyz"), "appendIfMissing(abc,xyz)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz"), "appendIfMissing(abcxyz,xyz)");
|
||||
assertEquals("aXYZxyz", StringUtils.appendIfMissing("aXYZ", "xyz"), "appendIfMissing(aXYZ,xyz)");
|
||||
|
||||
assertEquals("appendIfMissing(null,null,null)", null, StringUtils.appendIfMissing(null, null, (CharSequence[]) null));
|
||||
assertEquals("appendIfMissing(abc,null,null)", "abc", StringUtils.appendIfMissing("abc", null, (CharSequence[]) null));
|
||||
assertEquals("appendIfMissing(\"\",xyz,null))", "xyz", StringUtils.appendIfMissing("", "xyz", (CharSequence[]) null));
|
||||
assertEquals("appendIfMissing(abc,xyz,{null})", "abcxyz", StringUtils.appendIfMissing("abc", "xyz", new CharSequence[]{null}));
|
||||
assertEquals("appendIfMissing(abc,xyz,\"\")", "abc", StringUtils.appendIfMissing("abc", "xyz", ""));
|
||||
assertEquals("appendIfMissing(abc,xyz,mno)", "abcxyz", StringUtils.appendIfMissing("abc", "xyz", "mno"));
|
||||
assertEquals("appendIfMissing(abcxyz,xyz,mno)", "abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz", "mno"));
|
||||
assertEquals("appendIfMissing(abcmno,xyz,mno)", "abcmno", StringUtils.appendIfMissing("abcmno", "xyz", "mno"));
|
||||
assertEquals("appendIfMissing(abcXYZ,xyz,mno)", "abcXYZxyz", StringUtils.appendIfMissing("abcXYZ", "xyz", "mno"));
|
||||
assertEquals("appendIfMissing(abcMNO,xyz,mno)", "abcMNOxyz", StringUtils.appendIfMissing("abcMNO", "xyz", "mno"));
|
||||
assertEquals(null, StringUtils.appendIfMissing(null, null, (CharSequence[]) null), "appendIfMissing(null,null,null)");
|
||||
assertEquals("abc", StringUtils.appendIfMissing("abc", null, (CharSequence[]) null), "appendIfMissing(abc,null,null)");
|
||||
assertEquals("xyz", StringUtils.appendIfMissing("", "xyz", (CharSequence[]) null), "appendIfMissing(\"\",xyz,null))");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissing("abc", "xyz", new CharSequence[]{null}), "appendIfMissing(abc,xyz,{null})");
|
||||
assertEquals("abc", StringUtils.appendIfMissing("abc", "xyz", ""), "appendIfMissing(abc,xyz,\"\")");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissing("abc", "xyz", "mno"), "appendIfMissing(abc,xyz,mno)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissing("abcxyz", "xyz", "mno"), "appendIfMissing(abcxyz,xyz,mno)");
|
||||
assertEquals("abcmno", StringUtils.appendIfMissing("abcmno", "xyz", "mno"), "appendIfMissing(abcmno,xyz,mno)");
|
||||
assertEquals("abcXYZxyz", StringUtils.appendIfMissing("abcXYZ", "xyz", "mno"), "appendIfMissing(abcXYZ,xyz,mno)");
|
||||
assertEquals("abcMNOxyz", StringUtils.appendIfMissing("abcMNO", "xyz", "mno"), "appendIfMissing(abcMNO,xyz,mno)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3052,23 +3023,23 @@ public class StringUtilsTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAppendIfMissingIgnoreCase() {
|
||||
assertEquals("appendIfMissingIgnoreCase(null,null)", null, StringUtils.appendIfMissingIgnoreCase(null, null));
|
||||
assertEquals("appendIfMissingIgnoreCase(abc,null)", "abc", StringUtils.appendIfMissingIgnoreCase("abc", null));
|
||||
assertEquals("appendIfMissingIgnoreCase(\"\",xyz)", "xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abcxyz,xyz)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abcXYZ,xyz)", "abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz"));
|
||||
assertEquals(null, StringUtils.appendIfMissingIgnoreCase(null, null), "appendIfMissingIgnoreCase(null,null)");
|
||||
assertEquals("abc", StringUtils.appendIfMissingIgnoreCase("abc", null), "appendIfMissingIgnoreCase(abc,null)");
|
||||
assertEquals("xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz"), "appendIfMissingIgnoreCase(\"\",xyz)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz"), "appendIfMissingIgnoreCase(abc,xyz)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz"), "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("appendIfMissingIgnoreCase(abc,null,null)", "abc", StringUtils.appendIfMissingIgnoreCase("abc", null, (CharSequence[]) null));
|
||||
assertEquals("appendIfMissingIgnoreCase(\"\",xyz,null)", "xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz", (CharSequence[]) null));
|
||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz,{null})", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}));
|
||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz,\"\")", "abc", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", ""));
|
||||
assertEquals("appendIfMissingIgnoreCase(abc,xyz,mno)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "mno"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abcxyz,xyz,mno)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abcmno,xyz,mno)", "abcmno", StringUtils.appendIfMissingIgnoreCase("abcmno", "xyz", "mno"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abcXYZ,xyz,mno)", "abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno"));
|
||||
assertEquals("appendIfMissingIgnoreCase(abcMNO,xyz,mno)", "abcMNO", StringUtils.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno"));
|
||||
assertEquals(null, StringUtils.appendIfMissingIgnoreCase(null, null, (CharSequence[]) null), "appendIfMissingIgnoreCase(null,null,null)");
|
||||
assertEquals("abc", StringUtils.appendIfMissingIgnoreCase("abc", null, (CharSequence[]) null), "appendIfMissingIgnoreCase(abc,null,null)");
|
||||
assertEquals("xyz", StringUtils.appendIfMissingIgnoreCase("", "xyz", (CharSequence[]) null), "appendIfMissingIgnoreCase(\"\",xyz,null)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}), "appendIfMissingIgnoreCase(abc,xyz,{null})");
|
||||
assertEquals("abc", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", ""), "appendIfMissingIgnoreCase(abc,xyz,\"\")");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "mno"), "appendIfMissingIgnoreCase(abc,xyz,mno)");
|
||||
assertEquals("abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno"), "appendIfMissingIgnoreCase(abcxyz,xyz,mno)");
|
||||
assertEquals("abcmno", StringUtils.appendIfMissingIgnoreCase("abcmno", "xyz", "mno"), "appendIfMissingIgnoreCase(abcmno,xyz,mno)");
|
||||
assertEquals("abcXYZ", StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno"), "appendIfMissingIgnoreCase(abcXYZ,xyz,mno)");
|
||||
assertEquals("abcMNO", StringUtils.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno"), "appendIfMissingIgnoreCase(abcMNO,xyz,mno)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3076,23 +3047,23 @@ public class StringUtilsTest {
|
|||
*/
|
||||
@Test
|
||||
public void testPrependIfMissing() {
|
||||
assertEquals("prependIfMissing(null,null)", null, StringUtils.prependIfMissing(null, null));
|
||||
assertEquals("prependIfMissing(abc,null)", "abc", StringUtils.prependIfMissing("abc", null));
|
||||
assertEquals("prependIfMissing(\"\",xyz)", "xyz", StringUtils.prependIfMissing("", "xyz"));
|
||||
assertEquals("prependIfMissing(abc,xyz)", "xyzabc", StringUtils.prependIfMissing("abc", "xyz"));
|
||||
assertEquals("prependIfMissing(xyzabc,xyz)", "xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz"));
|
||||
assertEquals("prependIfMissing(XYZabc,xyz)", "xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz"));
|
||||
assertEquals(null, StringUtils.prependIfMissing(null, null), "prependIfMissing(null,null)");
|
||||
assertEquals("abc", StringUtils.prependIfMissing("abc", null), "prependIfMissing(abc,null)");
|
||||
assertEquals("xyz", StringUtils.prependIfMissing("", "xyz"), "prependIfMissing(\"\",xyz)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissing("abc", "xyz"), "prependIfMissing(abc,xyz)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz"), "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("prependIfMissing(abc,null,null)", "abc", StringUtils.prependIfMissing("abc", null, (CharSequence[]) null));
|
||||
assertEquals("prependIfMissing(\"\",xyz,null)", "xyz", StringUtils.prependIfMissing("", "xyz", (CharSequence[]) null));
|
||||
assertEquals("prependIfMissing(abc,xyz,{null})", "xyzabc", StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null}));
|
||||
assertEquals("prependIfMissing(abc,xyz,\"\")", "abc", StringUtils.prependIfMissing("abc", "xyz", ""));
|
||||
assertEquals("prependIfMissing(abc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("abc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissing(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissing(mnoabc,xyz,mno)", "mnoabc", StringUtils.prependIfMissing("mnoabc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissing(XYZabc,xyz,mno)", "xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissing(MNOabc,xyz,mno)", "xyzMNOabc", StringUtils.prependIfMissing("MNOabc", "xyz", "mno"));
|
||||
assertEquals(null, StringUtils.prependIfMissing(null, null, (CharSequence[]) null), "prependIfMissing(null,null null)");
|
||||
assertEquals("abc", StringUtils.prependIfMissing("abc", null, (CharSequence[]) null), "prependIfMissing(abc,null,null)");
|
||||
assertEquals("xyz", StringUtils.prependIfMissing("", "xyz", (CharSequence[]) null), "prependIfMissing(\"\",xyz,null)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null}), "prependIfMissing(abc,xyz,{null})");
|
||||
assertEquals("abc", StringUtils.prependIfMissing("abc", "xyz", ""), "prependIfMissing(abc,xyz,\"\")");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissing("abc", "xyz", "mno"), "prependIfMissing(abc,xyz,mno)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz", "mno"), "prependIfMissing(xyzabc,xyz,mno)");
|
||||
assertEquals("mnoabc", StringUtils.prependIfMissing("mnoabc", "xyz", "mno"), "prependIfMissing(mnoabc,xyz,mno)");
|
||||
assertEquals("xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz", "mno"), "prependIfMissing(XYZabc,xyz,mno)");
|
||||
assertEquals("xyzMNOabc", StringUtils.prependIfMissing("MNOabc", "xyz", "mno"), "prependIfMissing(MNOabc,xyz,mno)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3100,23 +3071,23 @@ public class StringUtilsTest {
|
|||
*/
|
||||
@Test
|
||||
public void testPrependIfMissingIgnoreCase() {
|
||||
assertEquals("prependIfMissingIgnoreCase(null,null)", null, StringUtils.prependIfMissingIgnoreCase(null, null));
|
||||
assertEquals("prependIfMissingIgnoreCase(abc,null)", "abc", StringUtils.prependIfMissingIgnoreCase("abc", null));
|
||||
assertEquals("prependIfMissingIgnoreCase(\"\",xyz)", "xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz"));
|
||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz"));
|
||||
assertEquals("prependIfMissingIgnoreCase(xyzabc,xyz)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz"));
|
||||
assertEquals("prependIfMissingIgnoreCase(XYZabc,xyz)", "XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz"));
|
||||
assertEquals(null, StringUtils.prependIfMissingIgnoreCase(null, null), "prependIfMissingIgnoreCase(null,null)");
|
||||
assertEquals("abc", StringUtils.prependIfMissingIgnoreCase("abc", null), "prependIfMissingIgnoreCase(abc,null)");
|
||||
assertEquals("xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz"), "prependIfMissingIgnoreCase(\"\",xyz)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz"), "prependIfMissingIgnoreCase(abc,xyz)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz"), "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("prependIfMissingIgnoreCase(abc,null,null)", "abc", StringUtils.prependIfMissingIgnoreCase("abc", null, (CharSequence[]) null));
|
||||
assertEquals("prependIfMissingIgnoreCase(\"\",xyz,null)", "xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz", (CharSequence[]) null));
|
||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz,{null})", "xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}));
|
||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz,\"\")", "abc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", ""));
|
||||
assertEquals("prependIfMissingIgnoreCase(abc,xyz,mno)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissingIgnoreCase(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissingIgnoreCase(mnoabc,xyz,mno)", "mnoabc", StringUtils.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissingIgnoreCase(XYZabc,xyz,mno)", "XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno"));
|
||||
assertEquals("prependIfMissingIgnoreCase(MNOabc,xyz,mno)", "MNOabc", StringUtils.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno"));
|
||||
assertEquals(null, StringUtils.prependIfMissingIgnoreCase(null, null, (CharSequence[]) null), "prependIfMissingIgnoreCase(null,null null)");
|
||||
assertEquals("abc", StringUtils.prependIfMissingIgnoreCase("abc", null, (CharSequence[]) null), "prependIfMissingIgnoreCase(abc,null,null)");
|
||||
assertEquals("xyz", StringUtils.prependIfMissingIgnoreCase("", "xyz", (CharSequence[]) null), "prependIfMissingIgnoreCase(\"\",xyz,null)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}), "prependIfMissingIgnoreCase(abc,xyz,{null})");
|
||||
assertEquals("abc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", ""), "prependIfMissingIgnoreCase(abc,xyz,\"\")");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "mno"), "prependIfMissingIgnoreCase(abc,xyz,mno)");
|
||||
assertEquals("xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno"), "prependIfMissingIgnoreCase(xyzabc,xyz,mno)");
|
||||
assertEquals("mnoabc", StringUtils.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno"), "prependIfMissingIgnoreCase(mnoabc,xyz,mno)");
|
||||
assertEquals("XYZabc", StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno"), "prependIfMissingIgnoreCase(XYZabc,xyz,mno)");
|
||||
assertEquals("MNOabc", StringUtils.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno"), "prependIfMissingIgnoreCase(MNOabc,xyz,mno)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
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
|
||||
|
@ -220,19 +220,19 @@ public class StringUtilsTrimStripTest {
|
|||
@Test
|
||||
public void testStripAccents() {
|
||||
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" +
|
||||
"\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D1\u00D2\u00D3" +
|
||||
"\u00D4\u00D5\u00D6\u00D9\u00DA\u00DB\u00DC\u00DD";
|
||||
assertEquals( "Failed to strip accents from " + lots,
|
||||
"AAAAAACEEEEIIIINOOOOOUUUUY",
|
||||
StringUtils.stripAccents(lots));
|
||||
assertEquals("AAAAAACEEEEIIIINOOOOOUUUUY",
|
||||
StringUtils.stripAccents(lots),
|
||||
"Failed to strip accents from " + lots);
|
||||
|
||||
assertNull( "Failed null safety", StringUtils.stripAccents(null) );
|
||||
assertEquals( "Failed empty String", "", StringUtils.stripAccents("") );
|
||||
assertEquals( "Failed to handle non-accented text", "control", StringUtils.stripAccents("control") );
|
||||
assertEquals( "Failed to handle easy example", "eclair", StringUtils.stripAccents("\u00E9clair") );
|
||||
assertNull(StringUtils.stripAccents(null), "Failed null safety");
|
||||
assertEquals("", StringUtils.stripAccents(""), "Failed empty String");
|
||||
assertEquals("control", StringUtils.stripAccents("control"), "Failed to handle non-accented text");
|
||||
assertEquals("eclair", StringUtils.stripAccents("\u00E9clair"), "Failed to handle easy example");
|
||||
assertEquals("ALOSZZCN aloszzcn", StringUtils.stripAccents("\u0104\u0141\u00D3\u015A\u017B\u0179\u0106\u0143 "
|
||||
+ "\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_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.SystemUtils}.
|
||||
|
@ -64,7 +64,7 @@ public class SystemUtilsTest {
|
|||
public void testGetEnvironmentVariableAbsent() {
|
||||
final String name = "THIS_ENV_VAR_SHOULD_NOT_EXIST_FOR_THIS_TEST_TO_PASS";
|
||||
final String expected = System.getenv(name);
|
||||
Assert.assertNull(expected);
|
||||
assertNull(expected);
|
||||
final String value = SystemUtils.getEnvironmentVariable(name, "DEFAULT");
|
||||
assertEquals("DEFAULT", value);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
|
||||
package org.apache.commons.lang3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
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.Modifier;
|
||||
|
@ -32,76 +33,78 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.ThreadUtils}.
|
||||
*/
|
||||
public class ThreadUtilsTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadName() throws InterruptedException {
|
||||
ThreadUtils.findThreadsByName(null);
|
||||
@Test
|
||||
public void testNullThreadName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadGroupName() throws InterruptedException {
|
||||
ThreadUtils.findThreadGroupsByName(null);
|
||||
@Test
|
||||
public void testNullThreadGroupName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadGroupsByName(null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadThreadGroupName1() throws InterruptedException {
|
||||
ThreadUtils.findThreadsByName(null, "tgname");
|
||||
@Test
|
||||
public void testNullThreadThreadGroupName1() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null, "tgname"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadThreadGroupName2() throws InterruptedException {
|
||||
ThreadUtils.findThreadsByName("tname", (String) null);
|
||||
@Test
|
||||
public void testNullThreadThreadGroupName2() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName("tname", (String) null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadThreadGroupName3() throws InterruptedException {
|
||||
ThreadUtils.findThreadsByName(null, (String) null);
|
||||
@Test
|
||||
public void testNullThreadThreadGroupName3() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null, (String) null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadThreadGroup1() throws InterruptedException {
|
||||
ThreadUtils.findThreadsByName("tname", (ThreadGroup) null);
|
||||
@Test
|
||||
public void testNullThreadThreadGroup1() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName("tname", (ThreadGroup) null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadThreadGroup2() throws InterruptedException {
|
||||
ThreadUtils.findThreadById(1L, (ThreadGroup) null);
|
||||
@Test
|
||||
public void testNullThreadThreadGroup2() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadById(1L, (ThreadGroup) null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullThreadThreadGroup3() throws InterruptedException {
|
||||
ThreadUtils.findThreadsByName(null, (ThreadGroup) null);
|
||||
@Test
|
||||
public void testNullThreadThreadGroup3() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadsByName(null, (ThreadGroup) null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testInvalidThreadId() throws InterruptedException {
|
||||
ThreadUtils.findThreadById(-5L);
|
||||
@Test
|
||||
public void testInvalidThreadId() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadById(-5L));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testThreadGroupsByIdFail() throws InterruptedException {
|
||||
ThreadUtils.findThreadById(Thread.currentThread().getId(), (String) null);
|
||||
@Test
|
||||
public void testThreadGroupsByIdFail() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ThreadUtils.findThreadById(Thread.currentThread().getId(), (String) null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testThreadgroupsNullParent() throws InterruptedException {
|
||||
ThreadUtils.findThreadGroups(null, true, ThreadUtils.ALWAYS_TRUE_PREDICATE);
|
||||
@Test
|
||||
public void testThreadgroupsNullParent() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ThreadUtils.findThreadGroups(null, true, ThreadUtils.ALWAYS_TRUE_PREDICATE));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testThreadgroupsNullPredicate() throws InterruptedException {
|
||||
ThreadUtils.findThreadGroups(null);
|
||||
@Test
|
||||
public void testThreadgroupsNullPredicate() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreadGroups(null));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testThreadsNullPredicate() throws InterruptedException {
|
||||
ThreadUtils.findThreads(null);
|
||||
@Test
|
||||
public void testThreadsNullPredicate() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ThreadUtils.findThreads(null));
|
||||
}
|
||||
|
||||
@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