diff options
27 files changed, 443 insertions, 115 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyBlockCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyBlockCheckTest.java index f1931f40f..06c2bdbea 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyBlockCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyBlockCheckTest.java @@ -23,6 +23,9 @@ import static com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck.MSG_ import static com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck.MSG_KEY_BLOCK_NO_STMT; import static org.junit.Assert.assertEquals; +import java.io.File; +import java.io.IOException; + import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -30,6 +33,11 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; public class EmptyBlockCheckTest extends BaseCheckTestSupport { + @Override + protected String getPath(String filename) throws IOException { + return super.getPath("checks" + File.separator + + "blocks" + File.separator + filename); + } /* Additional test for jacoco, since valueOf() * is generated by javac and jacoco reports that @@ -47,14 +55,14 @@ public class EmptyBlockCheckTest final DefaultConfiguration checkConfig = createCheckConfig(EmptyBlockCheck.class); final String[] expected = { - "75:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "77:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "79:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "82:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "178:5: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "206:29: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "208:41: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "219:12: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "33:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "35:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "37:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "40:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "63:5: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "71:29: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "73:41: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "84:12: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -66,11 +74,11 @@ public class EmptyBlockCheckTest createCheckConfig(EmptyBlockCheck.class); checkConfig.addAttribute("option", BlockOption.TEXT.toString()); final String[] expected = { - "75:13: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "try"), - "77:17: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "finally"), - "178:5: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "INSTANCE_INIT"), - "206:29: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "synchronized"), - "219:12: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "STATIC_INIT"), + "33:13: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "try"), + "35:17: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "finally"), + "63:5: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "INSTANCE_INIT"), + "71:29: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "synchronized"), + "84:12: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "STATIC_INIT"), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -82,14 +90,14 @@ public class EmptyBlockCheckTest createCheckConfig(EmptyBlockCheck.class); checkConfig.addAttribute("option", BlockOption.STMT.toString()); final String[] expected = { - "75:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "77:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "79:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "82:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "178:5: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "206:29: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "208:41: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), - "219:12: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "33:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "35:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "37:13: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "40:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "63:5: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "71:29: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "73:41: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), + "84:12: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java index c044a3055..653811013 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java @@ -25,6 +25,9 @@ import static com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.MSG_K import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import java.io.File; +import java.io.IOException; + import org.apache.commons.lang3.ArrayUtils; import org.junit.Before; import org.junit.Test; @@ -41,6 +44,12 @@ public class LeftCurlyCheckTest extends BaseCheckTestSupport { checkConfig = createCheckConfig(LeftCurlyCheck.class); } + @Override + protected String getPath(String filename) throws IOException { + return super.getPath("checks" + File.separator + + "blocks" + File.separator + filename); + } + /* Additional test for jacoco, since valueOf() * is generated by javac and jacoco reports that * valueOf() is uncovered. @@ -62,10 +71,10 @@ public class LeftCurlyCheckTest extends BaseCheckTestSupport { public void testDefault() throws Exception { final String[] expected = { "8:1: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 1), - "12:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "21:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "30:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "39:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "10:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "14:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "18:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "22:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), }; verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); } @@ -74,12 +83,12 @@ public class LeftCurlyCheckTest extends BaseCheckTestSupport { public void testNL() throws Exception { checkConfig.addAttribute("option", LeftCurlyOption.NL.toString()); final String[] expected = { - "49:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), - "53:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), - "58:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), - "62:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), - "67:12: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 12), - "72:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), + "27:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), + "31:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), + "36:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), + "40:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), + "45:12: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 12), + "50:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), }; verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); } @@ -89,16 +98,16 @@ public class LeftCurlyCheckTest extends BaseCheckTestSupport { checkConfig.addAttribute("option", LeftCurlyOption.NLOW.toString()); final String[] expected = { "8:1: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 1), - "12:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "21:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "30:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "39:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), - "49:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), - "53:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), - "58:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), - "62:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), - "67:12: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 12), - "72:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), + "10:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "14:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "18:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "22:5: " + getCheckMessage(MSG_KEY_LINE_PREVIOUS, "{", 5), + "27:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), + "31:14: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 14), + "36:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), + "40:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), + "45:12: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 12), + "50:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "{", 18), }; verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/NeedBracesCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/NeedBracesCheckTest.java index e3b14433f..8133bf1ec 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/NeedBracesCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/NeedBracesCheckTest.java @@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.blocks; import static com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck.MSG_KEY_NEED_BRACES; import java.io.File; +import java.io.IOException; import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; @@ -30,6 +31,18 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; public class NeedBracesCheckTest extends BaseCheckTestSupport { + @Override + protected String getPath(String filename) throws IOException { + return super.getPath("checks" + File.separator + + "blocks" + File.separator + filename); + } + + @Override + protected String getNonCompilablePath(String filename) throws IOException { + return super.getNonCompilablePath("checks" + File.separator + + "blocks" + File.separator + filename); + } + @Test public void testIt() throws Exception { final DefaultConfiguration checkConfig = @@ -85,9 +98,7 @@ public class NeedBracesCheckTest extends BaseCheckTestSupport { final String[] expected = { "7: " + getCheckMessage(MSG_KEY_NEED_BRACES, "->"), }; - verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/" - + "tools/checkstyle/blocks/InputSingleLineLambda.java").getCanonicalPath(), - expected); + verify(checkConfig, getNonCompilablePath("InputSingleLineLambda.java"), expected); } @Test diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java index 2f8ab4de6..047cfa2a4 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java @@ -25,6 +25,9 @@ import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_ import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_SAME; import static org.junit.Assert.assertEquals; +import java.io.File; +import java.io.IOException; + import org.apache.commons.lang3.ArrayUtils; import org.junit.Before; import org.junit.Test; @@ -40,6 +43,12 @@ public class RightCurlyCheckTest extends BaseCheckTestSupport { checkConfig = createCheckConfig(RightCurlyCheck.class); } + @Override + protected String getPath(String filename) throws IOException { + return super.getPath("checks" + File.separator + + "blocks" + File.separator + filename); + } + /* Additional test for jacoco, since valueOf() * is generated by javac and jacoco reports that * valueOf() is uncovered. @@ -160,57 +169,57 @@ public class RightCurlyCheckTest extends BaseCheckTestSupport { + "LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, " + "STATIC_INIT, INSTANCE_INIT"); final String[] expected = { - "9:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), - "12:65: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 65), - "23:46: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 46), - "27:31: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 31), - "30:35: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 35), - "33:36: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 36), - "39:73: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 73), - "41:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37), - "46:58: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 58), - "48:97: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 97), - "51:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30), - "54:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30), - "61:38: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 38), - "68:62: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 62), - "77:28: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 28), - "79:21: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 21), - "81:20: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 20), - "83:14: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 14), - "94:26: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 26), - "104:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29), - "108:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29), - "112:52: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 52), - "112:112: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 112), - "115:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 18), - "119:23: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 23), - "122:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37), - "124:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30), - "128:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), - "137:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), - "139:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), - "149:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), - "151:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75), + "8:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), + "11:65: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 65), + "22:46: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 46), + "26:31: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 31), + "29:35: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 35), + "32:36: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 36), + "38:73: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 73), + "40:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37), + "45:58: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 58), + "47:97: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 97), + "50:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30), + "53:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30), + "60:38: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 38), + "67:62: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 62), + "76:28: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 28), + "78:21: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 21), + "80:20: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 20), + "82:14: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 14), + "93:26: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 26), + "103:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29), + "107:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29), + "111:52: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 52), + "111:112: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 112), + "114:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 18), + "118:23: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 23), + "121:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37), + "123:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30), + "127:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), + "136:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), + "138:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), + "148:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), + "150:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75), + "151:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), + "151:93: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 93), "152:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), - "152:93: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 93), "153:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), - "154:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77), - "154:93: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 93), - "160:37: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 37), - "167:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37), - "182:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), - "189:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), - "189:13: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 13), - "198:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), - "198:10: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 10), - "202:49: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 49), - "202:50: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 50), - "205:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75), - "205:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76), - "205:77: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 77), - "209:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76), - "217:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27), + "153:93: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 93), + "159:37: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 37), + "166:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37), + "181:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), + "188:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), + "188:13: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 13), + "197:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9), + "197:10: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 10), + "201:49: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 49), + "201:50: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 50), + "204:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75), + "204:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76), + "204:77: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 77), + "208:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76), + "216:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27), }; verify(checkConfig, getPath("InputRightCurlyAnnotations.java"), expected); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java index 9c54f9204..52cf2824f 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java @@ -46,7 +46,7 @@ public class ParameterNameCheckTest createCheckConfig(ParameterNameCheck.class); checkConfig.addAttribute("format", "^NO_WAY_MATEY$"); final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputLeftCurlyOther.java"), expected); + verify(checkConfig, getPath("checks/naming/InputCatchOnly.java"), expected); } @Test diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/blocks/InputSingleLineLambda.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/blocks/InputSingleLineLambda.java index 92dd9c38c..82aa043fe 100644 --- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/blocks/InputSingleLineLambda.java +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/blocks/InputSingleLineLambda.java @@ -1,5 +1,5 @@ //Compilable with Java8 -package com.puppycrawl.tools.checkstyle.blocks; +package com.puppycrawl.tools.checkstyle.checks.blocks; public class InputSingleLineLambda { static Runnable r1 = ()->System.out.println("Hello world one!"); diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyAllInOneLine.java b/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyAllInOneLine.java deleted file mode 100644 index 11ec6102d..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyAllInOneLine.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.puppycrawl.tools.checkstyle;import java.lang.annotation.ElementType;import java.lang.annotation.Target;import java.util.ArrayList;import java.util.List;class InputLeftCurlyAllInOneLine{ - - -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java new file mode 100644 index 000000000..702d68d27 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.blocks; + +/** + * Test case for correct use of braces. + * @author Oliver Burn + **/ +class InputBraces +{ + /** @return helper func **/ + boolean condition() + { + return false; + } + + /** Test do/while loops **/ + void testDoWhile() + { + // Valid + do { + testDoWhile(); + } + while (condition()); + + // Invalid + do testDoWhile(); while (condition()); + } + + /** Test while loops **/ + void testWhile() + { + // Valid + while (condition()) { + testWhile(); + } + + // Invalid + while(condition()); + while (condition()) + testWhile(); + while (condition()) + if (condition()) + testWhile(); + } + + /** Test for loops **/ + void testFor() + { + // Valid + for (int i = 1; i < 5; i++) { + testFor(); + } + + // Invalid + for(int i = 1;i < 5;i++); + for (int i = 1; i < 5; i++) + testFor(); + for (int i = 1; i < 5; + i++) + if (i > 2) + testFor(); + } + + /** Test if constructs **/ + public void testIf() + { + // Valid + if (condition()) { + testIf(); + } + else if (condition()) { + testIf(); + } + else { + testIf(); + } + + // Invalid + if (condition()); + if (condition()) + testIf(); + if (condition()) + testIf(); + else + testIf(); + if (condition()) + testIf(); + else { + testIf(); + } + if (condition()) { + testIf(); + } + else + testIf(); + if (condition()) + if (condition()) + testIf(); + } + + void whitespaceAfterSemi() + { + //reject + int i = 1;int j = 2; + + //accept + for (;;) { + } + } + + /** Empty constructor block. **/ + public InputBraces() {} + + /** Empty method block. **/ + public void emptyImplementation() {} +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputBracesSingleLineStatements.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBracesSingleLineStatements.java index 9d04f7fe3..6260ddd82 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputBracesSingleLineStatements.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBracesSingleLineStatements.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; public class InputBracesSingleLineStatements { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java new file mode 100644 index 000000000..b6e33b174 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java @@ -0,0 +1,4 @@ +package com.puppycrawl.tools.checkstyle.checks.blocks;import java.lang.annotation.ElementType;import java.lang.annotation.Target;import java.util.ArrayList;import java.util.List;class InputLeftCurlyAllInOneLine{ + + +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyAnnotations.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAnnotations.java index a63b4f8d7..5b5f94ba5 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyAnnotations.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAnnotations.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; import java.lang.annotation.ElementType; import java.lang.annotation.Target; diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyEnums.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyEnums.java index 28c592a3f..5406cb528 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyEnums.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyEnums.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; public class InputLeftCurlyEnums { enum Colors {RED, diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyLineBreakAfter.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyLineBreakAfter.java index 9b8040d76..a25324491 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyLineBreakAfter.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyLineBreakAfter.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; import java.lang.annotation.ElementType; import java.lang.annotation.Target; diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyMethod.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyMethod.java index 57794df9d..bcfc7384f 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyMethod.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyMethod.java @@ -2,7 +2,7 @@ // Test case file for checkstyle. // Created: 2001 //////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; /** * Test case for correct use of braces. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyOther.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyOther.java index 0b79b495b..42c51c7dd 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputLeftCurlyOther.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyOther.java @@ -2,7 +2,7 @@ // Test case file for checkstyle. // Created: 2001 //////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; /** * Test case for correct use of braces. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputNeedBracesCheckTest.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputNeedBracesCheckTest.java index 93f34c0f3..6f0f40ec9 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputNeedBracesCheckTest.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputNeedBracesCheckTest.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; public class InputNeedBracesCheckTest { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurly.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurly.java index b2b2d0d60..9b8562845 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurly.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurly.java @@ -2,7 +2,7 @@ // Test case file for checkstyle. // Created: 2001 //////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; class InputRightCurly { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyAloneOrSingleline.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAloneOrSingleline.java index 5988e11af..de27350d3 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyAloneOrSingleline.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAloneOrSingleline.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; public class InputRightCurlyAloneOrSingleline { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyAnnotations.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAnnotations.java index 72f3a5cf0..7802a0274 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyAnnotations.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAnnotations.java @@ -1,6 +1,5 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; -@TestClassAnnotation class InputRightCurlyAnnotations { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyEmptyAbstractMethod.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyEmptyAbstractMethod.java index 582f23257..c142bd0fb 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyEmptyAbstractMethod.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyEmptyAbstractMethod.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; abstract class CharSequenceReader{ abstract void moveTo(double deltaX, double deltaY); diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyLineBreakBefore.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyLineBreakBefore.java index 7ffa37d2d..15e953162 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyLineBreakBefore.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyLineBreakBefore.java @@ -1,4 +1,4 @@ -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; import java.lang.annotation.ElementType; import java.lang.annotation.Target; diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyNameForOneLiners.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyNameForOneLiners.java index c5e6da826..6f7ecc23f 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputRightCurlyNameForOneLiners.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyNameForOneLiners.java @@ -2,7 +2,7 @@ // Test case file for checkstyle. // Created: 2015 //////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; /** * Test case for RightCurly with option SAME to omit oneliners diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java new file mode 100644 index 000000000..ecabce5da --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.blocks; + +public class InputScopeInnerInterfaces +{ + private interface PrivateInterface + { + } + + interface PackageInnerInterface + { + } + + protected interface ProtectedInnerInterface + { + } + + public interface PublicInnerInterface + { + } + + private + class + MyClass1 { + } + + class + MyClass2 { + } + + private + interface + MyInterface1 { + } + + interface + MyInterface2 { + } + + protected + enum + MyEnum { + } + + private + @interface + MyAnnotation { + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces2.java index fbef2f51c..2540fc540 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces2.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces2.java @@ -2,7 +2,7 @@ // Test case file for checkstyle. // Created: 2001 //////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; public class InputScopeInnerInterfaces2{ // inner interfaces with different scopes diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java new file mode 100644 index 000000000..94cda5d53 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java @@ -0,0 +1,87 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.blocks; + +import java.io.*; // star import for instantiation tests +import java.awt.Dimension; // explicit import for instantiation tests +import java.awt.Color; + +/** + * Test case for detecting empty block statements. + * @author Lars Kühne + **/ +class InputSemantic +{ + static { + Boolean x = new Boolean(true); + } + + { + Boolean x = new Boolean(true); + Boolean[] y = new Boolean[]{Boolean.TRUE, Boolean.FALSE}; + } + + Boolean getBoolean() + { + return new java.lang.Boolean(true); + } + + void exHandlerTest() + { + try { + } + finally { + } + try { + // something + } + finally { + // something + } + try { + ; // something + } + finally { + ; // statement + } + } + + /** test **/ + private static final long IGNORE = 666l + 666L; + + public class EqualsVsHashCode1 + { + public boolean equals(int a) + { + return a == 1; + } + } + + // empty instance initializer + { + } + + private class InputBraces { + + } + + synchronized void foo() { + synchronized (this) {} // not OK + synchronized (Class.class) { // OK + synchronized (new Object()) { + // not OK if checking statements + } + } + } + + + static { + + int a = 0;} + + static { + + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputSemantic2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic2.java index e95753184..a85c38998 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/InputSemantic2.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic2.java @@ -2,7 +2,7 @@ // Test case file for checkstyle. // Created: 2001 //////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; +package com.puppycrawl.tools.checkstyle.checks.blocks; import java.io.*; // star import for instantiation tests import java.awt.Dimension; // explicit import for instantiation tests diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java new file mode 100644 index 000000000..ac1a01a11 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java @@ -0,0 +1,34 @@ +package com.puppycrawl.tools.checkstyle.checks.naming; + +/** + * Test case for skipping over catch names. + **/ +public class InputCatchOnly { + int foo() { + if (System.currentTimeMillis() > 1000) + return 1; + + int test = 0; + + try + { + return 1; + } + catch (Exception e) + { + return 0; + } + } + + public InputCatchOnly() + { + return; + } + + class InnerFoo + { + public void fooInnerMethod () + { + } + } +} |