use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class FileTabCharacterCheckTest method testBadFile.
@Test
public void testBadFile() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(FileTabCharacterCheck.class);
checkConfig.addProperty("eachLine", "false");
final String path = getPath("Claira");
final String exceptionMessage = " (No such file or directory)";
final Violation violation = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, "general.exception", new String[] { path + exceptionMessage }, null, getClass(), null);
final String[] expected = { "1: " + violation.getViolation() };
verify(createChecker(checkConfig), path, expected);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideViolation.
@Test
public void testDecideViolation() {
final Violation violation = new Violation(1, 0, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
// deny because there are matches on file and check names
assertWithMessage("Names match").that(filter.accept(ev)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpMatch.
@Test
public void testDecideByFileNameAndModuleMatchingCheckRegExpMatch() {
final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
final SuppressFilterElement myFilter = new SuppressFilterElement("Test", getClass().getCanonicalName(), null, null, null, null);
assertWithMessage("Filter should not accept invalid event").that(myFilter.accept(ev)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingModuleNotEqual.
@Test
public void testDecideByFileNameAndModuleMatchingModuleNotEqual() {
final Violation message = new Violation(10, 10, "", "", null, "TheirModule", getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
final SuppressFilterElement myFilter = new SuppressFilterElement("Test", "Test", null, "MyModule", null, null);
assertWithMessage("Filter should accept valid event").that(myFilter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method getTagsAfterExecution.
/**
* Calls the filter with a minimal set of inputs and returns a list of
* {@link SuppressWithNearbyCommentFilter} internal type {@code Tag}.
* Our goal is 100% test coverage, for this we use white-box testing.
* So we need access to the implementation details. For this reason,
* it is necessary to use reflection to gain access to the inner field here.
*
* @return {@code Tag} list
*/
private static List<?> getTagsAfterExecution(SuppressWithNearbyCommentFilter filter, String filename, String... lines) {
final FileContents contents = new FileContents(new FileText(new File(filename), Arrays.asList(lines)));
contents.reportSingleLineComment(1, 0);
final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, filename, new Violation(1, null, null, null, null, Object.class, null), null);
filter.accept(dummyEvent);
return TestUtil.getInternalState(filter, "tags");
}
Aggregations