Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #13345: Enabled MutableExceptionCheckExamplesTest #14796

Merged
merged 1 commit into from Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,12 +19,12 @@

package com.puppycrawl.tools.checkstyle.checks.design;

import org.junit.jupiter.api.Disabled;
import static com.puppycrawl.tools.checkstyle.checks.design.MutableExceptionCheck.MSG_KEY;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;

@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class MutableExceptionCheckExamplesTest extends AbstractExamplesModuleTestSupport {
@Override
protected String getPackageLocation() {
Expand All @@ -34,27 +34,30 @@ protected String getPackageLocation() {
@Test
public void testExample1() throws Exception {
final String[] expected = {

"23:3: " + getCheckMessage(MSG_KEY, "code"),
"32:3: " + getCheckMessage(MSG_KEY, "message"),
"41:3: " + getCheckMessage(MSG_KEY, "code"),
};

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}

@Test
public void testExample2() throws Exception {
final String[] expected = {

"23:3: " + getCheckMessage(MSG_KEY, "code"),
"41:3: " + getCheckMessage(MSG_KEY, "code"),
};

verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
verifyWithInlineConfigParser(getPath("Example2.java"), expected);
}

@Test
public void testExample3() throws Exception {
final String[] expected = {

"32:3: " + getCheckMessage(MSG_KEY, "message"),
};

verifyWithInlineConfigParser(getPath("Example3.txt"), expected);
verifyWithInlineConfigParser(getPath("Example3.java"), expected);
}
}
@@ -0,0 +1,47 @@
/*xml
<module name="Checker">
<module name="TreeWalker">
<module name="MutableException"/>
</module>
</module>
*/



package com.puppycrawl.tools.checkstyle.checks.design.mutableexception;

// xdoc section -- start
class Example1 extends Exception {
private int code; // OK, class name doesn't match with default pattern

public Example1() {
code = 1;
}
}

class FirstException extends Exception {
private int code; // violation

public FirstException() {
code = 2;
}
}

class FirstThrowable extends Throwable {
final int code; // OK
String message; // violation

public FirstThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class FirstBadException extends java.lang.Exception {
int code; // violation

public FirstBadException(int code) {
this.code = code;
}
}
// xdoc section -- end

This file was deleted.

Expand Up @@ -8,37 +8,39 @@
</module>
*/

package com.puppycrawl.tools.checkstyle.checks.design.mutableexception;

// xdoc section -- start
class FirstClass extends Exception {
class Example2 extends Exception {
private int code; // OK, class name doesn't match with given pattern

public FirstClass() {
public Example2() {
code = 1;
}
}

class MyException extends Exception {
private int code; // violation, The field 'code' must be declared final
class SecondException extends Exception {
private int code; // violation

public MyException() {
public SecondException() {
code = 2;
}
}

class MyThrowable extends Throwable {
class SecondThrowable extends Throwable {
final int code; // OK, class name doesn't match with given pattern
String message; // OK, class name doesn't match with given pattern

public MyThrowable(int code, String message) {
public SecondThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
int code; // violation, The field 'code' must be declared final
class SecondBadException extends java.lang.Exception {
int code; // violation

public BadException(int code) {
public SecondBadException(int code) {
this.code = code;
}
}
Expand Down
Expand Up @@ -8,37 +8,39 @@
</module>
*/

package com.puppycrawl.tools.checkstyle.checks.design.mutableexception;

// xdoc section -- start
class FirstClass extends Exception {
class Example3 extends Exception {
private int code; // OK, extended class name doesn't match with given pattern

public FirstClass() {
public Example3() {
code = 1;
}
}

class MyException extends Exception {
class ThirdException extends Exception {
private int code; // OK, extended class name doesn't match with given pattern

public MyException() {
public ThirdException() {
code = 2;
}
}

class MyThrowable extends Throwable {
class ThirdThrowable extends Throwable {
final int code; // OK
String message; // violation, The field 'message' must be declared final
String message; // violation

public MyThrowable(int code, String message) {
public ThirdThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
class ThirdBadException extends java.lang.Exception {
int code; // OK, extended class name doesn't match with given pattern

public BadException(int code) {
public ThirdBadException(int code) {
this.code = code;
}
}
Expand Down
60 changes: 30 additions & 30 deletions src/xdocs/checks/design/mutableexception.xml
Expand Up @@ -74,36 +74,36 @@
</source>
<p id="Example1-code">Example:</p>
<source>
class FirstClass extends Exception {
class Example1 extends Exception {
private int code; // OK, class name doesn't match with default pattern

public FirstClass() {
public Example1() {
code = 1;
}
}

class MyException extends Exception {
private int code; // violation, The field 'code' must be declared final
class FirstException extends Exception {
private int code; // violation

public MyException() {
public FirstException() {
code = 2;
}
}

class MyThrowable extends Throwable {
class FirstThrowable extends Throwable {
final int code; // OK
String message; // violation, The field 'message' must be declared final
String message; // violation

public MyThrowable(int code, String message) {
public FirstThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
int code; // violation, The field 'code' must be declared final
class FirstBadException extends java.lang.Exception {
int code; // violation

public BadException(int code) {
public FirstBadException(int code) {
this.code = code;
}
}
Expand All @@ -124,36 +124,36 @@ class BadException extends java.lang.Exception {
</source>
<p id="Example2-code">Example:</p>
<source>
class FirstClass extends Exception {
class Example2 extends Exception {
private int code; // OK, class name doesn't match with given pattern

public FirstClass() {
public Example2() {
code = 1;
}
}

class MyException extends Exception {
private int code; // violation, The field 'code' must be declared final
class SecondException extends Exception {
private int code; // violation

public MyException() {
public SecondException() {
code = 2;
}
}

class MyThrowable extends Throwable {
class SecondThrowable extends Throwable {
final int code; // OK, class name doesn't match with given pattern
String message; // OK, class name doesn't match with given pattern

public MyThrowable(int code, String message) {
public SecondThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
int code; // violation, The field 'code' must be declared final
class SecondBadException extends java.lang.Exception {
int code; // violation

public BadException(int code) {
public SecondBadException(int code) {
this.code = code;
}
}
Expand All @@ -174,36 +174,36 @@ class BadException extends java.lang.Exception {
</source>
<p id="Example3-code">Example:</p>
<source>
class FirstClass extends Exception {
class Example3 extends Exception {
private int code; // OK, extended class name doesn't match with given pattern

public FirstClass() {
public Example3() {
code = 1;
}
}

class MyException extends Exception {
class ThirdException extends Exception {
private int code; // OK, extended class name doesn't match with given pattern

public MyException() {
public ThirdException() {
code = 2;
}
}

class MyThrowable extends Throwable {
class ThirdThrowable extends Throwable {
final int code; // OK
String message; // violation, The field 'message' must be declared final
String message; // violation

public MyThrowable(int code, String message) {
public ThirdThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
class ThirdBadException extends java.lang.Exception {
int code; // OK, extended class name doesn't match with given pattern

public BadException(int code) {
public ThirdBadException(int code) {
this.code = code;
}
}
Expand Down