diff options
author | Dmytro Kytsmen <dmitrokytsmen@gmail.com> | 2017-04-20 21:08:50 +0300 |
---|---|---|
committer | Roman Ivanov <romani@users.noreply.github.com> | 2017-04-21 07:50:09 -0700 |
commit | ba3abf6a7a9cc9b5c0deb9e64ae9c964828a6949 (patch) | |
tree | dc6e6bfc3d80ebd07f862dc6f2948e6e5a8a3455 /src | |
parent | ca8dbf6d2beaed5b66a86de29ff2112240fe4ece (diff) | |
download | checkstyle-ba3abf6a7a9cc9b5c0deb9e64ae9c964828a6949.tar.gz |
Issue #4165: Split and Organize Checkstyle inputs by Test for checks in coding package: SimplifyBooleanExpression
Diffstat (limited to 'src')
2 files changed, 92 insertions, 2 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckTest.java index a98d0b835..7e908bdb9 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckTest.java @@ -35,7 +35,9 @@ public class SimplifyBooleanExpressionCheckTest @Override protected String getPath(String filename) throws IOException { return super.getPath("checks" + File.separator - + "coding" + File.separator + filename); + + "coding" + File.separator + + "simplifybooleanexpression" + File.separator + + filename); } @Test @@ -49,7 +51,7 @@ public class SimplifyBooleanExpressionCheckTest "43:16: " + getCheckMessage(MSG_KEY), "43:32: " + getCheckMessage(MSG_KEY), }; - verify(checkConfig, getPath("InputSimplifyBoolean.java"), expected); + verify(checkConfig, getPath("InputSimplifyBooleanExpression.java"), expected); } @Test diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/InputSimplifyBooleanExpression.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/InputSimplifyBooleanExpression.java new file mode 100644 index 000000000..b86453b0b --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/InputSimplifyBooleanExpression.java @@ -0,0 +1,88 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.coding.simplifybooleanexpression; + +/** + Contains boolean logic that can be simplified. + + @author lkuehne + */ +public class InputSimplifyBooleanExpression +{ + + public static boolean isOddMillis() + { + boolean even = System.currentTimeMillis() % 2 == 0; + + // can be simplified to "if (even)" + if (even == true) { + return false; + } + else { + return true; + } + // return can be simplified to "return !even" + } + + public static boolean isOddMillis2() + { + boolean even = System.currentTimeMillis() % 2 == 0; + // can be simplified to "return !even" + if (!even) + return true; + else + return false; + } + + public static boolean giveMeTrue() + { + boolean tt = isOddMillis() || true; + boolean ff = isOddMillis() && false; + return !false || (true != false); + } + + public void tryToProvokeNPE() + { + if (true) { + } + else { + } + + if (true) { + return; + } + else { + return; + } + } + + public boolean ifNoElse() + { + if (isOddMillis()) { + return true; + } + return false; + } + + boolean a() { + boolean asd = false; + boolean dasa = true; + + if (asd) { + return true; + } else { + return dasa; + } + } + + boolean b() { + boolean asd = false; + + if(asd); + else; + + return true; + } +} |