diff options
author | Andrei Selkin <andreyselkin@gmail.com> | 2015-11-04 14:10:56 +0300 |
---|---|---|
committer | Roman Ivanov <ivanov-jr@mail.ru> | 2015-11-04 06:00:32 -0800 |
commit | a66d414ae6254d11f5c6021cc804a56d250a3595 (patch) | |
tree | 06ba4827a5e67ec985c1762eee245f131de09cad /src/test | |
parent | 880ae00b7b8c90cf4ae0b66685f59b56adaf2aff (diff) | |
download | checkstyle-a66d414ae6254d11f5c6021cc804a56d250a3595.tar.gz |
Issue #2480: Fix skipping validation for non empty classes when allowEmptyTypes is true
Diffstat (limited to 'src/test')
2 files changed, 77 insertions, 0 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundCheckTest.java index 4305a37c0..89d57b7c6 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundCheckTest.java @@ -286,4 +286,48 @@ public class WhitespaceAroundCheckTest }; assertArrayEquals(expected, actual); } + + @Test + public void testAllowEmptyTypesIsSetToFalseAndNonEmptyClasses() throws Exception { + checkConfig.addAttribute("allowEmptyTypes", "false"); + final String[] expected = { + "6:52: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "10:20: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "14:32: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "18:18: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "20:24: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "20:25: " + getCheckMessage(WS_NOT_FOLLOWED, "{"), + "20:31: " + getCheckMessage(WS_NOT_PRECEDED, "}"), + "22:31: " + getCheckMessage(WS_NOT_FOLLOWED, "}"), + "24:18: " + getCheckMessage(WS_NOT_FOLLOWED, "{"), + "24:18: " + getCheckMessage(WS_NOT_PRECEDED, "}"), + "26:69: " + getCheckMessage(WS_NOT_FOLLOWED, "{"), + "26:69: " + getCheckMessage(WS_NOT_PRECEDED, "}"), + "28:24: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "31:13: " + getCheckMessage(WS_NOT_FOLLOWED, "{"), + "31:13: " + getCheckMessage(WS_NOT_PRECEDED, "}"), + }; + verify(checkConfig, getPath("InputAllowEmptyTypesAndNonEmptyClasses.java"), + expected); + } + + @Test + public void testAllowEmptyTypesIsSetToTrueAndNonEmptyClasses() throws Exception { + checkConfig.addAttribute("allowEmptyTypes", "true"); + final String[] expected = { + "6:52: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "10:20: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "14:32: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "18:18: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "20:24: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "20:25: " + getCheckMessage(WS_NOT_FOLLOWED, "{"), + "20:31: " + getCheckMessage(WS_NOT_PRECEDED, "}"), + "22:31: " + getCheckMessage(WS_NOT_FOLLOWED, "}"), + "28:24: " + getCheckMessage(WS_NOT_PRECEDED, "{"), + "31:13: " + getCheckMessage(WS_NOT_FOLLOWED, "{"), + "31:13: " + getCheckMessage(WS_NOT_PRECEDED, "}"), + }; + verify(checkConfig, getPath("InputAllowEmptyTypesAndNonEmptyClasses.java"), + expected); + } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/InputAllowEmptyTypesAndNonEmptyClasses.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/InputAllowEmptyTypesAndNonEmptyClasses.java new file mode 100644 index 000000000..befda3042 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/InputAllowEmptyTypesAndNonEmptyClasses.java @@ -0,0 +1,33 @@ +package com.puppycrawl.tools.checkstyle.checks.whitespace; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; + +public class InputAllowEmptyTypesAndNonEmptyClasses{ + + private Object object; + + class SomeClass{ + int a = 5; + } + + public class CheckstyleTest{ + private static final int SOMETHING = 1; + } + + class MyClass{ int a; } + + class SomeTestClass{int a;} + + class TestClass { int a; }int b; + + class Table {} + + interface SupplierFunction<T> extends Function<Supplier<T>, T> {} + + class NotEmptyClass{ public void foo1() { foo2(); } } + + public void foo2() { + do {} while (true); + } +} |