// 1
String name = "equals";
InvocationConstraint ic = Delegation.YES;
InvocationConstraints constraints = new InvocationConstraints(
ic, null);
MethodDesc methodDesc = new MethodDesc(name, constraints);
MethodDesc [] descs = {methodDesc};
BasicMethodConstraints bmc = new BasicMethodConstraints(descs);
Method mEquals = Object.class.getDeclaredMethod(name,
new Class[] { Object.class });
InvocationConstraints returnedConstraints =
bmc.getConstraints(mEquals);
if (!constraints.equals(returnedConstraints)) {
throw new TestException(
"Invalid constraints was returned");
}
// 2
String name1 = "hashCode";
Method mHashCode = Object.class.getDeclaredMethod(name1,
new Class[] {});
returnedConstraints = bmc.getConstraints(mHashCode);
InvocationConstraints emptyConstraints = new InvocationConstraints(
(InvocationConstraint) null, null);
if (!emptyConstraints.equals(returnedConstraints)) {
throw new TestException(
"Empty constraints should be returned");
}
// 3
String name2 = "*ashCode";
InvocationConstraint ic2 = Delegation.NO;
InvocationConstraints constraints2 = new InvocationConstraints(
ic2, null);
MethodDesc methodDesc2 = new MethodDesc(name2, constraints2);
String name3 = "*shCode";
InvocationConstraint ic3 = Integrity.NO;
InvocationConstraints constraints3 = new InvocationConstraints(
ic3, null);
MethodDesc methodDesc3 = new MethodDesc(name3, constraints3);
MethodDesc [] descs3 = {methodDesc, methodDesc2, methodDesc3};
bmc = new BasicMethodConstraints(descs3);
returnedConstraints = bmc.getConstraints(mHashCode);
if (!returnedConstraints.equals(constraints2)) {
throw new TestException(
"Invalid constraints was returned:"
+ returnedConstraints
+ ", should be:" + constraints2);
}
// 4
MethodDesc methodDesc1 = new MethodDesc(name,
new Class[] {}, constraints2);
methodDesc2 = new MethodDesc(name,
new Class[] { Object.class, Class.class }, constraints2);
methodDesc3 = new MethodDesc(name,
new Class[] { Object.class }, constraints3);
MethodDesc [] descs4 = {methodDesc1, methodDesc2, methodDesc3};
bmc = new BasicMethodConstraints(descs4);
returnedConstraints = bmc.getConstraints(mEquals);
if (!returnedConstraints.equals(constraints3)) {