You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2018/10/11 20:29:55 UTC
[6/6] [lang] Update tests to JUnit Jupiter (closes #375)
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.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/e99b0dde
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/e99b0dde
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/e99b0dde
Branch: refs/heads/master
Commit: e99b0dde8ee5069eaee745b62b57b109def4b22c
Parents: ca2e59c
Author: Allon Mureinik <mu...@gmail.com>
Authored: Thu Oct 11 16:21:52 2018 +0300
Committer: pascalschumacher <pa...@gmx.net>
Committed: Thu Oct 11 22:28:38 2018 +0200
----------------------------------------------------------------------
pom.xml | 6 -
.../commons/lang3/AnnotationUtilsTest.java | 134 ++-
.../org/apache/commons/lang3/ArchUtilsTest.java | 16 +-
.../apache/commons/lang3/ArrayUtilsAddTest.java | 14 +-
.../commons/lang3/ArrayUtilsInsertTest.java | 10 +-
.../lang3/ArrayUtilsRemoveMultipleTest.java | 121 +-
.../commons/lang3/ArrayUtilsRemoveTest.java | 10 +-
.../apache/commons/lang3/ArrayUtilsTest.java | 1099 +++++++-----------
.../org/apache/commons/lang3/BitFieldTest.java | 8 +-
.../apache/commons/lang3/BooleanUtilsTest.java | 784 ++++++-------
.../apache/commons/lang3/CharEncodingTest.java | 10 +-
.../org/apache/commons/lang3/CharRangeTest.java | 17 +-
.../commons/lang3/CharSequenceUtilsTest.java | 27 +-
.../org/apache/commons/lang3/CharSetTest.java | 12 +-
.../apache/commons/lang3/CharSetUtilsTest.java | 12 +-
.../org/apache/commons/lang3/CharUtilsTest.java | 16 +-
.../commons/lang3/ClassPathUtilsTest.java | 65 +-
.../apache/commons/lang3/ClassUtilsTest.java | 575 +++++----
.../apache/commons/lang3/ConversionTest.java | 10 +-
.../org/apache/commons/lang3/EnumUtilsTest.java | 123 +-
.../apache/commons/lang3/JavaVersionTest.java | 48 +-
.../apache/commons/lang3/LocaleUtilsTest.java | 26 +-
.../lang3/NotImplementedExceptionTest.java | 14 +-
.../apache/commons/lang3/ObjectUtilsTest.java | 134 +--
.../commons/lang3/RandomStringUtilsTest.java | 110 +-
.../apache/commons/lang3/RandomUtilsTest.java | 67 +-
.../org/apache/commons/lang3/RangeTest.java | 79 +-
.../apache/commons/lang3/RegExUtilsTest.java | 8 +-
.../commons/lang3/SerializationUtilsTest.java | 88 +-
.../commons/lang3/StringEscapeUtilsTest.java | 147 ++-
.../commons/lang3/StringUtilsContainsTest.java | 26 +-
.../lang3/StringUtilsEmptyBlankTest.java | 10 +-
.../lang3/StringUtilsEqualsIndexOfTest.java | 16 +-
.../apache/commons/lang3/StringUtilsIsTest.java | 6 +-
.../lang3/StringUtilsStartsEndsWithTest.java | 168 +--
.../commons/lang3/StringUtilsSubstringTest.java | 8 +-
.../apache/commons/lang3/StringUtilsTest.java | 525 ++++-----
.../commons/lang3/StringUtilsTrimStripTest.java | 26 +-
.../apache/commons/lang3/SystemUtilsTest.java | 14 +-
.../apache/commons/lang3/ThreadUtilsTest.java | 95 +-
.../commons/lang3/test/SystemDefaults.java | 40 -
.../lang3/test/SystemDefaultsSwitch.java | 113 --
.../lang3/test/SystemDefaultsSwitchTest.java | 89 --
43 files changed, 2215 insertions(+), 2711 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5d69ade..6875f8b 100644
--- a/pom.xml
+++ b/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>
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java b/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java
index fc656ae..fb129d0 100644
--- a/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java
@@ -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,65 +458,73 @@ public class AnnotationUtilsTest {
}
}
- @Test(timeout = 666000)
- public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
- final Test real = getClass().getDeclaredMethod(
- "testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
+ @Test
+ public void testGeneratedAnnotationEquivalentToRealAnnotation() {
+ assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
+ final Test real = getClass().getDeclaredMethod(
+ "testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
- final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
+ final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
- @Override
- public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
- return Boolean.valueOf(proxy == args[0]);
+ @Override
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
+ if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
+ return Boolean.valueOf(proxy == args[0]);
+ }
+ if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
+ return Integer.valueOf(System.identityHashCode(proxy));
+ }
+ if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
+ return "Test proxy";
+ }
+ return method.invoke(real, args);
}
- if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
- return Integer.valueOf(System.identityHashCode(proxy));
- }
- if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
- return "Test proxy";
- }
- return method.invoke(real, args);
- }
- };
+ };
- final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread()
- .getContextClassLoader(), new Class[] { Test.class },
- generatedTestInvocationHandler);
- assertTrue(real.equals(generated));
- assertFalse(generated.equals(real));
- assertTrue(AnnotationUtils.equals(generated, real));
- assertTrue(AnnotationUtils.equals(real, generated));
+ final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread()
+ .getContextClassLoader(), new Class[]{Test.class},
+ generatedTestInvocationHandler);
+ assertTrue(real.equals(generated));
+ assertFalse(generated.equals(real));
+ assertTrue(AnnotationUtils.equals(generated, real));
+ assertTrue(AnnotationUtils.equals(real, generated));
- final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
- .getContextClassLoader(), new Class[] { Test.class },
- generatedTestInvocationHandler);
- assertFalse(generated.equals(generated2));
- assertFalse(generated2.equals(generated));
- assertTrue(AnnotationUtils.equals(generated, generated2));
- assertTrue(AnnotationUtils.equals(generated2, generated));
+ final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
+ .getContextClassLoader(), new Class[]{Test.class},
+ generatedTestInvocationHandler);
+ assertFalse(generated.equals(generated2));
+ assertFalse(generated2.equals(generated));
+ assertTrue(AnnotationUtils.equals(generated, generated2));
+ assertTrue(AnnotationUtils.equals(generated2, generated));
+ });
}
- @Test(timeout = 666000)
- public void testHashCode() throws Exception {
- 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
+ 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);
- final String annotationString = AnnotationUtils.toString(testAnnotation);
- assertTrue(annotationString.startsWith("@org.junit.Test("));
- assertTrue(annotationString.endsWith(")"));
- assertTrue(annotationString.contains("expected=class org.junit.Test$None"));
- assertTrue(annotationString.contains("timeout=666000"));
- assertTrue(annotationString.contains(", "));
+ @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.apache.commons.lang3.AnnotationUtilsTest$TestMethodAnnotation("));
+ assertTrue(annotationString.endsWith(")"));
+ assertTrue(annotationString.contains("expected=class org.apache.commons.lang3.AnnotationUtilsTest$TestMethodAnnotation$None"));
+ assertTrue(annotationString.contains("timeout=666000"));
+ assertTrue(annotationString.contains(", "));
+ });
}
}
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
index a20379c..ead1183 100644
--- a/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
@@ -17,14 +17,14 @@
package org.apache.commons.lang3;
import org.apache.commons.lang3.arch.Processor;
-import org.junit.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 org.junit.jupiter.api.Test;
+
+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}.
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java
index a058427..ce7ed2c 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java
@@ -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.
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/src/test/java/org/apache/commons/lang3/ArrayUtilsInsertTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsInsertTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsInsertTest.java
index 2a0a23f..a3bfbf4 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsInsertTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsInsertTest.java
@@ -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.
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java
index 9e596d4..74e7e3c 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java
@@ -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
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e99b0dde/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java
index 95ea490..9bb46c1 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java
@@ -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.