|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.codenarc.test.AbstractTestCase
groovy.org.codenarc.rule.AbstractRuleTestCase
@SuppressWarnings('DuplicateLiteral')
abstract class AbstractRuleTestCase
extends AbstractTestCase
Abstract superclass for tests of Rule classes
| Field Summary | |
|---|---|
protected static def |
CONSTRUCTOR_METHOD_NAME
|
protected static def |
DEFAULT_TEST_CLASS_NAMES
|
protected static def |
DEFAULT_TEST_FILES
|
protected Rule |
rule
|
protected String |
sourceCodeName
|
protected String |
sourceCodePath
|
| Method Summary | |
|---|---|
protected List
|
applyRuleTo(String source)
Apply the current Rule to the specified source (String) and return the resulting List of Violations. |
protected void
|
assertInlineViolations(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(String source)
Apply the current Rule to the specified source (String) and assert that it results in no violations. |
protected void
|
assertSingleViolation(String source, Integer lineNumber = null, String sourceLineText = null, def 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(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(String source, Integer lineNumber1, String sourceLineText1, Integer lineNumber2, 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(String source, Integer lineNumber1, String sourceLineText1, def msg1, Integer lineNumber2, String sourceLineText2, def 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, Integer lineNumber, String sourceLineText, def 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(String source, Map[] violationMaps)
Apply the current Rule to the specified source (String) and assert that it results in the violations specified in violationMaps. |
protected Rule
|
createRule()
Create and return a new instance of the Rule class to be tested. |
protected static String
|
inlineViolation(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 List
|
manuallyApplyRule(String source)
Apply the current Rule to the specified source (String) and return the resulting List of Violations. |
protected static String
|
removeInlineViolations(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. |
| Field Detail |
|---|
protected static final def CONSTRUCTOR_METHOD_NAME
protected static final def DEFAULT_TEST_CLASS_NAMES
protected static final def DEFAULT_TEST_FILES
protected Rule rule
protected String sourceCodeName
protected String sourceCodePath
| Method Detail |
|---|
protected List applyRuleTo(String source)
source - - the full source code to which the rule is applied, as a String
protected void assertInlineViolations(String annotatedSource)
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 String
protected void assertNoViolations(String source)
source - - the full source code to which the rule is applied, as a String
protected void assertSingleViolation(String source, Integer lineNumber = null, String sourceLineText = null, def messageText = null)
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;
protected void assertSingleViolation(String source, groovy.lang.Closure closure)
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 parameter
protected void assertTwoViolations(String source, Integer lineNumber1, String sourceLineText1, Integer lineNumber2, String sourceLineText2)
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 violation
@SuppressWarnings('ParameterCount')
protected void assertTwoViolations(String source, Integer lineNumber1, String sourceLineText1, def msg1, Integer lineNumber2, String sourceLineText2, def msg2)
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;
protected void assertViolation(Violation violation, Integer lineNumber, String sourceLineText, def messageText = null)
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;
protected void assertViolations(String source, Map[] 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 lineNumber, sourceLineText and messageText entries.
protected Rule createRule()
protected static String inlineViolation(String violationMessage)
violationMessage - message for the inline violation
protected List manuallyApplyRule(String source)
source - - the full source code to which the rule is applied, as a String
protected static String removeInlineViolations(String annotatedSource)
annotatedSource - source possibly containing inline violations
@Before void setUpAbstractRuleTestCase()
@Test void testThatApplyToFilesMatchingValuesAreValidRegex()
@Test void testThatInvalidCodeHasNoViolations()
@Test void testThatUnrelatedCodeHasNoViolations()
Groovy Documentation