Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more code checks #211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> annotations() {
return Set.of("Provide");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public abstract class WithinTestMethod extends WithinAnnotatedMethod {
add("Test"); // junit
add("ParameterizedTest"); // junit
add("Property"); // jqwik
add("Example"); // jqwik
}};

protected Set<String> annotations() {
Expand Down