From 5320065461ca38393ab2402c7402cc8f65c331d4 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Thu, 30 Sep 2010 17:09:25 +1000 Subject: [PATCH] The start of a test case. --- .../checks/metrics/MethodCountCheck.java | 31 ++- .../checks/metrics/MethodCountCheckInput.java | 191 ++++++++++++++++++ .../checks/metrics/MethodCountCheckTest.java | 13 ++ 3 files changed, 217 insertions(+), 18 deletions(-) create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckInput.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckTest.java diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheck.java index 4ea064df8..c1131c943 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheck.java @@ -34,21 +34,6 @@ import java.util.EnumMap; */ public final class MethodCountCheck extends Check { - /** default maximum number of methods */ - private static final int DEFAULT_MAX_METHODS = 999; - - /** Maximum private methods. */ - private int mMaxPrivate = DEFAULT_MAX_METHODS; - /** Maximum package methods. */ - private int mMaxPackage = DEFAULT_MAX_METHODS; - /** Maximum protected methods. */ - private int mMaxProtected = DEFAULT_MAX_METHODS; - /** Maximum public methods. */ - private int mMaxPublic = DEFAULT_MAX_METHODS; - /** Maximum total number of methods. */ - private int mMaxTotal = DEFAULT_MAX_METHODS; - - /** * Marker class used to collect data about the number of methods per * class. Objects of this class are used on the Stack to count the @@ -80,9 +65,19 @@ public final class MethodCountCheck extends Check } }; - /** - * To be able to trace also inner-classes correctly we need a stack. - */ + /** default maximum number of methods */ + private static final int DEFAULT_MAX_METHODS = 999; + /** Maximum private methods. */ + private int mMaxPrivate = DEFAULT_MAX_METHODS; + /** Maximum package methods. */ + private int mMaxPackage = DEFAULT_MAX_METHODS; + /** Maximum protected methods. */ + private int mMaxProtected = DEFAULT_MAX_METHODS; + /** Maximum public methods. */ + private int mMaxPublic = DEFAULT_MAX_METHODS; + /** Maximum total number of methods. */ + private int mMaxTotal = DEFAULT_MAX_METHODS; + /** Maintains stack of counters, to support inner types. */ private FastStack mCounters = new FastStack(); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckInput.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckInput.java new file mode 100644 index 000000000..9c4a47951 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckInput.java @@ -0,0 +1,191 @@ +package com.puppycrawl.tools.checkstyle.checks.metrics; + +public class MethodCountCheckInput { + + /** + * Dummy inner class to check that the inner-classes methods are not counted + * for the outer class. + */ + public class PublicMethodsInnerclassInnerclass { + /** + * Dummy method doing nothing + */ + public void doNothing50() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing51() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing52() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing53() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing54() { + } + } + + /** + * Dummy inner class to check that the inner-classes methods are not counted + * for the outer class. + */ + public interface PublicMethodsInnerInterface { + /** + * Dummy method doing nothing + */ + public void doNothing60(); + + /** + * Dummy method doing nothing + */ + public void doNothing61(); + + /** + * Dummy method doing nothing + */ + public void doNothing62(); + + /** + * Dummy method doing nothing + */ + public void doNothing63(); + + /** + * Dummy method doing nothing + */ + public void doNothing64(); + } + + /** + * Dummy method doing nothing + */ + public void doNothing00() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing01() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing02() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing03() { + } + + /** + * Dummy method doing nothing + */ + public void doNothing04() { + } + + /** + * Dummy method doing nothing + */ + protected void doNothing10() { + } + + /** + * Dummy method doing nothing + */ + protected void doNothing11() { + } + + /** + * Dummy method doing nothing + */ + protected void doNothing12() { + } + + /** + * Dummy method doing nothing + */ + protected void doNothing13() { + } + + /** + * Dummy method doing nothing + */ + protected void doNothing14() { + } + + /** + * Dummy method doing nothing + */ + void doNothing20() { + } + + /** + * Dummy method doing nothing + */ + void doNothing21() { + } + + /** + * Dummy method doing nothing + */ + void doNothing22() { + } + + /** + * Dummy method doing nothing + */ + void doNothing23() { + } + + /** + * Dummy method doing nothing + */ + void doNothing24() { + } + + /** + * Dummy method doing nothing + */ + private void doNothing30() { + } + + /** + * Dummy method doing nothing + */ + private void doNothing31() { + } + + /** + * Dummy method doing nothing + */ + private void doNothing32() { + } + + /** + * Dummy method doing nothing + */ + private void doNothing33() { + } + + /** + * Dummy method doing nothing + */ + private void doNothing34() { + } +} \ No newline at end of file diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckTest.java new file mode 100644 index 000000000..ac720a251 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/MethodCountCheckTest.java @@ -0,0 +1,13 @@ +package com.puppycrawl.tools.checkstyle.checks.metrics; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class MethodCountCheckTest { + + @Test + public void testSomeMethod() { + fail("Need to implement"); + } + +} \ No newline at end of file