use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class MainTest method testExistingTargetFileWithViolations.
@Test
public void testExistingTargetFileWithViolations(@SysErr Capturable systemErr, @SysOut Capturable systemOut) throws IOException {
assertMainReturnCode(0, "-c", getPath("InputMainConfig-classname2.xml"), getPath("InputMain.java"));
final Violation invalidPatternMessageMain = new Violation(1, "com.puppycrawl.tools.checkstyle.checks.naming.messages", "name.invalidPattern", new String[] { "InputMain", "^[a-z0-9]*$" }, null, getClass(), null);
final Violation invalidPatternMessageMainInner = new Violation(1, "com.puppycrawl.tools.checkstyle.checks.naming.messages", "name.invalidPattern", new String[] { "InputMainInner", "^[a-z0-9]*$" }, null, getClass(), null);
final String expectedPath = getFilePath("InputMain.java");
assertWithMessage("Unexpected output log").that(systemOut.getCapturedData()).isEqualTo(addEndOfLine(auditStartMessage.getViolation(), "[WARN] " + expectedPath + ":3:14: " + invalidPatternMessageMain.getViolation() + " [TypeName]", "[WARN] " + expectedPath + ":5:7: " + invalidPatternMessageMainInner.getViolation() + " [TypeName]", auditFinishMessage.getViolation()));
assertWithMessage("Unexpected system error log").that(systemErr.getCapturedData()).isEqualTo("");
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class MainTest method testCustomSimpleRootModule.
@Test
public void testCustomSimpleRootModule(@SysErr Capturable systemErr) {
TestRootModuleChecker.reset();
assertMainReturnCode(-2, "-c", getPath("InputMainConfig-custom-simple-root-module.xml"), getPath("InputMain.java"));
final String checkstylePackage = "com.puppycrawl.tools.checkstyle.";
final Violation unableToInstantiateExceptionMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, "PackageObjectFactory.unableToInstantiateExceptionMessage", new String[] { "TestRootModuleChecker", checkstylePackage + "TestRootModuleChecker, " + "TestRootModuleCheckerCheck, " + checkstylePackage + "TestRootModuleCheckerCheck" }, null, getClass(), null);
assertWithMessage("Unexpected system error log").that(systemErr.getCapturedData().startsWith(checkstylePackage + "api.CheckstyleException: " + unableToInstantiateExceptionMessage.getViolation())).isTrue();
assertWithMessage("Invalid checker state").that(TestRootModuleChecker.isProcessed()).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class MainTest method testExistingTargetFileWithOneErrorAgainstSunCheck.
@Test
public void testExistingTargetFileWithOneErrorAgainstSunCheck(@SysErr Capturable systemErr, @SysOut Capturable systemOut) throws Exception {
assertMainReturnCode(1, "-c", "/sun_checks.xml", getPath("InputMain1.java"));
final Violation errorCounterTwoMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, Main.ERROR_COUNTER, new String[] { String.valueOf(1) }, null, getClass(), null);
final Violation message = new Violation(1, "com.puppycrawl.tools.checkstyle.checks.javadoc.messages", "javadoc.packageInfo", new String[] {}, null, getClass(), null);
final String expectedPath = getFilePath("InputMain1.java");
assertWithMessage("Unexpected output log").that(systemOut.getCapturedData()).isEqualTo(addEndOfLine(auditStartMessage.getViolation(), "[ERROR] " + expectedPath + ":1: " + message.getViolation() + " [JavadocPackage]", auditFinishMessage.getViolation()));
assertWithMessage("Unexpected system error log").that(systemErr.getCapturedData()).isEqualTo(addEndOfLine(errorCounterTwoMessage.getViolation()));
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SarifLoggerTest method testEmpty.
@Test
public void testEmpty() throws IOException {
final SarifLogger logger = new SarifLogger(outStream, AutomaticBean.OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "null", null, null, getClass(), "found an error");
final AuditEvent ev = new AuditEvent(this, null, violation);
logger.fileStarted(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyContent(getPath("ExpectedSarifLoggerEmpty.sarif"), outStream);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SarifLoggerTest method testAddErrorWithWarningLevel.
@Test
public void testAddErrorWithWarningLevel() throws IOException {
final SarifLogger logger = new SarifLogger(outStream, AutomaticBean.OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "ruleId", null, SeverityLevel.WARNING, null, getClass(), "found an error");
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyContent(getPath("ExpectedSarifLoggerSingleWarning.sarif"), outStream);
}
Aggregations