use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class TranslationCheckTest method testLogIoExceptionFileNotFound.
@Test
public void testLogIoExceptionFileNotFound() throws Exception {
// I can't put wrong file here. Checkstyle fails before check started.
// I saw some usage of file or handling of wrong file in Checker, or somewhere
// in checks running part. So I had to do it with reflection to improve coverage.
final TranslationCheck check = new TranslationCheck();
final DefaultConfiguration checkConfig = createModuleConfig(TranslationCheck.class);
final TestMessageDispatcher dispatcher = new TestMessageDispatcher();
check.configure(checkConfig);
check.setMessageDispatcher(dispatcher);
final Set<String> keys = TestUtil.invokeMethod(check, "getTranslationKeys", new File(".no.such.file"));
assertWithMessage("Translation keys should be empty when File is not found").that(keys).isEmpty();
assertWithMessage("expected number of errors to fire").that(dispatcher.savedErrors).hasSize(1);
final Violation violation = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, "general.fileNotFound", null, null, getClass(), null);
assertWithMessage("Invalid violation").that(dispatcher.savedErrors.iterator().next().getViolation()).isEqualTo(violation.getViolation());
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class TranslationCheckTest method testLogIoException.
@Test
public void testLogIoException() throws Exception {
// I can't put wrong file here. Checkstyle fails before check started.
// I saw some usage of file or handling of wrong file in Checker, or somewhere
// in checks running part. So I had to do it with reflection to improve coverage.
final TranslationCheck check = new TranslationCheck();
final DefaultConfiguration checkConfig = createModuleConfig(TranslationCheck.class);
final TestMessageDispatcher dispatcher = new TestMessageDispatcher();
check.configure(checkConfig);
check.setMessageDispatcher(dispatcher);
final Exception exception = new IOException("test exception");
TestUtil.invokeMethod(check, "logException", exception, new File(""));
assertWithMessage("expected number of errors to fire").that(dispatcher.savedErrors.size()).isEqualTo(1);
final Violation violation = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, "general.exception", new String[] { exception.getMessage() }, null, getClass(), null);
assertWithMessage("Invalid violation").that(dispatcher.savedErrors.iterator().next().getViolation()).isEqualTo(violation.getViolation());
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class OrderedPropertiesCheckTest method testKeepForLoopIntact.
/**
* This test validates the PIT mutation of getIndex().
* Here the for statement for
* (int index = startLineNo; index < fileText.size(); index++)
* will change to
* for (int index = startLineNo; true; index++)
* By creating a FileText having no lines it makes sure that
* fileText.size() returning zero size.
* This will keep the for loop intact.
*/
@Test
public void testKeepForLoopIntact() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(OrderedPropertiesCheck.class);
final OrderedPropertiesCheck check = new OrderedPropertiesCheck();
check.configure(checkConfig);
final String fileName = getPath("InputOrderedProperties2EmptyValue.properties");
final File file = new File(fileName);
final FileText fileText = new FileText(file, Collections.emptyList());
final SortedSet<Violation> violations = check.process(file, fileText);
assertWithMessage("Wrong violations count").that(violations).hasSize(1);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class RequireThisCheckTest method testDefaultSwitch.
@Test
public void testDefaultSwitch() {
final RequireThisCheck check = new RequireThisCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.ENUM, "ENUM"));
check.visitToken(ast);
final SortedSet<Violation> violations = check.getViolations();
assertWithMessage("No exception violations expected").that(violations).isEmpty();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class UniquePropertiesCheckTest method testIoException.
/**
* Tests IO exception, that can occur during reading of properties file.
*/
@Test
public void testIoException() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(UniquePropertiesCheck.class);
final UniquePropertiesCheck check = new UniquePropertiesCheck();
check.configure(checkConfig);
final String fileName = getPath("InputUniquePropertiesCheckNotExisting.properties");
final File file = new File(fileName);
final FileText fileText = new FileText(file, Collections.emptyList());
final SortedSet<Violation> violations = check.process(file, fileText);
assertWithMessage("Wrong messages count: " + violations.size()).that(violations).hasSize(1);
final Violation violation = violations.iterator().next();
final String retrievedMessage = violations.iterator().next().getKey();
assertWithMessage("violation key '" + retrievedMessage + "' is not valid").that(retrievedMessage).isEqualTo("unable.open.cause");
assertWithMessage("violation '" + violation.getViolation() + "' is not valid").that(getCheckMessage(MSG_IO_EXCEPTION_KEY, fileName, getFileNotFoundDetail(file))).isEqualTo(violation.getViolation());
}
Aggregations