Skip to content

Commit

Permalink
Issue #13345: Enabled MutableExceptionCheckExamplesTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Prathamesh-007 authored and romani committed Apr 17, 2024
1 parent 8c27c6d commit 0707dd5
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 106 deletions.
Original file line number Diff line number Diff line change
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);
}
}
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 0707dd5

Please sign in to comment.