diff options
author | Andrei Selkin <andreyselkin@gmail.com> | 2015-10-31 14:57:33 +0300 |
---|---|---|
committer | Roman Ivanov <ivanov-jr@mail.ru> | 2015-10-31 15:48:32 -0700 |
commit | 866daeeb2ad31e6a5a78235aa46819d9f966ee1c (patch) | |
tree | cf0b244dba4b5dadefabe97b0666cf9439c0f76d /src/test/java | |
parent | c56dce9222a819b4741b4c0cd664d38c58b31050 (diff) | |
download | checkstyle-866daeeb2ad31e6a5a78235aa46819d9f966ee1c.tar.gz |
Issue #2078: Update UTs for CommentsIndentationCheck
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java | 118 |
1 files changed, 110 insertions, 8 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java index 0ba54adb9..e5a7b45c0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java @@ -37,9 +37,11 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; /** * * @author <a href="mailto:nesterenko-aleksey@list.ru">Aleksey Nesterenko</a> +* @author <a href="mailto:andreyselkin@gmail.com">Aleksey Nesterenko</a> * */ public class CommentsIndentationCheckTest extends BaseCheckTestSupport { + @Override protected String getPath(String filename) throws IOException { return super.getPath("checks" + File.separator @@ -47,6 +49,84 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport { } @Test + public void testCommentIsAtTheEndOfBlock() throws Exception { + final DefaultConfiguration checkConfig = + createCheckConfig(CommentsIndentationCheck.class); + final String[] expected = { + "18: " + getCheckMessage(MSG_KEY_SINGLE, 17, 25, 8), + "33: " + getCheckMessage(MSG_KEY_SINGLE, 35, 5, 4), + "37: " + getCheckMessage(MSG_KEY_SINGLE, 36, 0, 8), + "47: " + getCheckMessage(MSG_KEY_SINGLE, 46, 15, 12), + "49: " + getCheckMessage(MSG_KEY_SINGLE, 48, 10, 8), + "54: " + getCheckMessage(MSG_KEY_SINGLE, 53, 13, 8), + "74: " + getCheckMessage(MSG_KEY_SINGLE, 70, 18, 8), + "88: " + getCheckMessage(MSG_KEY_SINGLE, 85, 31, 8), + "100: " + getCheckMessage(MSG_KEY_SINGLE, 98, 21, 8), + "115: " + getCheckMessage(MSG_KEY_SINGLE, 116, 29, 12), + "138: " + getCheckMessage(MSG_KEY_SINGLE, 131, 26, 8), + "164: " + getCheckMessage(MSG_KEY_SINGLE, 161, 33, 8), + "174: " + getCheckMessage(MSG_KEY_SINGLE, 173, 21, 8), + "186: " + getCheckMessage(MSG_KEY_SINGLE, 184, 34, 8), + "208: " + getCheckMessage(MSG_KEY_SINGLE, 206, 26, 8), + "214: " + getCheckMessage(MSG_KEY_SINGLE, 213, 0, 8), + "228: " + getCheckMessage(MSG_KEY_SINGLE, 225, 12, 8), + "234: " + getCheckMessage(MSG_KEY_SINGLE, 233, 0, 8), + "248: " + getCheckMessage(MSG_KEY_SINGLE, 245, 12, 8), + "255: " + getCheckMessage(MSG_KEY_SINGLE, 252, 0, 8), + "265: " + getCheckMessage(MSG_KEY_SINGLE, 264, 14, 8), + "271: " + getCheckMessage(MSG_KEY_SINGLE, 269, 9, 8), + "277: " + getCheckMessage(MSG_KEY_SINGLE, 276, 9, 8), + "316: " + getCheckMessage(MSG_KEY_SINGLE, 315, 9, 8), + "322: " + getCheckMessage(MSG_KEY_SINGLE, 323, 0, 4), + "336: " + getCheckMessage(MSG_KEY_SINGLE, 337, 0, 4), + "355: " + getCheckMessage(MSG_KEY_SINGLE, 352, 9, 8), + }; + final String testInputFile = "InputCommentsIndentationCommentIsAtTheEndOfBlock.java"; + verify(checkConfig, getPath(testInputFile), expected); + } + + @Test + public void testCommentIsInsideSwitchBlock() throws Exception { + final DefaultConfiguration checkConfig = + createCheckConfig(CommentsIndentationCheck.class); + final String[] expected = { + "25: " + getCheckMessage(MSG_KEY_SINGLE, "24, 26", 19, "16, 12"), + "31: " + getCheckMessage(MSG_KEY_SINGLE, "30, 32", 19, "16, 12"), + "48: " + getCheckMessage(MSG_KEY_SINGLE, 49, 6, 16), + "55: " + getCheckMessage(MSG_KEY_SINGLE, 56, 8, 12), + "59: " + getCheckMessage(MSG_KEY_SINGLE, 58, 22, 16), + "68: " + getCheckMessage(MSG_KEY_SINGLE, "65, 69", 14, "12, 16"), + "88: " + getCheckMessage(MSG_KEY_SINGLE, 89, 24, 20), + "113: " + getCheckMessage(MSG_KEY_SINGLE, "112, 114", 15, "17, 12"), + "125: " + getCheckMessage(MSG_KEY_SINGLE, 126, 8, 12), + "138: " + getCheckMessage(MSG_KEY_SINGLE, 139, 4, 8), + "157: " + getCheckMessage(MSG_KEY_SINGLE, "156, 158", 18, "16, 12"), + "200: " + getCheckMessage(MSG_KEY_SINGLE, "199, 201", 4, "12, 12"), + "203: " + getCheckMessage(MSG_KEY_SINGLE, 204, 22, 20), + "204: " + getCheckMessage(MSG_KEY_SINGLE, 205, 20, 17), + "205: " + getCheckMessage(MSG_KEY_SINGLE, "202, 206", 17, "16, 12"), + "229: " + getCheckMessage(MSG_KEY_SINGLE, "228, 230", 6, "12, 12"), + }; + final String testInputFile = "InputCommentsIndentationInSwitchBlock.java"; + verify(checkConfig, getPath(testInputFile), expected); + } + + @Test + public void testCommentIsInsideEmptyBlock() throws Exception { + final DefaultConfiguration checkConfig = + createCheckConfig(CommentsIndentationCheck.class); + final String[] expected = { + "9: " + getCheckMessage(MSG_KEY_SINGLE, 10, 19, 23), + "10: " + getCheckMessage(MSG_KEY_BLOCK, 12, 23, 31), + "33: " + getCheckMessage(MSG_KEY_SINGLE, 34, 0, 8), + "57: " + getCheckMessage(MSG_KEY_SINGLE, 58, 0, 8), + "71: " + getCheckMessage(MSG_KEY_SINGLE, 72, 0, 8), + }; + final String testInputFile = "InputCommentsIndentationInEmptyBlock.java"; + verify(checkConfig, getPath(testInputFile), expected); + } + + @Test public void testSurroundingCode() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(CommentsIndentationCheck.class); @@ -57,30 +137,52 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport { "28: " + getCheckMessage(MSG_KEY_BLOCK, 31, 16, 12), "50: " + getCheckMessage(MSG_KEY_SINGLE, 51, 27, 23), "51: " + getCheckMessage(MSG_KEY_BLOCK, 53, 23, 36), - "136: " + getCheckMessage(MSG_KEY_SINGLE, 137, 20, 16), + "90: " + getCheckMessage(MSG_KEY_SINGLE, 91, 14, 8), + "98: " + getCheckMessage(MSG_KEY_SINGLE, 99, 13, 8), + "108: " + getCheckMessage(MSG_KEY_SINGLE, 109, 33, 8), }; - verify(checkConfig, getPath("InputCommentsIndentationSurroundingCode.java"), expected); + final String testInputFile = "InputCommentsIndentationSurroundingCode.java"; + verify(checkConfig, getPath(testInputFile), expected); } @Test - public void testNpe() throws Exception { + public void testNoNpeWhenBlockCommentEndsClassFile() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(CommentsIndentationCheck.class); final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputCommentsIndentationNpe.java"), expected); + final String testInputFile = "InputCommentsIndentationNoNpe.java"; + verify(checkConfig, getPath(testInputFile), expected); } @Test - public void testTokens() throws Exception { + public void testCheckOnlySingleLineComments() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(CommentsIndentationCheck.class); checkConfig.addAttribute("tokens", "SINGLE_LINE_COMMENT"); final String[] expected = { "13: " + getCheckMessage(MSG_KEY_SINGLE, 14, 14, 12), "50: " + getCheckMessage(MSG_KEY_SINGLE, 51, 27, 23), - "136: " + getCheckMessage(MSG_KEY_SINGLE, 137, 20, 16), + "90: " + getCheckMessage(MSG_KEY_SINGLE, 91, 14, 8), + "98: " + getCheckMessage(MSG_KEY_SINGLE, 99, 13, 8), + "108: " + getCheckMessage(MSG_KEY_SINGLE, 109, 33, 8), }; - verify(checkConfig, getPath("InputCommentsIndentationSurroundingCode.java"), expected); + final String testInputFile = "InputCommentsIndentationSurroundingCode.java"; + verify(checkConfig, getPath(testInputFile), expected); + } + + @Test + public void testCheckOnlyBlockComments() throws Exception { + final DefaultConfiguration checkConfig = + createCheckConfig(CommentsIndentationCheck.class); + checkConfig.addAttribute("tokens", "BLOCK_COMMENT_BEGIN"); + final String[] expected = { + "23: " + getCheckMessage(MSG_KEY_BLOCK, 24, 16, 12), + "25: " + getCheckMessage(MSG_KEY_BLOCK, 27, 16, 12), + "28: " + getCheckMessage(MSG_KEY_BLOCK, 31, 16, 12), + "51: " + getCheckMessage(MSG_KEY_BLOCK, 53, 23, 36), + }; + final String testInputFile = "InputCommentsIndentationSurroundingCode.java"; + verify(checkConfig, getPath(testInputFile), expected); } @Test @@ -91,7 +193,7 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport { methodDef.setText("methodStub"); try { check.visitToken(methodDef); - Assert.fail(); + Assert.fail("IllegalArgumentException should have been thrown!"); } catch (IllegalArgumentException e) { final String msg = e.getMessage(); |