@Test
 public void testGenerics() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(RequireThisCheck.class);
   checkConfig.addAttribute("validateOnlyOverlapping", "false");
   final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
   verify(checkConfig, getPath("Input15Extensions.java"), expected);
 }
 @Test
 public void test1379666() throws Exception {
   checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
   checkConfig.addAttribute("allowUndeclaredRTE", "true");
   final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
   verify(checkConfig, getPath("checks/javadoc/Input_1379666.java"), expected);
 }
 @Test
 public void testCatch() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(ParameterNameCheck.class);
   checkConfig.addAttribute("format", "^NO_WAY_MATEY$");
   final String[] expected = {};
   verify(checkConfig, getPath("InputLeftCurlyOther.java"), expected);
 }
 @Test
 public void testAnother2() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(JavadocVariableCheck.class);
   checkConfig.addAttribute("scope", Scope.PUBLIC.getName());
   final String[] expected = {};
   verify(checkConfig, getPath("InputInner.java"), expected);
 }
 @Test(expected = ConversionException.class)
 public void testInvalidMessageFormat() throws Exception {
   final DefaultConfiguration filterConfig = createFilterConfig(SuppressionCommentFilter.class);
   filterConfig.addAttribute("messageFormat", "e[l");
   final String[] suppressed = ArrayUtils.EMPTY_STRING_ARRAY;
   verifySuppressed(filterConfig, suppressed);
 }
  @Test
  public void testTypeAndVariablesAndMethodNames() throws Exception {

    final int expectedCapitalCount = 5;
    warningMessage = getCheckMessage(MSG_KEY, expectedCapitalCount);
    final DefaultConfiguration checkConfig = createCheckConfig(AbbreviationAsWordInNameCheck.class);
    checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
    checkConfig.addAttribute("allowedAbbreviations", "CLASS");
    checkConfig.addAttribute(
        "tokens",
        "CLASS_DEF"
            + ",VARIABLE_DEF"
            + ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
            + ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
    checkConfig.addAttribute("ignoreOverriddenMethods", "true");

    final String[] expected = {
      "32: " + warningMessage,
      "37: " + warningMessage,
      "38: " + warningMessage,
      "39: " + warningMessage,
      "40: " + warningMessage,
      "58: " + warningMessage,
    };

    verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
  }
 @Test
 public void testValidateBetweenScopesOption() throws Exception {
   final DefaultConfiguration checkConfig =
       createCheckConfig(VariableDeclarationUsageDistanceCheck.class);
   checkConfig.addAttribute("allowedDistance", "1");
   checkConfig.addAttribute("ignoreVariablePattern", "");
   checkConfig.addAttribute("validateBetweenScopes", "false");
   checkConfig.addAttribute("ignoreFinal", "false");
   final String[] expected = {
     "30: " + getCheckMessage(MSG_KEY, "a", 2, 1),
     "38: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
     "44: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
     "71: " + getCheckMessage(MSG_KEY, "count", 4, 1),
     "96: " + getCheckMessage(MSG_KEY, "arg", 2, 1),
     "219: " + getCheckMessage(MSG_KEY, "t", 5, 1),
     "222: " + getCheckMessage(MSG_KEY, "c", 3, 1),
     "223: " + getCheckMessage(MSG_KEY, "d2", 3, 1),
     "300: " + getCheckMessage(MSG_KEY, "wh", 2, 1),
     "343: " + getCheckMessage(MSG_KEY, "green", 2, 1),
     "344: " + getCheckMessage(MSG_KEY, "blue", 3, 1),
     "367: " + getCheckMessage(MSG_KEY, "intervalMs", 2, 1),
     "454: " + getCheckMessage(MSG_KEY, "aOpt", 3, 1),
     "455: " + getCheckMessage(MSG_KEY, "bOpt", 2, 1),
     "471: " + getCheckMessage(MSG_KEY, "l1", 3, 1),
     "471: " + getCheckMessage(MSG_KEY, "l2", 2, 1),
     "479: " + getCheckMessage(MSG_KEY, "myOption", 7, 1),
     "491: Distance between variable 'myOption' declaration and its first usage is 6, but allowed 1.",
     "505: Distance between variable 'files' declaration and its first usage is 2, but allowed 1.",
     "540: Distance between variable 'id' declaration and its first usage is 2, but allowed 1.",
     "542: Distance between variable 'parentId' declaration and its first usage is 4, but allowed 1.",
   };
   verify(checkConfig, getPath("InputVariableDeclarationUsageDistanceCheck.java"), expected);
 }
  @Test
  public void testOnlyModifiers() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(DeclarationOrderCheck.class);
    checkConfig.addAttribute("ignoreConstructors", "true");
    checkConfig.addAttribute("ignoreMethods", "true");
    checkConfig.addAttribute("ignoreModifiers", "false");

    final String[] expected = {
      "8:5: Variable access definition in wrong order.",
      "13:5: Variable access definition in wrong order.",
      "18:5: Variable access definition in wrong order.",
      "21:5: Variable access definition in wrong order.",
      "27:5: Static variable definition in wrong order.",
      "27:5: Variable access definition in wrong order.",
      "34:9: Variable access definition in wrong order.",
      "45:9: Static variable definition in wrong order.",
      "45:9: Variable access definition in wrong order.",
      "80:5: Instance variable definition in wrong order.",
      "92:9: Variable access definition in wrong order.",
      "100:9: Static variable definition in wrong order.",
      "100:9: Variable access definition in wrong order.",
      "106:5: Variable access definition in wrong order.",
      "111:5: Variable access definition in wrong order.",
      "116:5: Variable access definition in wrong order.",
      "119:5: Variable access definition in wrong order.",
      "125:5: Static variable definition in wrong order.",
      "125:5: Variable access definition in wrong order.",
      "132:9: Variable access definition in wrong order.",
      "143:9: Static variable definition in wrong order.",
      "143:9: Variable access definition in wrong order.",
      "178:5: Instance variable definition in wrong order.",
    };
    verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
  }
  @Test
  public void testOnlyModifiers() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(DeclarationOrderCheck.class);
    checkConfig.addAttribute("ignoreConstructors", "true");
    checkConfig.addAttribute("ignoreModifiers", "false");

    final String[] expected = {
      "8:5: " + getCheckMessage(MSG_ACCESS),
      "13:5: " + getCheckMessage(MSG_ACCESS),
      "18:5: " + getCheckMessage(MSG_ACCESS),
      "21:5: " + getCheckMessage(MSG_ACCESS),
      "27:5: " + getCheckMessage(MSG_STATIC),
      "27:5: " + getCheckMessage(MSG_ACCESS),
      "34:9: " + getCheckMessage(MSG_ACCESS),
      "45:9: " + getCheckMessage(MSG_STATIC),
      "45:9: " + getCheckMessage(MSG_ACCESS),
      "80:5: " + getCheckMessage(MSG_INSTANCE),
      "92:9: " + getCheckMessage(MSG_ACCESS),
      "100:9: " + getCheckMessage(MSG_STATIC),
      "100:9: " + getCheckMessage(MSG_ACCESS),
      "106:5: " + getCheckMessage(MSG_ACCESS),
      "111:5: " + getCheckMessage(MSG_ACCESS),
      "116:5: " + getCheckMessage(MSG_ACCESS),
      "119:5: " + getCheckMessage(MSG_ACCESS),
      "125:5: " + getCheckMessage(MSG_STATIC),
      "125:5: " + getCheckMessage(MSG_ACCESS),
      "132:9: " + getCheckMessage(MSG_ACCESS),
      "143:9: " + getCheckMessage(MSG_STATIC),
      "143:9: " + getCheckMessage(MSG_ACCESS),
      "178:5: " + getCheckMessage(MSG_INSTANCE),
      "182:9: " + getCheckMessage(MSG_ACCESS),
    };
    verify(checkConfig, getPath("InputDeclarationOrder.java"), expected);
  }
 @Test
 public void testTagsWithSubclassesAllowed() throws Exception {
   checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
   checkConfig.addAttribute("validateThrows", "true");
   final String[] expected = {
     "14:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
     "18:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unused"),
     "24: " + getCheckMessage(MSG_RETURN_EXPECTED),
     "33: " + getCheckMessage(MSG_RETURN_EXPECTED),
     "40:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
     "49:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
     "55:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
     "55:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "NullPointerException"),
     "60:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
     "68:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
     "72:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "WrongParam"),
     "73:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
     "73:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aTwo"),
     "78:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "Unneeded"),
     "79: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
     "87:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
     "109:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
     "109:55: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFour"),
     "109:66: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFive"),
     "178:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "ThreadDeath"),
     "179:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "ArrayStoreException"),
     "256:28: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IOException"),
     "262:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "aParam"),
     "320:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
     "329:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
     "333: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
   };
   verify(checkConfig, getPath("checks/javadoc/InputTags.java"), expected);
 }
 @Test
 public void testAllowEscapesForControlCharacterst() throws Exception {
   DefaultConfiguration checkConfig = createCheckConfig(AvoidEscapedUnicodeCharactersCheck.class);
   checkConfig.addAttribute("allowEscapesForControlCharacters", "true");
   final String[] expected = {
     "7: " + msg,
     "9: " + msg,
     "11: " + msg,
     "15: " + msg,
     "16: " + msg,
     "24: " + msg,
     "25: " + msg,
     "31: " + msg,
     "32: " + msg,
     "33: " + msg,
     "34: " + msg,
     "42: " + msg,
     "59: " + msg,
     "60: " + msg,
     "61: " + msg,
     "62: " + msg,
     "73: " + msg,
     "74: " + msg,
     "75: " + msg,
     "76: " + msg,
     "77: " + msg,
     "79: " + msg,
     "82: " + msg,
   };
   verify(checkConfig, getPath("InputAvoidEscapedUnicodeCharactersCheck.java"), expected);
 }
 @Test
 public void testIgnoreCaseFalse() throws Exception {
   final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
   mCheckConfig.addAttribute("format", illegal);
   mCheckConfig.addAttribute("ignoreCase", "false");
   final String[] expected = {};
   verify(mCheckConfig, getPath("InputSemantic.java"), expected);
 }
 public void testIgnoreNonLocal() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class);
   checkConfig.addAttribute("ignoreNonLocal", "true");
   final String[] expected = {
     "8:57: Unused parameter 'aUnreadPrimitive'.", "29:66: Unused parameter 'aUnreadArray'.",
   };
   verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected);
 }
 @Test
 public void testIgnore() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
   checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
   checkConfig.addAttribute("ignoreLines", "2");
   final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
   verify(checkConfig, getConfigPath("java2.header"), expected);
 }
  /**
   * This tests anonymous inner classes that are overriding methods are NOT flagged while in Java 5
   * compatibility mode.
   *
   * @throws Exception
   */
  @Test
  public void testBadAnnonOverrideJ5Compat() throws Exception {
    DefaultConfiguration checkConfig = createCheckConfig(MissingOverrideCheck.class);
    checkConfig.addAttribute("javaFiveCompatibility", "true");
    final String[] expected = {};

    verify(checkConfig, getPath("annotation" + File.separator + "BadAnnonOverride.java"), expected);
  }
  @Test
  public void allowedAnnotationsTest() throws Exception {

    DefaultConfiguration config = createCheckConfig(JavadocMethodCheck.class);
    config.addAttribute("allowedAnnotations", "Override,ThisIsOk, \t\n\t ThisIsOkToo");
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
    verify(config, getPath("javadoc/AllowedAnnotations.java"), expected);
  }
  /**
   * This tests anonymous inner classes that are overriding methods are NOT flagged while in Java 5
   * compatibility mode.
   */
  @Test
  public void testGoodAnnotationOverrideJ5Compatible() throws Exception {
    DefaultConfiguration checkConfig = createCheckConfig(MissingOverrideCheck.class);
    checkConfig.addAttribute("javaFiveCompatibility", "true");
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;

    verify(checkConfig, getPath("GoodAnnotationOverride.java"), expected);
  }
 @Test
 public void testCheckCPP() throws Exception {
   final DefaultConfiguration filterConfig = createFilterConfig(SuppressionCommentFilter.class);
   filterConfig.addAttribute("checkCPP", "false");
   final String[] suppressed = {
     "16:17: Name 'J' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
   };
   verifySuppressed(filterConfig, suppressed);
 }
 @Test
 public void testAnother4() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(JavadocVariableCheck.class);
   checkConfig.addAttribute("scope", Scope.PUBLIC.getName());
   final String[] expected = {
     "46:5: Missing a Javadoc comment.",
   };
   verify(checkConfig, getPath("InputPublicOnly.java"), expected);
 }
 @Test
 public void testForEachClauseToken() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(FinalParametersCheck.class);
   checkConfig.addAttribute("tokens", "FOR_EACH_CLAUSE");
   final String[] expected = {
     "150:13: " + getCheckMessage(MSG_KEY, "s"), "158:13: " + getCheckMessage(MSG_KEY, "s"),
   };
   verify(checkConfig, getPath("InputFinalParameters.java"), expected);
 }
 protected DefaultConfiguration createCheckerConfig(Configuration config) {
   final DefaultConfiguration dc = new DefaultConfiguration("configuration");
   final DefaultConfiguration twConf = createCheckConfig(TreeWalker.class);
   // make sure that the tests always run with this charset
   dc.addAttribute("charset", "iso-8859-1");
   dc.addChild(twConf);
   twConf.addChild(config);
   return dc;
 }
 @Test
 public void newTest() throws Exception {
   DefaultConfiguration config = createCheckConfig(JavadocMethodCheck.class);
   config.addAttribute("allowedAnnotations", "MyAnnotation, Override");
   config.addAttribute("minLineCount", "2");
   final String[] expected = {
     "57:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
   };
   verify(config, getPath("javadoc/InputJavadocMethodCheck_SmallMethods.java"), expected);
 }
 @Test
 public void testIgnoreCaseTrue() throws Exception {
   final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
   mCheckConfig.addAttribute("format", illegal);
   mCheckConfig.addAttribute("ignoreCase", "true");
   final String[] expected = {
     "69: Line matches the illegal pattern '" + illegal + "'.",
   };
   verify(mCheckConfig, getPath("InputSemantic.java"), expected);
 }
 @Test
 public void testLogLoadErrors() throws Exception {
   DefaultConfiguration config = createCheckConfig(JavadocMethodCheck.class);
   config.addAttribute("logLoadErrors", "true");
   config.addAttribute("allowUndeclaredRTE", "true");
   final String[] expected = {
     "7:8: " + getCheckMessage(MSG_CLASS_INFO, "@throws", "InvalidExceptionName"),
   };
   verify(config, getPath("javadoc/InputLoadErrors.java"), expected);
 }
 @Test
 public void testIt4() throws Exception {
   checkConfig.addAttribute("allowEmptyMethods", "true");
   checkConfig.addAttribute("allowEmptyConstructors", "true");
   final String[] expected = {
     "37:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
     "54:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "for"),
   };
   verify(checkConfig, getPath("InputBraces.java"), expected);
 }
 @Test
 public void testGithubIssue41() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(RequireThisCheck.class);
   checkConfig.addAttribute("validateOnlyOverlapping", "false");
   final String[] expected = {
     "7:19: " + getCheckMessage(MSG_VARIABLE, "number", ""),
     "8:16: " + getCheckMessage(MSG_METHOD, "other", ""),
   };
   verify(checkConfig, getPath("InputRequireThis2.java"), expected);
 }
 @Test
 public void testCheckWithOffset3() throws Exception {
   final DefaultConfiguration checkConfig =
       createCheckConfig(JavadocTagContinuationIndentationCheck.class);
   checkConfig.addAttribute("offset", "3");
   final String[] expected = {
     "7: " + getCheckMessage(MSG_KEY, 3), "19: " + getCheckMessage(MSG_KEY, 3),
   };
   verify(checkConfig, getPath("InputJavaDocTagContinuationIndentationOffset3.java"), expected);
 }
 @Test
 public void testStaticHeader() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
   checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
   checkConfig.addAttribute("ignoreLines", "");
   final String[] expected = {
     "1: " + getCheckMessage(MSG_MISSING),
   };
   verify(checkConfig, getPath("InputHeader.java"), expected);
 }
 @Test
 public void testCatchToken() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(FinalParametersCheck.class);
   checkConfig.addAttribute("tokens", "LITERAL_CATCH");
   final String[] expected = {
     "125:16: " + getCheckMessage(MSG_KEY, "npe"),
     "131:16: " + getCheckMessage(MSG_KEY, "e"),
     "134:16: " + getCheckMessage(MSG_KEY, "e"),
   };
   verify(checkConfig, getPath("InputFinalParameters.java"), expected);
 }
 @Test
 public void testCtorToken() throws Exception {
   final DefaultConfiguration checkConfig = createCheckConfig(FinalParametersCheck.class);
   checkConfig.addAttribute("tokens", "CTOR_DEF");
   final String[] expected = {
     "23:26: " + getCheckMessage(MSG_KEY, "s"),
     "38:26: " + getCheckMessage(MSG_KEY, "i"),
     "43:26: " + getCheckMessage(MSG_KEY, "s"),
   };
   verify(checkConfig, getPath("InputFinalParameters.java"), expected);
 }