Issue #1293: Improved coverage for ReturnCountCheck

This commit is contained in:
Baratali Izmailov 2015-07-26 14:09:08 -07:00 committed by Roman Ivanov
parent 75ddaad1c5
commit dd5562f6dc
3 changed files with 29 additions and 3 deletions

View File

@ -1091,7 +1091,6 @@
<regex><pattern>.*.checks.coding.DeclarationOrderCheck</pattern><branchRate>82</branchRate><lineRate>93</lineRate></regex>
<regex><pattern>.*.checks.coding.IllegalInstantiationCheck</pattern><branchRate>81</branchRate><lineRate>97</lineRate></regex>
<regex><pattern>.*.checks.coding.ReturnCountCheck</pattern><branchRate>55</branchRate><lineRate>74</lineRate></regex>
<regex><pattern>.*.checks.coding.VariableDeclarationUsageDistanceCheck</pattern><branchRate>90</branchRate><lineRate>98</lineRate></regex>
<regex><pattern>.*.checks.header.AbstractHeaderCheck</pattern><branchRate>90</branchRate><lineRate>87</lineRate></regex>

View File

@ -152,8 +152,8 @@ public final class ReturnCountCheck extends AbstractFormatCheck {
private void visitMethodDef(DetailAST ast) {
contextStack.push(context);
final DetailAST methodNameAST = ast.findFirstToken(TokenTypes.IDENT);
context =
new Context(!getRegexp().matcher(methodNameAST.getText()).find());
final boolean check = !getRegexp().matcher(methodNameAST.getText()).find();
context = new Context(check);
}
/**

View File

@ -23,10 +23,13 @@ import static com.puppycrawl.tools.checkstyle.checks.coding.ReturnCountCheck.MSG
import java.io.File;
import org.junit.Assert;
import org.junit.Test;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class ReturnCountCheckTest extends BaseCheckTestSupport {
@Test
@ -102,4 +105,28 @@ public class ReturnCountCheckTest extends BaseCheckTestSupport {
verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/"
+ "checkstyle/coding/InputReturnCountLambda.java").getCanonicalPath(), expected);
}
@Test
public void testImproperToken() throws Exception {
ReturnCountCheck check = new ReturnCountCheck();
DetailAST classDefAst = new DetailAST();
classDefAst.setType(TokenTypes.CLASS_DEF);
try {
check.visitToken(classDefAst);
Assert.fail();
}
catch (IllegalStateException e) {
// it is OK
}
try {
check.leaveToken(classDefAst);
Assert.fail();
}
catch (IllegalStateException e) {
// it is OK
}
}
}