use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class XpathFileGeneratorAuditListenerTest method testCorrectTwo.
@Test
public void testCorrectTwo() {
final AuditEvent event1 = createAuditEvent("InputXpathFileGeneratorAuditListener.java", SECOND_MESSAGE);
final AuditEvent event2 = createAuditEvent("InputXpathFileGeneratorAuditListener.java", THIRD_MESSAGE);
final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + EOL + "<!DOCTYPE suppressions PUBLIC" + EOL + " \"-//Checkstyle//DTD SuppressionXpathFilter Experimental Configuration 1.2" + "//EN\"" + EOL + " \"https://checkstyle.org/dtds/suppressions_1_2_xpath_experimental.dtd\">" + EOL + "<suppressions>" + EOL + "<suppress-xpath" + EOL + " files=\"InputXpathFileGeneratorAuditListener.java\"" + EOL + " id=\"MyModule\"" + EOL + " query=\"/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathFileGeneratorAuditListener']]" + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='sort']]\"/>" + EOL + "<suppress-xpath" + EOL + " files=\"InputXpathFileGeneratorAuditListener.java\"" + EOL + " checks=\"NestedForDepthCheck\"" + EOL + " query=\"/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathFileGeneratorAuditListener']]" + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='sort']]/SLIST/LITERAL_FOR/SLIST" + "/LITERAL_FOR\"/>" + EOL + "</suppressions>" + EOL;
verifyOutput(expected, event1, event2);
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class XpathFileGeneratorAuditListenerTest method testFileFinished.
@Test
public void testFileFinished() {
final OutputStream out = new ByteArrayOutputStream();
final XpathFileGeneratorAuditListener listener = new XpathFileGeneratorAuditListener(out, AutomaticBean.OutputStreamOptions.CLOSE);
final AuditEvent ev = new AuditEvent(this, "Test.java", null);
listener.fileFinished(ev);
listener.auditFinished(null);
final String actual = out.toString();
assertWithMessage("Output should be empty").that(actual).isEmpty();
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class AuditEventDefaultFormatterTest method testFormatModuleWithModuleId.
@Test
public void testFormatModuleWithModuleId() {
final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, "ModuleId", TestModule.class, "Mocked violation.");
final AuditEvent event = new AuditEvent("", "InputMockFile.java", violation);
final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
final String expected = "[WARN] InputMockFile.java:1:1: Mocked violation. [ModuleId]";
assertWithMessage("Invalid format").that(formatter.format(event)).isEqualTo(expected);
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class AuditEventDefaultFormatterTest method testCalculateBufferLength.
@Test
public void testCalculateBufferLength() throws Exception {
final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent auditEvent = new AuditEvent(new Object(), "fileName", violation);
final int result = TestUtil.invokeStaticMethod(AuditEventDefaultFormatter.class, "calculateBufferLength", auditEvent, SeverityLevel.ERROR.ordinal());
assertWithMessage("Buffer length is not expected").that(result).isEqualTo(54);
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class AuditEventDefaultFormatterTest method testFormatFullyQualifiedModuleNameContainsCheckSuffix.
@Test
public void testFormatFullyQualifiedModuleNameContainsCheckSuffix() {
final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, null, TestModuleCheck.class, "Mocked violation.");
final AuditEvent event = new AuditEvent("", "InputMockFile.java", violation);
final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
final String expected = "[WARN] InputMockFile.java:1:1: Mocked violation. " + "[AuditEventDefaultFormatterTest$TestModule]";
assertWithMessage("Invalid format").that(formatter.format(event)).isEqualTo(expected);
}
Aggregations