use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testIsSuppressed.
@Test
public void testIsSuppressed() throws Exception {
final Class<?> entry = Class.forName("com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder$Entry");
final Constructor<?> entryConstructor = entry.getDeclaredConstructor(String.class, int.class, int.class, int.class, int.class);
entryConstructor.setAccessible(true);
final Object entryInstance = entryConstructor.newInstance("MockEntry", 100, 100, 350, 350);
final List<Object> entriesList = new ArrayList<>();
entriesList.add(entryInstance);
final ThreadLocal<?> threadLocal = mock(ThreadLocal.class);
PowerMockito.doReturn(entriesList).when(threadLocal, "get");
final SuppressWarningsHolder holder = new SuppressWarningsHolder();
final Field entries = holder.getClass().getDeclaredField("ENTRIES");
entries.setAccessible(true);
entries.set(holder, threadLocal);
final Checker source = new Checker();
final LocalizedMessage message = new LocalizedMessage(100, 10, null, null, null, "id", MemberNameCheck.class, "message");
final AuditEvent event = new AuditEvent(source, "fileName", message);
assertFalse(SuppressWarningsHolder.isSuppressed(event));
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class FileSetCheckLifecycleTest method testProcessCallsFinishBeforeCallingDestroy.
@Test
public void testProcessCallsFinishBeforeCallingDestroy() throws Exception {
final DefaultConfiguration dc = new DefaultConfiguration("configuration");
final DefaultConfiguration twConf = createCheckConfig(TreeWalker.class);
dc.addAttribute("charset", "UTF-8");
dc.addChild(twConf);
twConf.addChild(new DefaultConfiguration(FileContentsHolder.class.getName()));
twConf.addChild(new DefaultConfiguration(AvoidStarImportCheck.class.getName()));
final Checker checker = new Checker();
final Locale locale = Locale.ROOT;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(dc);
checker.addListener(new BriefUtLogger(stream));
checker.addFileSetCheck(new TestFileSetCheck());
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, getPath("InputIllegalTokens.java"), expected);
assertTrue("FileContent should be available during finishProcessing() call", TestFileSetCheck.isFileContentAvailable());
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class AbstractJavadocCheckTest method testWithMultipleChecks.
@Test
public void testWithMultipleChecks() throws Exception {
final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
checksConfig.addChild(createCheckConfig(AtclauseOrderCheck.class));
checksConfig.addChild(createCheckConfig(JavadocParagraphCheck.class));
checkerConfig.addChild(checksConfig);
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
verify(checker, getPath("InputCorrectJavaDocParagraph.java"));
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class IndentationCheckTest method verify.
private void verify(Configuration config, String filePath, String[] expected, final IndentComment... linesWithWarn) throws Exception {
final Checker checker = createChecker(config);
checker.addListener(new IndentAudit(linesWithWarn));
checker.setLocaleCountry(Locale.ROOT.getCountry());
checker.setLocaleLanguage(Locale.ROOT.getLanguage());
checker.finishLocalSetup();
verify(checker, new File[] { new File(filePath) }, filePath, expected);
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class IndentationCheckTest method testInvalidArrayInitWithChecker.
@Test
public void testInvalidArrayInitWithChecker() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
checkConfig.addAttribute("arrayInitIndent", "4");
checkConfig.addAttribute("basicOffset", "4");
checkConfig.addAttribute("braceAdjustment", "0");
checkConfig.addAttribute("caseIndent", "4");
checkConfig.addAttribute("forceStrictCondition", "false");
checkConfig.addAttribute("lineWrappingIndentation", "4");
checkConfig.addAttribute("tabWidth", "4");
checkConfig.addAttribute("throwsIndent", "4");
final String fileName = getPath("InputInvalidArrayInitIndent.java");
final String[] expected = { "21: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4), "22: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4), "24: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4), "28: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4), "29: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 8, 10), "30: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"), "33: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 9, 8), "34: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 7, 8), "35: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 9, 8), "40: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"), "44: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"), "48: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"), "52: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20, "8, 31, 33"), "53: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 4, "8, 31, 33"), "58: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 6, 8), "63: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4), "65: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4), "66: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"), "69: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 6, 8), "76: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12), "89: " + getCheckMessage(MSG_ERROR, "1", 8, 12), "100: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12), "101: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12), "104: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12), "105: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12), "106: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"), "109: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"), "110: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12), "111: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12), "112: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12") };
final Checker checker = createChecker(checkConfig);
checker.setLocaleCountry(Locale.ROOT.getCountry());
checker.setLocaleLanguage(Locale.ROOT.getLanguage());
checker.finishLocalSetup();
//Test input for this test case is not checked due to issue #693.
verify(checker, fileName, expected);
}
Aggregations