add Checks system #6

Merged
tueem merged 16 commits from feat/checks into dev 2024-12-05 07:51:37 +00:00
4 changed files with 6 additions and 7 deletions
Showing only changes of commit c363ab9744 - Show all commits

View File

@ -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())
.filter(x -> x.getName().equals("postExec"))
.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.setAccessible(true);
try {
return (boolean) method.invoke(check, context, annotation);
method.invoke(check, context, annotation);
} catch (IllegalAccessException | InvocationTargetException | SecurityException e) {
e.printStackTrace();
return false;
}
}

View File

@ -5,6 +5,6 @@ import java.lang.annotation.Annotation;
public interface InteractionCheck<A extends Annotation> {
public boolean preExec(Object context, A annotation);
public boolean postExec(Object context, A annotation);
public void postExec(Object context, A annotation);
}

View File

@ -60,7 +60,8 @@ public abstract class InteractionMethod {
public abstract InteractionType getType();
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);
try {

View File

@ -28,11 +28,10 @@ public class TestInteractionCheck implements InteractionCheck<TestInteractionChe
}
@Override
public boolean postExec(Object context, TestCheck annotation) {
public void postExec(Object context, TestCheck annotation) {
assertNotNull(annotation);
assertNotNull(context);
postExecuted = true;
return true;
}
}