use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XpathFileGeneratorAstFilterTest method testAcceptNoToken.
@Test
public void testAcceptNoToken() {
final Violation violation = new Violation(0, 0, 0, null, null, null, null, null, XpathFileGeneratorAstFilterTest.class, null);
final TreeWalkerAuditEvent event = new TreeWalkerAuditEvent(null, null, violation, null);
final XpathFileGeneratorAstFilter filter = new XpathFileGeneratorAstFilter();
assertWithMessage("filter accepted").that(filter.accept(event)).isTrue();
final AuditEvent auditEvent = new AuditEvent(this, "Test.java", violation);
assertWithMessage("filter has no queries").that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent)).isNull();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XpathFileGeneratorAstFilterTest method testTabWidth.
@Test
public void testTabWidth() throws Exception {
final Violation violation = new Violation(6, 7, TokenTypes.LITERAL_RETURN, "messages.properties", null, null, SeverityLevel.ERROR, null, XpathFileGeneratorAstFilterTest.class, null);
final TreeWalkerAuditEvent event = createTreeWalkerAuditEvent("InputXpathFileGeneratorAstFilter.java", violation);
final XpathFileGeneratorAstFilter filter = new XpathFileGeneratorAstFilter();
filter.setTabWidth(6);
assertWithMessage("filter accepted").that(filter.accept(event)).isTrue();
final AuditEvent auditEvent = new AuditEvent(this, getPath("InputXpathFileGeneratorAstFilter.java"), violation);
assertWithMessage("expected xpath").that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent)).isEqualTo("/COMPILATION_UNIT" + "/CLASS_DEF[./IDENT[@text='InputXpathFileGeneratorAstFilter']]" + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='tabMethod']]/SLIST/LITERAL_RETURN");
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class NewlineAtEndOfFileCheckTest method testWrongFile.
@Test
public void testWrongFile() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(NewlineAtEndOfFileCheck.class);
final NewlineAtEndOfFileCheck check = new NewlineAtEndOfFileCheck();
check.configure(checkConfig);
final List<String> lines = new ArrayList<>(1);
lines.add("txt");
final File impossibleFile = new File("");
final FileText fileText = new FileText(impossibleFile, lines);
final Set<Violation> violations = check.process(impossibleFile, fileText);
assertWithMessage("Amount of violations is unexpected").that(violations).hasSize(1);
final Iterator<Violation> iterator = violations.iterator();
assertWithMessage("Violation message differs from expected").that(iterator.next().getViolation()).isEqualTo(getCheckMessage(MSG_KEY_UNABLE_OPEN, ""));
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddErrorWithNullFileName.
@Test
public void testAddErrorWithNullFileName() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, null, violation);
logger.addError(ev);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerErrorNullFileName.xml"), outStream, violation.getViolation());
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddError.
@Test
public void testAddError() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, violation.getViolation());
}
Aggregations