Refine search
@Test public void testMatchFolderAndFileNotMatchesBoth() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpOnFilenameCheck.class); checkConfig.addAttribute("match", "true"); checkConfig.addAttribute("folderPattern", "BAD.*"); checkConfig.addAttribute("fileNamePattern", ".*\\.properties"); verify(checkConfig, getPath("InputRegexpOnFilenameSemantic.java"), CommonUtil.EMPTY_STRING_ARRAY); }
@Test public void testNotMatchFolderAndFileNotMatchesFile() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpOnFilenameCheck.class); checkConfig.addAttribute("match", "false"); checkConfig.addAttribute("folderPattern", ".*[\\\\/]govstrangefolder[\\\\/].*"); checkConfig.addAttribute("fileNamePattern", ".*\\.java"); verify(checkConfig, getPath("InputRegexpOnFilenameSemantic.java"), CommonUtil.EMPTY_STRING_ARRAY); }
@Test public void testSetMessage() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpSinglelineCheck.class); checkConfig.addAttribute("format", "\\r"); checkConfig.addAttribute("minimum", "500"); checkConfig.addAttribute("message", "someMessage"); final String[] expected = { "1: someMessage", }; verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected); }
@Test public void testFieldsOnInterfaceAllowImpliedPublicStaticFinal() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(InterfaceMemberImpliedModifierCheck.class); checkConfig.addAttribute("violateImpliedPublicField", "false"); checkConfig.addAttribute("violateImpliedStaticField", "false"); checkConfig.addAttribute("violateImpliedFinalField", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; verify(checkConfig, getPath("InputInterfaceMemberImpliedModifierFieldsOnInterface.java"), expected); }
@Test public void testIgnoreCommentsInlineEnd() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpCheck.class); checkConfig.addAttribute("format", "int z"); checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("ignoreComments", "true"); final String[] expected = { "22: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "int z"), }; verify(checkConfig, getPath("InputRegexpTrailingComment.java"), expected); }
@Test public void testInputAnnotationScopeIndentationCheck() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class); checkConfig.addAttribute("tabWidth", "4"); checkConfig.addAttribute("basicOffset", "4"); checkConfig.addAttribute("forceStrictCondition", "true"); final String fileName = getPath("InputIndentationAnnotationScopeIndentationCheck.java"); final String[] expected = { "9: " + getCheckMessage(MSG_ERROR, "}", 8, 0), }; verifyWarns(checkConfig, fileName, expected); }
@Test public void testMatchFolderNotMatches() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpOnFilenameCheck.class); checkConfig.addAttribute("match", "true"); checkConfig.addAttribute("folderPattern", "BAD.*"); verify(checkConfig, getPath("InputRegexpOnFilenameSemantic.java"), CommonUtil.EMPTY_STRING_ARRAY); }
@Test public void testMessageProperty() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpSinglelineCheck.class); checkConfig.addAttribute("format", "System\\.(out)|(err)\\.print(ln)?\\("); checkConfig.addAttribute("message", "Bad line :("); final String[] expected = { "69: Bad line :(", }; verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected); }
@Test public void testSingleLineLambda() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(NeedBracesCheck.class); checkConfig.addAttribute("tokens", "LAMBDA"); checkConfig.addAttribute("allowSingleLineStatement", "true"); final String[] expected = { "7: " + getCheckMessage(MSG_KEY_NEED_BRACES, "->"), }; verify(checkConfig, getPath("InputNeedBracesSingleLineLambda.java"), expected); }
@Test public void testStaticInit() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(ExecutableStatementCountCheck.class); checkConfig.addAttribute("max", "0"); checkConfig.addAttribute("tokens", "STATIC_INIT"); final String[] expected = { "58:5: " + getCheckMessage(MSG_KEY, 2, 0), }; verify(checkConfig, getPath("InputExecutableStatementCount.java"), expected); }
@Test public void testDot() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(SeparatorWrapCheck.class); checkConfig.addAttribute("option", "NL"); checkConfig.addAttribute("tokens", "DOT"); final String[] expected = { "31:10: " + getCheckMessage(MSG_LINE_NEW, "."), }; verify(checkConfig, getPath("InputSeparatorWrapForTestDot.java"), expected); }
@Test public void testEllipsis() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(SeparatorWrapCheck.class); checkConfig.addAttribute("option", "EOL"); checkConfig.addAttribute("tokens", "ELLIPSIS"); final String[] expected = { "11:13: " + getCheckMessage(MSG_LINE_PREVIOUS, "..."), }; verify(checkConfig, getPath("InputSeparatorWrapForEllipsis.java"), expected); }
@Test public void testRegularExError() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(WriteTagCheck.class); checkConfig.addAttribute("tag", "@author"); checkConfig.addAttribute("tagFormat", "ABC"); final String[] expected = { "10: " + getCheckMessage(MSG_TAG_FORMAT, "@author", "ABC"), }; verify(checkConfig, getPath("InputWriteTag.java"), expected); }
@Test public void testIgnoreCommentsInlineMiddle() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpSinglelineJavaCheck.class); checkConfig.addAttribute("format", "int y"); checkConfig.addAttribute("ignoreComments", "true"); final String[] expected = { "23: " + getCheckMessage(MSG_REGEXP_EXCEEDED, "int y"), }; verify(checkConfig, getPath("InputRegexpSinglelineJavaTrailingComment.java"), expected); }
@Test public void testEmptyForLoop() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(NoWhitespaceBeforeCheck.class); checkConfig.addAttribute("tokens", "SEMI"); checkConfig.addAttribute("allowLineBreaks", "yes"); final String[] expected = { "12:24: " + getCheckMessage(MSG_KEY, ";"), "18:32: " + getCheckMessage(MSG_KEY, ";"), }; verify(checkConfig, getPath("InputNoWhitespaceBeforeEmptyForLoop.java"), expected); }
@Test public void testRegularExpression() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(ClassFanOutComplexityCheck.class); checkConfig.addAttribute("max", "0"); checkConfig.addAttribute("excludeClassesRegexps", "^Inner.*"); final String[] expected = { "6:1: " + getCheckMessage(MSG_KEY, 2, 0), "38:1: " + getCheckMessage(MSG_KEY, 1, 0), }; verify(checkConfig, getPath("InputClassFanOutComplexity.java"), expected); }
@Test public void testAllTokens() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(AnnotationLocationCheck.class); checkConfig.addAttribute("tokens", "CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, " + "CTOR_DEF, VARIABLE_DEF, PARAMETER_DEF, ANNOTATION_DEF, TYPECAST, " + "LITERAL_THROWS, IMPLEMENTS_CLAUSE, TYPE_ARGUMENT, LITERAL_NEW, DOT, " + "ANNOTATION_FIELD_DEF"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; verify(checkConfig, getPath("InputAnnotationLocationWithoutAnnotations.java"), expected); }
@Test public void testRequiredPass() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RegexpCheck.class); checkConfig.addAttribute("format", "Test case file"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; verify(checkConfig, getPath("InputRegexpSemantic.java"), expected); }
@Test public void testSkipCertainMethods() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class); checkConfig.addAttribute("ignoreMethodNamesRegex", "^foo.*$"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; verify(checkConfig, getPath("InputJavadocMethodIgnoreNameRegex.java"), expected); }
/** * This tests that classes not extending anything explicitly will be correctly * flagged for only including the inheritDoc tag. */ @Test public void testGoodOverrideFromObject() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(MissingOverrideCheck.class); checkConfig.addAttribute("javaFiveCompatibility", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; verify(checkConfig, getPath("InputMissingOverrideGoodOverrideFromObject.java"), expected); }