Skip to content

Commit

Permalink
Issue checkstyle#14937: Migrated section 7.3.2 Exception: Overrides t…
Browse files Browse the repository at this point in the history
…o chapter wise testing
  • Loading branch information
Zopsss authored and romani committed Jul 7, 2024
1 parent 122f247 commit b428d09
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ esversion
etsy
ev
Evt
exceptionoverrides
executablestatementcount
Exif
explicitinitialization
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.rule732exceptionoverrides;

import org.junit.jupiter.api.Test;

import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport;

public class ExceptionOverridesTest extends AbstractGoogleModuleTestSupport {

private static final String[] MODULES = {
"MissingJavadocMethod",
"JavadocMethod",
};

@Override
protected String getPackageLocation() {
return "com/google/checkstyle/test/chapter7javadoc/rule732exceptionoverrides";
}

@Test
public void testBothModules() throws Exception {
final String filePath = getPath("InputJavadocMethodAndMissingJavadocMethod.java");
verifyWithConfigParser(MODULES, filePath);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
package com.google.checkstyle.test.chapter7javadoc.rule732exceptionoverrides;

/**
* The following is a bad tag.
* @mytag Hello
*/
public class InputJavadocMethodAndMissingJavadocMethod 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";
}

// 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();
}

@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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ public class XdocsPagesTest {
// until https://github.com/checkstyle/checkstyle/issues/14937
private static final Set<String> PER_MODULE_TESTS_RULES_LIST = Set.of(
"4.8.5 Annotations",
"7.3.1 Exception: self-explanatory methods",
"7.3.2 Exception: overrides"
"7.3.1 Exception: self-explanatory methods"
);

/**
Expand Down
6 changes: 2 additions & 4 deletions src/xdocs/google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,7 @@
</a>
</td>
<td>
<a href="styleguides/google-java-style-20180523/javaguide.html#s7.3.2-javadoc-exception-overrides">
<a href="styleguides/google-java-style-20220203/javaguide.html#s7.3.2-javadoc-exception-overrides">
7.3.2 Exception: overrides</a>
</td>
<td>
Expand All @@ -2331,11 +2331,9 @@
<td>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingJavadocMethod">
config</a><br/>
<a href="https://github.com/checkstyle/checkstyle/blob/master/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/MissingJavadocMethodTest.java">
test</a>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+JavadocMethod">
config</a><br/>
<a href="https://github.com/checkstyle/checkstyle/blob/master/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/JavadocMethodTest.java">
<a href="https://github.com/checkstyle/checkstyle/blob/master/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule732exceptionoverrides/ExceptionOverridesTest.java">
test</a>
</td>
</tr>
Expand Down

0 comments on commit b428d09

Please sign in to comment.