From f5504ef9110e9b593284d917ec1a3d137a989cda Mon Sep 17 00:00:00 2001 From: Mauryan Kansara Date: Fri, 5 Jul 2024 14:26:38 +0530 Subject: [PATCH] Issue #14937: Migrated section 7.3.1 Exception: self-explanatory methods to chapter wise testing --- ... ExceptionSelfExplanatoryMembersTest.java} | 21 +- .../MissingJavadocMethodTest.java | 50 ----- ...tJavadocMethodAndMissingJavadocMethod.java | 206 ++++++++++++++++++ .../InputJavadocMethodCheck.java | 108 --------- .../InputMissingJavadocMethodCheck.java | 107 --------- .../checkstyle/internal/XdocsPagesTest.java | 3 +- src/xdocs/google_style.xml | 8 +- 7 files changed, 219 insertions(+), 284 deletions(-) rename src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/{JavadocMethodTest.java => ExceptionSelfExplanatoryMembersTest.java} (71%) delete mode 100644 src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/MissingJavadocMethodTest.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java delete mode 100644 src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodCheck.java delete mode 100644 src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputMissingJavadocMethodCheck.java diff --git a/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/JavadocMethodTest.java b/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/ExceptionSelfExplanatoryMembersTest.java similarity index 71% rename from src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/JavadocMethodTest.java rename to src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/ExceptionSelfExplanatoryMembersTest.java index 02ed495d1e0..00dfc52b5d2 100644 --- a/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/JavadocMethodTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/ExceptionSelfExplanatoryMembersTest.java @@ -22,10 +22,13 @@ import org.junit.jupiter.api.Test; import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; -import com.puppycrawl.tools.checkstyle.api.Configuration; -import com.puppycrawl.tools.checkstyle.utils.CommonUtil; -public class JavadocMethodTest extends AbstractGoogleModuleTestSupport { +public class ExceptionSelfExplanatoryMembersTest extends AbstractGoogleModuleTestSupport { + + private static final String[] MODULES = { + "MissingJavadocMethod", + "JavadocMethod", + }; @Override protected String getPackageLocation() { @@ -33,15 +36,9 @@ protected String getPackageLocation() { } @Test - public void testJavadocMethod() throws Exception { - - final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - - final Configuration checkConfig = getModuleConfig("JavadocMethod"); - final String filePath = getPath("InputJavadocMethodCheck.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); + public void testBothModules() throws Exception { + final String filePath = getPath("InputJavadocMethodAndMissingJavadocMethod.java"); + verifyWithConfigParser(MODULES, filePath); } } diff --git a/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/MissingJavadocMethodTest.java b/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/MissingJavadocMethodTest.java deleted file mode 100644 index 3baccd20950..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/MissingJavadocMethodTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter7javadoc.rule731selfexplanatory; - -import org.junit.jupiter.api.Test; - -import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; -import com.puppycrawl.tools.checkstyle.api.Configuration; -import com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck; - -public class MissingJavadocMethodTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory"; - } - - @Test - public void testJavadocMethod() throws Exception { - final String msg = getCheckMessage(MissingJavadocMethodCheck.class, "javadoc.missing"); - - final String[] expected = { - "57:5: " + msg, - }; - - final Configuration checkConfig = getModuleConfig("MissingJavadocMethod"); - final String filePath = getPath("InputMissingJavadocMethodCheck.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java new file mode 100644 index 00000000000..de60f096fdf --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java @@ -0,0 +1,206 @@ +package com.google.checkstyle.test.chapter7javadoc.rule731selfexplanatory; + +/** + * The following is a bad tag. + * @mytag Hello + */ +public class InputJavadocMethodAndMissingJavadocMethod extends OverrideClasss +{ + //with comments + + /** + * Some javadoc. + * @return Some javadoc. + */ + int foo1() + { + return 1; + } + + /** + * Some javadoc. + * + */ + String foo2() + { + return "Fooooooooooooooo" + + "ooooo" + + "ooo"; + } + + /** + * Some javadoc. + */ + void foo3() + { + foo2(); + } + + /** + * Some javadoc. + */ + void foo4() {} + + //without comments + + int foo5() + { + return 1; + } + + String foo6() + { + return "Fooooooooooooooo" + + "oooooooo"; + } + + // violation below 'Missing a Javadoc comment.' + public String foo7() + { + return "Fooooooooooooooo" + + "ooooo" + + "ooo"; + } + + // ok, private method does not require javadoc + private String correct(String param) { + return "Fooooooooooooooo" + + "ooooo" + + "ooo" + + param; + } + + // ok, default scope method does not require javadoc + String defaultScope(int x) { + return "Fooooooooooooooo" + + "ooooo" + + "ooo" + + x; + } + + // ok, methods smaller than 2 lines does not require javadoc + public void smallMethod1() { + foo2(); + } + + // ok, methods smaller than 2 lines does not require javadoc + protected void smallMethod2() { + foo2(); + } + + /** + * Ok, missing params tags and return tags in javadoc are allowed + */ + public String testingParams(String param1, String param2) { + return "Fooooooooooooooo" + + "ooooo" + + "ooo" + + param1 + + param2; + } + + /** + * Ok, missing params tags and return tags in javadoc are allowed + */ + protected String testingParams(int param1, int param2) { + return "Fooooooooooooooo" + + "ooooo" + + "ooo" + + param1 + + param2; + } + + + // violation below 'Missing a Javadoc comment.' + public InputJavadocMethodAndMissingJavadocMethod() { + foo2(); + foo91(); + foo4(); + foo3(); + } + + // ok, private constructor does not require javadoc + private InputJavadocMethodAndMissingJavadocMethod(float x) { + foo2(); + foo91(); + foo4(); + foo3(); + } + + // ok, default scope constructor does not require javadoc + InputJavadocMethodAndMissingJavadocMethod(int a) { + foo2(); + foo91(); + foo4(); + foo3(); + } + + // ok, constructors smaller than 2 lines does not require javadoc + public InputJavadocMethodAndMissingJavadocMethod(int a, int b) { + foo2(); + } + + // ok, constructors smaller than 2 lines does not require javadoc + private InputJavadocMethodAndMissingJavadocMethod(float a, float b) { + foo2(); + } + + /** + * Ok, missing params tags in javadoc are allowed + */ + public InputJavadocMethodAndMissingJavadocMethod(double a, double b) { + foo2(); + foo91(); + foo5(); + foo82(); + } + + void foo81() + { + foo2(); + } + + void foo82() { + + + + + + } + + void paramviolation(String param) { + foo2(); + } + + @MyAnnotationn + String foo91() + { + return "Fooooooooooooooo" + + "ooooo" + + "ooo"; + } + + @Override + public String foo92() + { + return "Fooooo" + + "ooo" + + "ooooooo" + + "ooooo" + + "ooo"; + } +} + + +class OverrideClasss { + + public String foo92() + { + return "Fooooo" + + "ooo" + + "ooooooo" + + "ooooo" + + "ooo"; + } +} +@interface MyAnnotationn {} diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodCheck.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodCheck.java deleted file mode 100644 index edea005def5..00000000000 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodCheck.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.google.checkstyle.test.chapter7javadoc.rule731selfexplanatory; - -/** - * The following is a bad tag. - * @mytag Hello - */ -public class InputJavadocMethodCheck extends OverrideClass -{ - //with comments - - /** - * Some javadoc. - * @return Some javadoc. - */ - int foo1() - { - return 1; - } - - /** - * Some javadoc. - * - */ - String foo2() - { - return "Fooooooooooooooo" - + "ooooo" - + "ooo"; - } - - /** - * Some javadoc. - */ - void foo3() - { - foo2(); - } - - /** - * Some javadoc. - */ - void foo4() {} - - //without comments - - int foo5() - { - return 1; - } - - String foo6() - { - return "Fooooooooooooooo" - + "oooooooo"; - } - - public String foo7() - { - return "Fooooooooooooooo" - + "ooooo" - + "ooo"; - } - - void foo81() - { - foo2(); - } - - void foo82() { - - - - - - } - - @MyAnnotation - String foo91() - { - return "Fooooooooooooooo" - + "ooooo" - + "ooo"; - } - - @Override - public String foo92() - { - return "Fooooo" - + "ooo" - + "ooooooo" - + "ooooo" - + "ooo"; - } -} - - -class OverrideClass { - - public String foo92() - { - return "Fooooo" - + "ooo" - + "ooooooo" - + "ooooo" - + "ooo"; - } -} -@interface MyAnnotation {} diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputMissingJavadocMethodCheck.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputMissingJavadocMethodCheck.java deleted file mode 100644 index 263f548dcf0..00000000000 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputMissingJavadocMethodCheck.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.google.checkstyle.test.chapter7javadoc.rule731selfexplanatory; - -/** - * The following is a bad tag. - * @mytag Hello - */ -public class InputMissingJavadocMethodCheck extends OverrideClass -{ - //with comments - - /** - * Some javadoc. - * @return Some javadoc. - */ - int foo1() - { - return 1; - } - - /** - * Some javadoc. - * - */ - String foo2() - { - return "Fooooooooooooooo" - + "ooooo" - + "ooo"; - } - - /** - * Some javadoc. - */ - void foo3() - { - foo2(); - } - - /** - * Some javadoc. - */ - void foo4() {} - - //without comments - - int foo5() - { - return 1; - } - - String foo6() - { - return "Fooooooooooooooo" - + "oooooooo"; - } - - public String foo7() //warn - { - return "Fooooooooooooooo" - + "ooooo" - + "ooo"; - } - - void foo81() - { - foo2(); - } - - void foo82() { - - - - - - } - - @MyAnnotation - String foo91() - { - return "Fooooooooooooooo" - + "ooooo" - + "ooo"; - } - - @Override - public String foo92() - { - return "Fooooo" - + "ooo" - + "ooooooo" - + "ooooo" - + "ooo"; - } -} - - -class MissingOverrideClass { - - public String foo92() - { - return "Fooooo" - + "ooo" - + "ooooooo" - + "ooooo" - + "ooo"; - } -} diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java index 69e40024fd2..2a9e8fa2f13 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java @@ -231,8 +231,7 @@ public class XdocsPagesTest { // This list will be removed once all the sections are migrated. // until https://github.com/checkstyle/checkstyle/issues/14937 private static final Set PER_MODULE_TESTS_RULES_LIST = Set.of( - "4.8.5 Annotations", - "7.3.1 Exception: self-explanatory methods" + "4.8.5 Annotations" ); /** diff --git a/src/xdocs/google_style.xml b/src/xdocs/google_style.xml index 6fe3d0aaa2b..7910a89a93a 100644 --- a/src/xdocs/google_style.xml +++ b/src/xdocs/google_style.xml @@ -2267,8 +2267,8 @@ - - 7.3.1 Exception: self-explanatory methods + + 7.3.1 Exception: self-explanatory members @@ -2289,11 +2289,9 @@ config
- - test config
- + test