add ability to return false to cancel execution in pre Checks and remove return type on post checks
This commit is contained in:
parent
33392b02fb
commit
c363ab9744
@ -24,7 +24,7 @@ public record AppliedCheck(InteractionCheck<?> check, Annotation annotation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean post(Object context) {
|
public void post(Object context) {
|
||||||
Method[] methods = Arrays.stream(check.getClass().getMethods())
|
Method[] methods = Arrays.stream(check.getClass().getMethods())
|
||||||
.filter(x -> x.getName().equals("postExec"))
|
.filter(x -> x.getName().equals("postExec"))
|
||||||
.filter(x -> !x.isBridge())
|
.filter(x -> !x.isBridge())
|
||||||
@ -32,10 +32,9 @@ public record AppliedCheck(InteractionCheck<?> check, Annotation annotation) {
|
|||||||
Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.getClass());
|
Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.getClass());
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
return (boolean) method.invoke(check, context, annotation);
|
method.invoke(check, context, annotation);
|
||||||
} catch (IllegalAccessException | InvocationTargetException | SecurityException e) {
|
} catch (IllegalAccessException | InvocationTargetException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,6 @@ import java.lang.annotation.Annotation;
|
|||||||
public interface InteractionCheck<A extends Annotation> {
|
public interface InteractionCheck<A extends Annotation> {
|
||||||
|
|
||||||
public boolean preExec(Object context, A annotation);
|
public boolean preExec(Object context, A annotation);
|
||||||
public boolean postExec(Object context, A annotation);
|
public void postExec(Object context, A annotation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,8 @@ public abstract class InteractionMethod {
|
|||||||
public abstract InteractionType getType();
|
public abstract InteractionType getType();
|
||||||
|
|
||||||
public void run(Object context) {
|
public void run(Object context) {
|
||||||
this.appliedChecks.forEach(x -> x.pre(context));
|
if (this.appliedChecks.stream().filter(x -> !x.pre(context)).count() > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
|
@ -28,11 +28,10 @@ public class TestInteractionCheck implements InteractionCheck<TestInteractionChe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean postExec(Object context, TestCheck annotation) {
|
public void postExec(Object context, TestCheck annotation) {
|
||||||
assertNotNull(annotation);
|
assertNotNull(annotation);
|
||||||
assertNotNull(context);
|
assertNotNull(context);
|
||||||
postExecuted = true;
|
postExecuted = true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user