aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTima <timur.tibeyev@bee.kz>2017-03-16 22:49:10 +0600
committerRoman Ivanov <romani@users.noreply.github.com>2017-04-05 04:08:23 -0700
commit7b95603c0e5036f397365a05b68483d0da690c63 (patch)
tree111d075b7f43ff02e2f20a1c2c5369ace1b33912 /src/test
parent33c71142f3a9ea8e4e0fc106b0c3302f317a4cab (diff)
downloadcheckstyle-7b95603c0e5036f397365a05b68483d0da690c63.tar.gz
Issue #3234: ClassDataAbstractionCoupling : Add a regex attribut
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java35
-rw-r--r--src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassFanOutComplexityCheckTest.java32
2 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java
index eded2d38a..557076ccf 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java
@@ -83,4 +83,39 @@ public class ClassDataAbstractionCouplingCheckTest extends BaseCheckTestSupport
assertEquals("Unknown type: ctor[0x-1]", ex.getMessage());
}
}
+
+ @Test
+ public void testRegularExpression() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(ClassDataAbstractionCouplingCheck.class);
+
+ checkConfig.addAttribute("max", "0");
+ checkConfig.addAttribute("excludedClasses", "InnerClass");
+ checkConfig.addAttribute("excludeClassesRegexps", "^Hash.*");
+
+ final String[] expected = {
+ "6:1: " + getCheckMessage(MSG_KEY, 2, 0, "[AnotherInnerClass, int]"),
+ "7:5: " + getCheckMessage(MSG_KEY, 1, 0, "[ArrayList]"),
+ };
+
+ verify(checkConfig, getPath("InputClassCoupling.java"), expected);
+ }
+
+ @Test
+ public void testEmptyRegularExpression() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(ClassDataAbstractionCouplingCheck.class);
+
+ checkConfig.addAttribute("max", "0");
+ checkConfig.addAttribute("excludedClasses", "InnerClass");
+ checkConfig.addAttribute("excludeClassesRegexps", "");
+
+ final String[] expected = {
+ "6:1: " + getCheckMessage(MSG_KEY, 4, 0, "[AnotherInnerClass, HashMap, HashSet, int]"),
+ "7:5: " + getCheckMessage(MSG_KEY, 1, 0, "[ArrayList]"),
+ "27:1: " + getCheckMessage(MSG_KEY, 2, 0, "[HashMap, HashSet]"),
+ };
+
+ verify(checkConfig, getPath("InputClassCoupling.java"), expected);
+ }
}
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassFanOutComplexityCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassFanOutComplexityCheckTest.java
index 301aa207c..d8fec41da 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassFanOutComplexityCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/ClassFanOutComplexityCheckTest.java
@@ -94,4 +94,36 @@ public class ClassFanOutComplexityCheckTest extends BaseCheckTestSupport {
Assert.assertNotNull(actual);
Assert.assertArrayEquals(expected, actual);
}
+
+ @Test
+ public void testRegularExpression() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(ClassFanOutComplexityCheck.class);
+
+ checkConfig.addAttribute("max", "0");
+ checkConfig.addAttribute("excludeClassesRegexps", "^Inner.*");
+
+ final String[] expected = {
+ "6:1: " + getCheckMessage(MSG_KEY, 2, 0),
+ "38:1: " + getCheckMessage(MSG_KEY, 1, 0),
+ };
+
+ verify(checkConfig, getPath("InputClassCoupling.java"), expected);
+ }
+
+ @Test
+ public void testEmptyRegularExpression() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(ClassFanOutComplexityCheck.class);
+
+ checkConfig.addAttribute("max", "0");
+ checkConfig.addAttribute("excludeClassesRegexps", "");
+
+ final String[] expected = {
+ "6:1: " + getCheckMessage(MSG_KEY, 3, 0),
+ "38:1: " + getCheckMessage(MSG_KEY, 1, 0),
+ };
+
+ verify(checkConfig, getPath("InputClassCoupling.java"), expected);
+ }
}