Coverage has been increased to 100% in DescedantTokensCheck. Issue #1290

This commit is contained in:
Ilja Dubinin 2015-08-03 22:21:47 +01:00 committed by Roman Ivanov
parent d282d5b8db
commit 78fbe6abf4
2 changed files with 48 additions and 1 deletions

View File

@ -1088,7 +1088,6 @@
<regex><pattern>.*.checks.CheckUtils</pattern><branchRate>91</branchRate><lineRate>97</lineRate></regex>
<regex><pattern>.*.checks.ClassResolver</pattern><branchRate>85</branchRate><lineRate>93</lineRate></regex>
<regex><pattern>.*.checks.AbstractDeclarationCollector</pattern><branchRate>94</branchRate><lineRate>100</lineRate></regex>
<regex><pattern>.*.checks.DescendantTokenCheck</pattern><branchRate>91</branchRate><lineRate>96</lineRate></regex>
<regex><pattern>.*.checks.NewlineAtEndOfFileCheck</pattern><branchRate>83</branchRate><lineRate>88</lineRate></regex>
<regex><pattern>.*.checks.SuppressWarningsHolder</pattern><branchRate>75</branchRate><lineRate>93</lineRate></regex>
<regex><pattern>.*.checks.TranslationCheck</pattern><branchRate>81</branchRate><lineRate>83</lineRate></regex>

View File

@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks;
import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_MAX;
import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_MIN;
import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_SUM_MAX;
import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_SUM_MIN;
import java.io.File;
@ -308,4 +309,51 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport {
getPath("coding" + File.separator + "InputReturnFromFinallyCheck.java"),
expected);
}
@Test
public void testWithSumLessThenMinDefMsg() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(DescendantTokenCheck.class);
checkConfig.addAttribute("tokens", "NOT_EQUAL,EQUAL");
checkConfig.addAttribute("limitedTokens", "LITERAL_THIS,LITERAL_NULL");
checkConfig.addAttribute("minimumNumber", "3");
checkConfig.addAttribute("sumTokenCounts", "true");
String[] expected = {
"16:44: " + getCheckMessage(MSG_KEY_SUM_MIN, 0, 3, "EQUAL"),
"22:32: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
"22:50: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
"23:33: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "NOT_EQUAL"),
"23:51: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "NOT_EQUAL"),
"24:54: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
"24:77: " + getCheckMessage(MSG_KEY_SUM_MIN, 1, 3, "EQUAL"),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputReturnFromFinallyCheck.java"),
expected);
}
@Test
public void testWithSumLessThenMinCustMsg() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(DescendantTokenCheck.class);
checkConfig.addAttribute("tokens", "NOT_EQUAL,EQUAL");
checkConfig.addAttribute("limitedTokens", "LITERAL_THIS,LITERAL_NULL");
checkConfig.addAttribute("minimumNumber", "3");
checkConfig.addAttribute("sumTokenCounts", "true");
checkConfig.addAttribute("minimumMessage", "custom message");
String[] expected = {
"16:44: custom message",
"22:32: custom message",
"22:50: custom message",
"23:33: custom message",
"23:51: custom message",
"24:54: custom message",
"24:77: custom message",
};
verify(checkConfig,
getPath("coding" + File.separator + "InputReturnFromFinallyCheck.java"),
expected);
}
}