-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate
BooleanIdentifierCheck
to new test format
- Loading branch information
Showing
4 changed files
with
95 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...re/src/test/java/de/firemage/autograder/core/check/naming/TestBooleanIdentifierCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
...t/resources/de/firemage/autograder/core/check_tests/BooleanIdentifierCheck/code/Test.java
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
.../test/resources/de/firemage/autograder/core/check_tests/BooleanIdentifierCheck/config.txt
This file was deleted.
Oops, something went wrong.