mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-08 11:05:09 +00:00
verify that a user-generated annotation which does not directly implement equals() nevertheless compares equivalently to a 'real' annotation
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@996701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
83efbc505b
commit
da9ebdf72a
@ -26,6 +26,9 @@
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -36,337 +39,127 @@
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class AnnotationUtilsTest {
|
public class AnnotationUtilsTest {
|
||||||
@TestAnnotation(
|
@TestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, nest = @NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValue = false,
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object.class, types = { Object.class }), nests = { @NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValues = { false },
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object[].class, types = { Object[].class }) }, shortValue = 0, shortValues = { 0 }, stooge = SHEMP, stooges = {
|
||||||
byteValue = 0,
|
MOE, LARRY, CURLY }, string = "", strings = { "" }, type = Object.class, types = { Object.class })
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
nest = @NestAnnotation(
|
|
||||||
booleanValue = false,
|
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object.class,
|
|
||||||
types = { Object.class }
|
|
||||||
),
|
|
||||||
nests = {
|
|
||||||
@NestAnnotation(
|
|
||||||
booleanValue = false,
|
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object[].class,
|
|
||||||
types = { Object[].class }
|
|
||||||
)
|
|
||||||
},
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = SHEMP,
|
|
||||||
stooges = { MOE, LARRY, CURLY },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object.class,
|
|
||||||
types = { Object.class }
|
|
||||||
)
|
|
||||||
public Object dummy1;
|
public Object dummy1;
|
||||||
|
|
||||||
@TestAnnotation(
|
@TestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, nest = @NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValue = false,
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object.class, types = { Object.class }), nests = { @NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValues = { false },
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object[].class, types = { Object[].class }) }, shortValue = 0, shortValues = { 0 }, stooge = SHEMP, stooges = {
|
||||||
byteValue = 0,
|
MOE, LARRY, CURLY }, string = "", strings = { "" }, type = Object.class, types = { Object.class })
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
nest = @NestAnnotation(
|
|
||||||
booleanValue = false,
|
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object.class,
|
|
||||||
types = { Object.class }
|
|
||||||
),
|
|
||||||
nests = {
|
|
||||||
@NestAnnotation(
|
|
||||||
booleanValue = false,
|
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object[].class,
|
|
||||||
types = { Object[].class }
|
|
||||||
)
|
|
||||||
},
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = SHEMP,
|
|
||||||
stooges = { MOE, LARRY, CURLY },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object.class,
|
|
||||||
types = { Object.class }
|
|
||||||
)
|
|
||||||
public Object dummy2;
|
public Object dummy2;
|
||||||
|
|
||||||
@TestAnnotation(
|
@TestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, nest = @NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValue = false,
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object.class, types = { Object.class }), nests = {
|
||||||
booleanValues = { false },
|
@NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
byteValue = 0,
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object[].class, types = { Object[].class }),
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
nest = @NestAnnotation(
|
|
||||||
booleanValue = false,
|
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object.class,
|
|
||||||
types = { Object.class }
|
|
||||||
),
|
|
||||||
nests = {
|
|
||||||
@NestAnnotation(
|
|
||||||
booleanValue = false,
|
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object[].class,
|
|
||||||
types = { Object[].class }
|
|
||||||
),
|
|
||||||
//add a second NestAnnotation to break equality:
|
//add a second NestAnnotation to break equality:
|
||||||
@NestAnnotation(
|
@NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValue = false,
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object[].class, types = { Object[].class }) }, shortValue = 0, shortValues = { 0 }, stooge = SHEMP, stooges = {
|
||||||
booleanValues = { false },
|
MOE, LARRY, CURLY }, string = "", strings = { "" }, type = Object.class, types = { Object.class })
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object[].class,
|
|
||||||
types = { Object[].class }
|
|
||||||
)
|
|
||||||
},
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = SHEMP,
|
|
||||||
stooges = { MOE, LARRY, CURLY },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object.class,
|
|
||||||
types = { Object.class }
|
|
||||||
)
|
|
||||||
public Object dummy3;
|
public Object dummy3;
|
||||||
|
|
||||||
@NestAnnotation(
|
@NestAnnotation(booleanValue = false, booleanValues = { false }, byteValue = 0, byteValues = { 0 }, charValue = 0, charValues = { 0 }, doubleValue = 0, doubleValues = { 0 }, floatValue = 0, floatValues = { 0 }, intValue = 0, intValues = { 0 }, longValue = 0, longValues = { 0 }, shortValue = 0, shortValues = { 0 }, stooge = CURLY, stooges = {
|
||||||
booleanValue = false,
|
MOE, LARRY, SHEMP }, string = "", strings = { "" }, type = Object[].class, types = { Object[].class })
|
||||||
booleanValues = { false },
|
|
||||||
byteValue = 0,
|
|
||||||
byteValues = { 0 },
|
|
||||||
charValue = 0,
|
|
||||||
charValues = { 0 },
|
|
||||||
doubleValue = 0,
|
|
||||||
doubleValues = { 0 },
|
|
||||||
floatValue = 0,
|
|
||||||
floatValues = { 0 },
|
|
||||||
intValue = 0,
|
|
||||||
intValues = { 0 },
|
|
||||||
longValue = 0,
|
|
||||||
longValues = { 0 },
|
|
||||||
shortValue = 0,
|
|
||||||
shortValues = { 0 },
|
|
||||||
stooge = CURLY,
|
|
||||||
stooges = { MOE, LARRY, SHEMP },
|
|
||||||
string = "",
|
|
||||||
strings = { "" },
|
|
||||||
type = Object[].class,
|
|
||||||
types = { Object[].class }
|
|
||||||
)
|
|
||||||
|
|
||||||
public Object dummy4;
|
public Object dummy4;
|
||||||
|
|
||||||
@Target(FIELD)
|
@Target(FIELD)
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface TestAnnotation {
|
public @interface TestAnnotation {
|
||||||
String string();
|
String string();
|
||||||
|
|
||||||
String[] strings();
|
String[] strings();
|
||||||
|
|
||||||
Class<?> type();
|
Class<?> type();
|
||||||
|
|
||||||
Class<?>[] types();
|
Class<?>[] types();
|
||||||
|
|
||||||
byte byteValue();
|
byte byteValue();
|
||||||
|
|
||||||
byte[] byteValues();
|
byte[] byteValues();
|
||||||
|
|
||||||
short shortValue();
|
short shortValue();
|
||||||
|
|
||||||
short[] shortValues();
|
short[] shortValues();
|
||||||
|
|
||||||
int intValue();
|
int intValue();
|
||||||
|
|
||||||
int[] intValues();
|
int[] intValues();
|
||||||
|
|
||||||
char charValue();
|
char charValue();
|
||||||
|
|
||||||
char[] charValues();
|
char[] charValues();
|
||||||
|
|
||||||
long longValue();
|
long longValue();
|
||||||
|
|
||||||
long[] longValues();
|
long[] longValues();
|
||||||
|
|
||||||
float floatValue();
|
float floatValue();
|
||||||
|
|
||||||
float[] floatValues();
|
float[] floatValues();
|
||||||
|
|
||||||
double doubleValue();
|
double doubleValue();
|
||||||
|
|
||||||
double[] doubleValues();
|
double[] doubleValues();
|
||||||
|
|
||||||
boolean booleanValue();
|
boolean booleanValue();
|
||||||
|
|
||||||
boolean[] booleanValues();
|
boolean[] booleanValues();
|
||||||
|
|
||||||
Stooge stooge();
|
Stooge stooge();
|
||||||
|
|
||||||
Stooge[] stooges();
|
Stooge[] stooges();
|
||||||
|
|
||||||
NestAnnotation nest();
|
NestAnnotation nest();
|
||||||
|
|
||||||
NestAnnotation[] nests();
|
NestAnnotation[] nests();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @interface NestAnnotation {
|
public @interface NestAnnotation {
|
||||||
String string();
|
String string();
|
||||||
|
|
||||||
String[] strings();
|
String[] strings();
|
||||||
|
|
||||||
Class<?> type();
|
Class<?> type();
|
||||||
|
|
||||||
Class<?>[] types();
|
Class<?>[] types();
|
||||||
|
|
||||||
byte byteValue();
|
byte byteValue();
|
||||||
|
|
||||||
byte[] byteValues();
|
byte[] byteValues();
|
||||||
|
|
||||||
short shortValue();
|
short shortValue();
|
||||||
|
|
||||||
short[] shortValues();
|
short[] shortValues();
|
||||||
|
|
||||||
int intValue();
|
int intValue();
|
||||||
|
|
||||||
int[] intValues();
|
int[] intValues();
|
||||||
|
|
||||||
char charValue();
|
char charValue();
|
||||||
|
|
||||||
char[] charValues();
|
char[] charValues();
|
||||||
|
|
||||||
long longValue();
|
long longValue();
|
||||||
|
|
||||||
long[] longValues();
|
long[] longValues();
|
||||||
|
|
||||||
float floatValue();
|
float floatValue();
|
||||||
|
|
||||||
float[] floatValues();
|
float[] floatValues();
|
||||||
|
|
||||||
double doubleValue();
|
double doubleValue();
|
||||||
|
|
||||||
double[] doubleValues();
|
double[] doubleValues();
|
||||||
|
|
||||||
boolean booleanValue();
|
boolean booleanValue();
|
||||||
|
|
||||||
boolean[] booleanValues();
|
boolean[] booleanValues();
|
||||||
|
|
||||||
Stooge stooge();
|
Stooge stooge();
|
||||||
|
|
||||||
Stooge[] stooges();
|
Stooge[] stooges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,22 +182,26 @@ public void setup() throws Exception {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquivalence() {
|
public void testEquivalence() {
|
||||||
assertTrue(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field2.getAnnotation(TestAnnotation.class)));
|
assertTrue(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field2
|
||||||
|
.getAnnotation(TestAnnotation.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSameInstance() {
|
public void testSameInstance() {
|
||||||
assertTrue(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field1.getAnnotation(TestAnnotation.class)));
|
assertTrue(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field1
|
||||||
|
.getAnnotation(TestAnnotation.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonEquivalentAnnotationsOfSameType() {
|
public void testNonEquivalentAnnotationsOfSameType() {
|
||||||
assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field3.getAnnotation(TestAnnotation.class)));
|
assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field3
|
||||||
|
.getAnnotation(TestAnnotation.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnnotationsOfDifferingTypes() {
|
public void testAnnotationsOfDifferingTypes() {
|
||||||
assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field4.getAnnotation(NestAnnotation.class)));
|
assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field4
|
||||||
|
.getAnnotation(NestAnnotation.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -427,4 +224,42 @@ public void testIsValidAnnotationMemberType() {
|
|||||||
.getClass()));
|
.getClass()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 666)
|
||||||
|
public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
|
||||||
|
final Test real = getClass().getDeclaredMethod(
|
||||||
|
"testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
|
||||||
|
|
||||||
|
InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
|
||||||
|
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
|
||||||
|
return proxy == args[0];
|
||||||
|
}
|
||||||
|
if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
|
||||||
|
return System.identityHashCode(proxy);
|
||||||
|
}
|
||||||
|
if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
|
||||||
|
return "Test proxy";
|
||||||
|
}
|
||||||
|
return method.invoke(real, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user