use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class PackageObjectFactoryTest method testMakeCheckFromName.
@Test
public void testMakeCheckFromName() {
final String name = "com.puppycrawl.tools.checkstyle.checks.naming.ConstantName";
try {
factory.createModule(name);
assertWithMessage("Exception is expected").fail();
} catch (CheckstyleException ex) {
final Violation exceptionMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE, new String[] { name, null }, null, factory.getClass(), null);
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo(exceptionMessage.getViolation());
}
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class PackageObjectFactoryTest method testCreateObjectFromFullModuleNamesWithExceptionByBruteForce.
@Test
public void testCreateObjectFromFullModuleNamesWithExceptionByBruteForce() {
final String package1 = BASE_PACKAGE + ".wrong1";
final String package2 = BASE_PACKAGE + ".wrong2";
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final PackageObjectFactory objectFactory = new PackageObjectFactory(new LinkedHashSet<>(Arrays.asList(package1, package2)), classLoader, TRY_IN_ALL_REGISTERED_PACKAGES);
final String name = "FooCheck";
final String checkName = name + CHECK_SUFFIX;
try {
objectFactory.createModule(name);
assertWithMessage("Exception is expected").fail();
} catch (CheckstyleException ex) {
final String attemptedNames = package1 + PACKAGE_SEPARATOR + name + STRING_SEPARATOR + package2 + PACKAGE_SEPARATOR + name + STRING_SEPARATOR + checkName + STRING_SEPARATOR + package1 + PACKAGE_SEPARATOR + checkName + STRING_SEPARATOR + package2 + PACKAGE_SEPARATOR + checkName;
final Violation exceptionMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE, new String[] { name, attemptedNames }, null, getClass(), null);
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo(exceptionMessage.getViolation());
}
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAuditFinishedWithoutFileFinished.
@Test
public void testAuditFinishedWithoutFileFinished() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
logger.fileStarted(fileStartedEvent);
final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent errorEvent = new AuditEvent(this, "Test.java", violation);
logger.addError(errorEvent);
logger.fileFinished(errorEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, violation.getViolation());
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddExceptionBetweenFileStartedAndFinished.
@Test
public void testAddExceptionBetweenFileStartedAndFinished() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", null, null, null, getClass(), null);
final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
logger.fileStarted(fileStartedEvent);
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
logger.fileFinished(fileFinishedEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerException2.xml"), outStream);
assertWithMessage("Invalid close count").that(outStream.getCloseCount()).isEqualTo(1);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddException.
@Test
public void testAddException() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", null, null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerException.xml"), outStream);
assertWithMessage("Invalid close count").that(outStream.getCloseCount()).isEqualTo(1);
}
Aggregations