Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
134 changes: 78 additions & 56 deletions src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@
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;

/**
*/
Expand Down Expand Up @@ -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
}
Expand All @@ -386,7 +400,7 @@ public enum Stooge {
private Field field3;
private Field field4;

@Before
@BeforeEach
public void setup() throws Exception {
field1 = getClass().getDeclaredField("dummy1");
field2 = getClass().getDeclaredField("dummy2");
Expand Down Expand Up @@ -444,65 +458,73 @@ public void testIsValidAnnotationMemberType() {
}
}

@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(", "));
});
}

}
16 changes: 8 additions & 8 deletions src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/apache/commons/lang3/ArrayUtilsInsertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading