Skip to content

Commit

Permalink
migrate BooleanIdentifierCheck to new test format
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Sep 29, 2024
1 parent 7d165a4 commit 272124b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void process(CtMethod<?> ctMethod) {
return;
}

//
String methodName = ctMethod.getSimpleName();
if (ctMethod.getType().equals(ctMethod.getFactory().Type().booleanPrimitiveType())
&& methodName.startsWith("get")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package de.firemage.autograder.core.check.naming;

import de.firemage.autograder.api.JavaVersion;
import de.firemage.autograder.api.LinterException;
import de.firemage.autograder.core.LocalizedMessage;
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

class TestBooleanIdentifierCheck extends AbstractCheckTest {
private static final List<ProblemType> PROBLEM_TYPES = List.of(ProblemType.BOOLEAN_GETTER_NOT_CALLED_IS);

private void assertName(Problem problem, String methodName, String newName) {
assertEquals(
this.linter.translateMessage(
new LocalizedMessage(
"bool-getter-name",
Map.of(
"oldName", methodName,
"newName", newName
)
)),
this.linter.translateMessage(problem.getExplanation())
);
}

@Test
void testGetter() throws LinterException, IOException {
ProblemIterator problems = this.checkIterator(StringSourceInfo.fromSourceString(
JavaVersion.JAVA_17,
"Test",
"""
public class Test {
public boolean getValue() { /*# not ok #*/
return true;
}
}
"""
), PROBLEM_TYPES);

assertName(problems.next(), "getValue", "isValue");
problems.assertExhausted();
}

@Test
void testCorrectlyNamedGetter() throws LinterException, IOException {
ProblemIterator problems = this.checkIterator(StringSourceInfo.fromSourceString(
JavaVersion.JAVA_17,
"Test",
"""
public class Test {
public boolean hasValue() {
return true;
}
public boolean isValue() {
return true;
}
public boolean value() {
return true;
}
}
"""
), PROBLEM_TYPES);

problems.assertExhausted();
}

@Test
void testBooleanArray() throws LinterException, IOException {
ProblemIterator problems = this.checkIterator(StringSourceInfo.fromSourceString(
JavaVersion.JAVA_17,
"Test",
"""
public class Test {
public boolean[] getValue() {
return null;
}
}
"""
), PROBLEM_TYPES);

problems.assertExhausted();
}
}

This file was deleted.

This file was deleted.

0 comments on commit 272124b

Please sign in to comment.