Issue #1287: 'BooleanExpressionComplexityCheck' refactored, UT coverage improved
This commit is contained in:
parent
22d40e6bfd
commit
37fe13f3f1
1
pom.xml
1
pom.xml
|
|
@ -1127,7 +1127,6 @@
|
|||
|
||||
<regex><pattern>.*.checks.metrics.AbstractClassCouplingCheck</pattern><branchRate>87</branchRate><lineRate>97</lineRate></regex>
|
||||
<regex><pattern>.*.checks.metrics.AbstractClassCouplingCheck\$.*</pattern><branchRate>78</branchRate><lineRate>100</lineRate></regex>
|
||||
<regex><pattern>.*.checks.metrics.BooleanExpressionComplexityCheck</pattern><branchRate>74</branchRate><lineRate>80</lineRate></regex>
|
||||
|
||||
<regex><pattern>.*.checks.regexp.CommentSuppressor</pattern><branchRate>75</branchRate><lineRate>100</lineRate></regex>
|
||||
<regex><pattern>.*.checks.regexp.DetectorOptions</pattern><branchRate>100</branchRate><lineRate>96</lineRate></regex>
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public final class BooleanExpressionComplexityCheck extends Check {
|
|||
context.visitBooleanOperator();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(ast.toString());
|
||||
throw new IllegalArgumentException("Unknown type: " + ast);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +186,8 @@ public final class BooleanExpressionComplexityCheck extends Check {
|
|||
*/
|
||||
private void visitMethodDef(DetailAST ast) {
|
||||
contextStack.push(context);
|
||||
context = new Context(!CheckUtils.isEqualsMethod(ast));
|
||||
final boolean check = !CheckUtils.isEqualsMethod(ast);
|
||||
context = new Context(check);
|
||||
}
|
||||
|
||||
/** Removes old context. */
|
||||
|
|
@ -197,7 +198,7 @@ public final class BooleanExpressionComplexityCheck extends Check {
|
|||
/** Creates and pushes new context. */
|
||||
private void visitExpr() {
|
||||
contextStack.push(context);
|
||||
context = new Context(context == null || context.isChecking());
|
||||
context = new Context(context.isChecking());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,8 +25,12 @@ import java.io.File;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import antlr.CommonHiddenStreamToken;
|
||||
|
||||
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 BooleanExpressionComplexityCheckTest extends BaseCheckTestSupport {
|
||||
@Test
|
||||
|
|
@ -67,4 +71,12 @@ public class BooleanExpressionComplexityCheckTest extends BaseCheckTestSupport {
|
|||
|
||||
verify(checkConfig, getPath("metrics" + File.separator + "InputBooleanExpressionComplexityNPE.java"), expected);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWrongToken() {
|
||||
BooleanExpressionComplexityCheck booleanExpressionComplexityCheckObj = new BooleanExpressionComplexityCheck();
|
||||
DetailAST ast = new DetailAST();
|
||||
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
|
||||
booleanExpressionComplexityCheckObj.visitToken(ast);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue