aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAndrei Selkin <andreyselkin@gmail.com>2015-11-04 14:10:56 +0300
committerRoman Ivanov <ivanov-jr@mail.ru>2015-11-04 06:00:32 -0800
commita66d414ae6254d11f5c6021cc804a56d250a3595 (patch)
tree06ba4827a5e67ec985c1762eee245f131de09cad /src/test
parent880ae00b7b8c90cf4ae0b66685f59b56adaf2aff (diff)
downloadcheckstyle-a66d414ae6254d11f5c6021cc804a56d250a3595.tar.gz
Issue #2480: Fix skipping validation for non empty classes when allowEmptyTypes is true
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundCheckTest.java44
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/InputAllowEmptyTypesAndNonEmptyClasses.java33
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);
+ }
+}