Abstract generic superclass for tests of Rule classes
Modifiers | Name | Description |
---|---|---|
protected static java.lang.Object |
CONSTRUCTOR_METHOD_NAME |
|
protected static java.lang.Object |
DEFAULT_TEST_CLASS_NAMES |
|
protected static java.lang.Object |
DEFAULT_TEST_FILES |
|
protected T |
rule |
|
protected java.lang.String |
sourceCodeName |
|
protected java.lang.String |
sourceCodePath |
Fields inherited from class | Fields |
---|---|
class AbstractTestCase |
CODENARC_PROPERTIES_FILE_PROP, LOG, testName |
Type Params | Return Type | Name and description |
---|---|---|
|
protected java.util.List |
applyRuleTo(java.lang.String source) Apply the current Rule to the specified source (String) and return the resulting List of Violations. |
|
protected void |
assertInlineViolations(java.lang.String annotatedSource) Apply the current Rule to the specified source (String) and assert that it results in the violations specified inline within the source. |
|
protected void |
assertNoViolations(java.lang.String source) Apply the current Rule to the specified source (String) and assert that it results in no violations. |
|
protected void |
assertSingleViolation(java.lang.String source, java.lang.Integer lineNumber = null, java.lang.String sourceLineText = null, java.lang.Object messageText = null) Apply the current Rule to the specified source (String) and assert that it results in a single violation with the specified line number and containing the specified source text. |
|
protected void |
assertSingleViolation(java.lang.String source, groovy.lang.Closure closure) Apply the current Rule to the specified source (String) and assert that it results in a single violation and that the specified closure returns true. |
|
protected void |
assertTwoViolations(java.lang.String source, java.lang.Integer lineNumber1, java.lang.String sourceLineText1, java.lang.Integer lineNumber2, java.lang.String sourceLineText2) Apply the current Rule to the specified source (String) and assert that it results in two violations with the specified line numbers and containing the specified source text values. |
|
protected void |
assertTwoViolations(java.lang.String source, java.lang.Integer lineNumber1, java.lang.String sourceLineText1, java.lang.Object msg1, java.lang.Integer lineNumber2, java.lang.String sourceLineText2, java.lang.Object msg2) Apply the current Rule to the specified source (String) and assert that it results in two violations with the specified line numbers and containing the specified source text values. |
|
protected void |
assertViolation(Violation violation, java.lang.Integer lineNumber, java.lang.String sourceLineText, java.lang.Object messageText = null) Assert that the specified violation is for the current rule, and has expected line number and contains the specified source text and message text. |
|
protected void |
assertViolations(java.lang.String source, java.util.Map[] violationMaps) Apply the current Rule to the specified source (String) and assert that it results in the violations specified in violationMaps. |
|
protected T |
createRule() Create and return a new instance of the Rule class to be tested. |
|
protected static java.lang.String |
inlineViolation(java.lang.String violationMessage) Prepares an inline violation with a given message, escaping all '#' characters and preventing accidental escaping of next inline violation's start when the message ends with a '\' character. |
|
protected java.util.List |
manuallyApplyRule(java.lang.String source) Apply the current Rule to the specified source (String) and return the resulting List of Violations. |
|
protected static java.lang.String |
removeInlineViolations(java.lang.String annotatedSource) Removes all inline violations from a source. |
|
void |
setUpAbstractRuleTestCase() |
|
void |
testThatApplyToFilesMatchingValuesAreValidRegex() |
|
void |
testThatInvalidCodeHasNoViolations() |
|
void |
testThatUnrelatedCodeHasNoViolations() Make sure that code unrelated to the rule under test causes no violations. |
Methods inherited from class | Name |
---|---|
class AbstractTestCase |
getName, log, setUpAbstractTestCase |
Apply the current Rule to the specified source (String) and return the resulting List of Violations.
source
- - the full source code to which the rule is applied, as a StringApply the current Rule to the specified source (String) and assert that it results in the violations specified inline within the source.
Inline violations can be specified either by using the inlineViolation(java.lang.String) method or simply by prefixing a violation message with a '#'. Multiple inline violations per line are allowed.
One can prevent a '#' character from starting a violation message by escaping it with a '\' character (keep in mind that most of Groovy's string literal syntax demands the '\' to be escaped itself, as a '\\' sequence).
For every source line all text after the first non-escaped '#' character is part of some inline violation message (with the sole exception of the first line of a Groovy script beginning with a shebang). More precisely, every '#' character that is neither escaped nor part of a shebang starts an inline violation that spans to the end of its line or until next non-escaped '#' character.
See the inlineViolation(java.lang.String) method.
See the removeInlineViolations(java.lang.String) method.
source
- - the full source code to which the rule is applied annotated with inline violations, as a StringApply the current Rule to the specified source (String) and assert that it results in no violations.
source
- - the full source code to which the rule is applied, as a StringApply the current Rule to the specified source (String) and assert that it results in a single violation with the specified line number and containing the specified source text.
source
- - the full source code to which the rule is applied, as a StringlineNumber
- - the expected line number in the resulting violation; defaults to nullsourceLineText
- - the text expected within the sourceLine of the resulting violation; defaults to nullmessageText
- - the text expected within the message of the resulting violation; May be a String or List of Strings; Defaults to null;Apply the current Rule to the specified source (String) and assert that it results in a single violation and that the specified closure returns true.
source
- - the full source code to which the rule is applied, as a String; defaults to nullclosure
- - the closure to apply to the violation; takes a single Violation parameterApply the current Rule to the specified source (String) and assert that it results in two violations with the specified line numbers and containing the specified source text values.
source
- - the full source code to which the rule is applied, as a StringlineNumber1
- - the expected line number in the first violationsourceLineText1
- - the text expected within the sourceLine of the first violationlineNumber2
- - the expected line number in the second violationsourceLineText2
- - the text expected within the sourceLine of the second violationApply the current Rule to the specified source (String) and assert that it results in two violations with the specified line numbers and containing the specified source text values.
source
- - the full source code to which the rule is applied, as a StringlineNumber1
- - the expected line number in the first violationsourceLineText1
- - the text expected within the sourceLine of the first violationmsg1
- - the text expected within the message of the first violation; May be a String or List of Strings; Defaults to null;lineNumber2
- - the expected line number in the second violationsourceLineText2
- - the text expected within the sourceLine of the second violationmsg2
- - the text expected within the message of the second violation; May be a String or List of Strings; Defaults to null;Assert that the specified violation is for the current rule, and has expected line number and contains the specified source text and message text.
violation
- - the ViolationlineNumber
- - the expected line number in the resulting violationsourceLineText
- - the text expected within the sourceLine of the resulting violation; may be nullmessageText
- - the text expected within the message of the resulting violation; May be a String or List of Strings; Defaults to null;Apply the current Rule to the specified source (String) and assert that it results in the violations specified in violationMaps.
source
- - the full source code to which the rule is applied, as a StringviolationMaps
- - a list (array) of Maps, each describing a single violation.
Each element in the map can contain a line/lineNumber, source/sourceLineText and message/messageText entries.Create and return a new instance of the Rule class to be tested.
Prepares an inline violation with a given message, escaping all '#' characters and preventing accidental escaping of next inline violation's start when the message ends with a '\' character.
violationMessage
- message for the inline violationApply the current Rule to the specified source (String) and return the resulting List of Violations.
source
- - the full source code to which the rule is applied, as a StringRemoves all inline violations from a source.
annotatedSource
- source possibly containing inline violationsMake sure that code unrelated to the rule under test causes no violations. Subclasses can skip this rule by defining a property named 'skipTestThatUnrelatedCodeHasNoViolations'.