Package org.sonar.java.testing
Class InternalCheckVerifier
- java.lang.Object
-
- org.sonar.java.testing.InternalCheckVerifier
-
- All Implemented Interfaces:
CheckVerifier
public class InternalCheckVerifier extends Object implements CheckVerifier
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static InternalCheckVerifier
newInstance()
InternalCheckVerifier
onFile(String filename)
Defines the filename to be verified with the given rule(s).InternalCheckVerifier
onFiles(String... filenames)
Defines the filenames to be verified with the given rule(s).InternalCheckVerifier
onFiles(Collection<String> filenames)
Defines a collection of filenames to be verified with the given rule(s).void
verifyIssueOnFile(String expectedIssueMessage)
Verifies that an issue (only one) is raised directly on the file, and not within the content of the file.void
verifyIssueOnProject(String expectedIssueMessage)
Verifies that an issue (only one) is raised directly on the project which would include this file, and not within the content of the file.void
verifyIssues()
Verifies that all the expected issues are correctly raised by the rule(s), at their expected positions and attributes.void
verifyNoIssues()
Verifies that no issues are raised by the rule(s) on the given file(s).InternalCheckVerifier
withCheck(JavaFileScanner check)
Defines the check to be verified against at least one test file.CheckVerifier
withChecks(JavaFileScanner... checks)
Defines the check(s) to be verified against at least one test file.InternalCheckVerifier
withClassPath(Collection<File> classpath)
Defines the classpath to be used for the verification.InternalCheckVerifier
withCustomIssueVerifier(Consumer<Set<AnalyzerMessage>> customIssueVerifier)
InternalCheckVerifier
withJavaVersion(int javaVersionAsInt)
Defines the java version syntax to be used for the verification.InternalCheckVerifier
withoutSemantic()
Tells the verifier that no bytecode will be provided.
-
-
-
Method Detail
-
newInstance
public static InternalCheckVerifier newInstance()
-
withCheck
public InternalCheckVerifier withCheck(JavaFileScanner check)
Description copied from interface:CheckVerifier
Defines the check to be verified against at least one test file.- Specified by:
withCheck
in interfaceCheckVerifier
- Parameters:
check
- the rule to be verified- Returns:
- the verifier configured to use the check provided as argument
-
withChecks
public CheckVerifier withChecks(JavaFileScanner... checks)
Description copied from interface:CheckVerifier
Defines the check(s) to be verified against at least one test file.- Specified by:
withChecks
in interfaceCheckVerifier
- Parameters:
checks
- the rules to be verified- Returns:
- the verifier configured to use the checks provided as argument
-
withClassPath
public InternalCheckVerifier withClassPath(Collection<File> classpath)
Description copied from interface:CheckVerifier
Defines the classpath to be used for the verification. Usually used when the code of the test files requires the knowledge of a particular set of libraries or java compiled classes.- Specified by:
withClassPath
in interfaceCheckVerifier
- Parameters:
classpath
- a collection of file which defines the classes/jars/zips which contains the bytecode to be used as classpath when executing the rule- Returns:
- the verifier configured to use the files provided as argument as classpath
-
withCustomIssueVerifier
@Beta public InternalCheckVerifier withCustomIssueVerifier(Consumer<Set<AnalyzerMessage>> customIssueVerifier)
-
withJavaVersion
public InternalCheckVerifier withJavaVersion(int javaVersionAsInt)
Description copied from interface:CheckVerifier
Defines the java version syntax to be used for the verification. Usually used when the code of the test files target explicitly a given version (eg. java 7), where a particular syntax/API has been introduced.- Specified by:
withJavaVersion
in interfaceCheckVerifier
- Parameters:
javaVersionAsInt
- defines the java language syntax version to be considered during verification, provided as an integer. For instance, for Java 1.7, use '7'. For Java 12, simply '12'.- Returns:
- the verifier configured to consider the provided test file(s) as following the syntax of the given java version
-
onFile
public InternalCheckVerifier onFile(String filename)
Description copied from interface:CheckVerifier
Defines the filename to be verified with the given rule(s). This file should contain all the "Noncompliant" comments defining the expected issues.- Specified by:
onFile
in interfaceCheckVerifier
- Parameters:
filename
- the file to be analyzed- Returns:
- the verifier configured to consider the provided test file as source for the rule(s)
-
onFiles
public InternalCheckVerifier onFiles(String... filenames)
Description copied from interface:CheckVerifier
Defines the filenames to be verified with the given rule(s). These files should all contain "Noncompliant" comments defining the expected issues.- Specified by:
onFiles
in interfaceCheckVerifier
- Parameters:
filenames
- the files to be analyzed- Returns:
- the verifier configured to consider the provided test file(s) as source for the rule(s)
-
onFiles
public InternalCheckVerifier onFiles(Collection<String> filenames)
Description copied from interface:CheckVerifier
Defines a collection of filenames to be verified with the given rule(s). These files should all contain "Noncompliant" comments defining the expected issues.- Specified by:
onFiles
in interfaceCheckVerifier
- Parameters:
filenames
- a collection of files to be analyzed- Returns:
- the verifier configured to consider the provided test file(s) as source for the rule(s)
-
withoutSemantic
public InternalCheckVerifier withoutSemantic()
Description copied from interface:CheckVerifier
Tells the verifier that no bytecode will be provided. This method is usually used in combination withCheckVerifier.verifyNoIssues()
, to assert the fact that if no bytecode is provided, the rule will not raise any issues.- Specified by:
withoutSemantic
in interfaceCheckVerifier
- Returns:
- the verifier configured to consider that no bytecode will be provided for analysis
-
verifyIssues
public void verifyIssues()
Description copied from interface:CheckVerifier
Verifies that all the expected issues are correctly raised by the rule(s), at their expected positions and attributes.- Specified by:
verifyIssues
in interfaceCheckVerifier
-
verifyIssueOnFile
public void verifyIssueOnFile(String expectedIssueMessage)
Description copied from interface:CheckVerifier
Verifies that an issue (only one) is raised directly on the file, and not within the content of the file.- Specified by:
verifyIssueOnFile
in interfaceCheckVerifier
- Parameters:
expectedIssueMessage
- the message to be expected with the issue.
-
verifyIssueOnProject
public void verifyIssueOnProject(String expectedIssueMessage)
Description copied from interface:CheckVerifier
Verifies that an issue (only one) is raised directly on the project which would include this file, and not within the content of the file.- Specified by:
verifyIssueOnProject
in interfaceCheckVerifier
-
verifyNoIssues
public void verifyNoIssues()
Description copied from interface:CheckVerifier
Verifies that no issues are raised by the rule(s) on the given file(s).- Specified by:
verifyNoIssues
in interfaceCheckVerifier
-
-