From 25ed61f9638115bb35689bde4713a5845eaddcc1 Mon Sep 17 00:00:00 2001 From: Martin Mladenov Date: Sun, 11 Jun 2023 16:53:49 +0200 Subject: [PATCH 1/5] Add MethodCalledInProvideMethod --- .../checks/MethodCalledInProvideMethod.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalledInProvideMethod.java diff --git a/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalledInProvideMethod.java b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalledInProvideMethod.java new file mode 100644 index 00000000..3425b776 --- /dev/null +++ b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalledInProvideMethod.java @@ -0,0 +1,15 @@ +package nl.tudelft.cse1110.andy.codechecker.checks; + +import java.util.Set; + +public class MethodCalledInProvideMethod extends MethodCalledInTestMethod { + + public MethodCalledInProvideMethod(String methodToBeCalled) { + super(methodToBeCalled); + } + + @Override + protected Set annotations() { + return Set.of("Provide"); + } +} From c26eeadf25c6573886acfd335e5ce644c8d686a6 Mon Sep 17 00:00:00 2001 From: Martin Mladenov Date: Sun, 11 Jun 2023 16:56:48 +0200 Subject: [PATCH 2/5] Add AnnotatedMethod --- .../codechecker/checks/AnnotatedMethod.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/AnnotatedMethod.java diff --git a/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/AnnotatedMethod.java b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/AnnotatedMethod.java new file mode 100644 index 00000000..6682795a --- /dev/null +++ b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/AnnotatedMethod.java @@ -0,0 +1,44 @@ +package nl.tudelft.cse1110.andy.codechecker.checks; + +import org.eclipse.jdt.core.dom.MarkerAnnotation; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.NormalAnnotation; +import org.eclipse.jdt.core.dom.SingleMemberAnnotation; + +public class AnnotatedMethod extends Check { + + private boolean annotationIdentified = false; + private String annotation; + + public AnnotatedMethod(String annotation) { + this.annotation = annotation; + } + + @Override + public boolean visit(MarkerAnnotation node) { + checkIfThisIsTheAnnotation(node.getTypeName()); + return true; + } + + @Override + public boolean visit(NormalAnnotation node) { + checkIfThisIsTheAnnotation(node.getTypeName()); + return true; + } + + @Override + public boolean visit(SingleMemberAnnotation node) { + checkIfThisIsTheAnnotation(node.getTypeName()); + return true; + } + + private void checkIfThisIsTheAnnotation(Name name) { + if (name.getFullyQualifiedName().equals(annotation)) + annotationIdentified = true; + } + + @Override + public boolean result() { + return annotationIdentified; + } +} From 54156d9e92135897be3fb656384399dd563e2dac Mon Sep 17 00:00:00 2001 From: Martin Mladenov Date: Sun, 11 Jun 2023 17:17:16 +0200 Subject: [PATCH 3/5] Add MethodCalled --- .../andy/codechecker/checks/MethodCalled.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalled.java diff --git a/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalled.java b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalled.java new file mode 100644 index 00000000..7a3bf4dc --- /dev/null +++ b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/MethodCalled.java @@ -0,0 +1,12 @@ +package nl.tudelft.cse1110.andy.codechecker.checks; + +public class MethodCalled extends MethodCalledInTestMethod { + public MethodCalled(String methodToBeCalled) { + super(methodToBeCalled); + } + + @Override + protected boolean isInTheAnnotatedMethod(){ + return true; + } +} From 5284b6a7b2a66706915753d0375693a3977d1429 Mon Sep 17 00:00:00 2001 From: Martin Mladenov Date: Sun, 11 Jun 2023 17:25:47 +0200 Subject: [PATCH 4/5] Add Example annotation to the list of annotations identifying test methods --- .../cse1110/andy/codechecker/checks/WithinTestMethod.java | 1 + 1 file changed, 1 insertion(+) diff --git a/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/WithinTestMethod.java b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/WithinTestMethod.java index 5a48d4d9..8149307e 100644 --- a/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/WithinTestMethod.java +++ b/andy/src/main/java/nl/tudelft/cse1110/andy/codechecker/checks/WithinTestMethod.java @@ -10,6 +10,7 @@ public abstract class WithinTestMethod extends WithinAnnotatedMethod { add("Test"); // junit add("ParameterizedTest"); // junit add("Property"); // jqwik + add("Example"); // jqwik }}; protected Set annotations() { From 101f5ab81f2c07e17a7a77f00af640199e7d65c8 Mon Sep 17 00:00:00 2001 From: Martin Mladenov Date: Sun, 11 Jun 2023 17:27:12 +0200 Subject: [PATCH 5/5] Extend code check documentation --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index edbc321c..45571d23 100644 --- a/README.md +++ b/README.md @@ -298,8 +298,11 @@ Andy provides different checks for JUnit, Mockito, and JQWik tests: - `NumberOfTests`: checks whether the test suite has a minimum number of tests. - `TestMethodsHaveAssertions`: checks whether all test methods have assertions. - `LoopInTestMethods`: checks whether there is a loop in a test method. - - `UseOfStringLiterals`: checks whether there is a string literal in a test method. - - `MethodCalledInTestMethod`: checks whether a method was invoked in a test method. + - `UseOfStringLiterals`: checks whether there is a string of at least a specified length in a test method. + - `AnnotatedMethod`: checks whether a method with a specified annotation exists. + - `MethodCalled`: checks whether a method was invoked anywhere in the test code. + - `MethodCalledInTestMethod`: checks whether a method was invoked in a test method (annotated with `@Test`, `@ParameterizedTest`, `@Property`, or `@Example`). + - `MethodCalledInProvideMethod`: checks whether a method was invoked in a method with the `@Provide` annotation. - Mockito: - `MockClass`: Checks whether a class was mocked in the test suite.