forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#14937: Migrated section 7.3.2 Exception: Overrides t…
…o chapter wise testing
- Loading branch information
Showing
5 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,7 @@ esversion | |
etsy | ||
ev | ||
Evt | ||
exceptionoverrides | ||
executablestatementcount | ||
Exif | ||
explicitinitialization | ||
|
44 changes: 44 additions & 0 deletions
44
...gle/checkstyle/test/chapter7javadoc/rule732exceptionoverrides/ExceptionOverridesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
206 changes: 206 additions & 0 deletions
206
.../chapter7javadoc/rule732exceptionoverrides/InputJavadocMethodAndMissingJavadocMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters