Skip to content

Commit

Permalink
Issue checkstyle#10385: Update inputs for MutableExceptionCheckTest
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatj07 authored and romani committed Jul 20, 2021
1 parent 08d8769 commit 175c5ed
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 33 deletions.
16 changes: 0 additions & 16 deletions config/checkstyle_input_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,6 @@



<suppress id="ConfigCommentOnTopInputs"
files="design[\\/]mutableexception[\\/]InputMutableExceptionClassExtendsGenericClass.java"/>

<suppress id="ConfigCommentOnTopInputs"
files="design[\\/]mutableexception[\\/]InputMutableException.java"/>

<suppress id="ConfigCommentOnTopInputs"
files="design[\\/]mutableexception[\\/]InputMutableExceptionMultipleInputs.java"/>



Expand Down Expand Up @@ -2073,14 +2065,6 @@



<suppress id="StyleValidationCommentInInputs"
files="design[\\/]mutableexception[\\/]InputMutableExceptionClassExtendsGenericClass.java"/>

<suppress id="StyleValidationCommentInInputs"
files="design[\\/]mutableexception[\\/]InputMutableException.java"/>

<suppress id="StyleValidationCommentInInputs"
files="design[\\/]mutableexception[\\/]InputMutableExceptionMultipleInputs.java"/>



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public void testDefault() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MutableExceptionCheck.class);

final String[] expected = {
"6:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"23:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"46:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"14:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"31:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"54:9: " + getCheckMessage(MSG_KEY, "errorCode"),
};

verify(checkConfig, getPath("InputMutableException.java"), expected);
Expand All @@ -69,16 +69,16 @@ public void testDefault() throws Exception {
@Test
public void testMultipleInputs() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MutableExceptionCheck.class);
final String filePath1 = getPath("InputMutableException.java");
final String filePath1 = getPath("InputMutableException2.java");
final String filePath2 = getPath("InputMutableExceptionMultipleInputs.java");

final List<String> expected1 = Arrays.asList(
"6:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"23:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"46:9: " + getCheckMessage(MSG_KEY, "errorCode"));
"14:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"31:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"54:9: " + getCheckMessage(MSG_KEY, "errorCode"));
final List<String> expected2 = Arrays.asList(
"6:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"10:9: " + getCheckMessage(MSG_KEY, "errorCode"));
"14:9: " + getCheckMessage(MSG_KEY, "errorCode"),
"18:9: " + getCheckMessage(MSG_KEY, "errorCode"));

final File[] inputs = {new File(filePath1), new File(filePath2)};

Expand All @@ -92,10 +92,10 @@ public void testFormat() throws Exception {
checkConfig.addProperty("format", "^.*Failure$");
checkConfig.addProperty("extendedClassNameFormat", "^.*ThreadDeath$");
final String[] expected = {
"34:13: " + getCheckMessage(MSG_KEY, "errorCode"),
"42:13: " + getCheckMessage(MSG_KEY, "errorCode"),
};

verify(checkConfig, getPath("InputMutableException.java"), expected);
verify(checkConfig, getPath("InputMutableException3.java"), expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/*
MutableException
format = (default)^.*Exception$|^.*Error$|^.*Throwable$
extendedClassNameFormat = (default)^.*Exception$|^.*Error$|^.*Throwable$
*/

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

public class InputMutableException {
public class FooException extends Exception {
private final int finalErrorCode;
private int errorCode = 1;
private int errorCode = 1; // violation

public FooException() {
finalErrorCode = 1;
Expand All @@ -20,7 +28,7 @@ public FooExceptionThisIsNot() {
}

public class BarError extends Throwable {
private int errorCode;
private int errorCode; // violation
}

public class BazDoesNotExtendError {
Expand All @@ -43,7 +51,7 @@ public void someMethod() {
class CustomException extends java.lang.Exception {}

class CustomMutableException extends java.lang.Exception {
int errorCode;
int errorCode; // violation
}

class ExampleException extends java.lang.Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
MutableException
format = (default)^.*Exception$|^.*Error$|^.*Throwable$
extendedClassNameFormat = (default)^.*Exception$|^.*Error$|^.*Throwable$
*/

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

public class InputMutableException2 {
public class FooException extends Exception {
private final int finalErrorCode;
private int errorCode = 1; // violation

public FooException() {
finalErrorCode = 1;
}

public class FooExceptionThisIsNot extends RuntimeException {
private final int finalErrorCode;
private int errorCode = 1;
/** constructor */
public FooExceptionThisIsNot() {
finalErrorCode = 1;
}
}
}

public class BarError extends Throwable {
private int errorCode; // violation
}

public class BazDoesNotExtendError {
private int errorCode;
}

public class CustomProblem extends ThreadDeath {
private int errorCode;

public class CustomFailure extends ThreadDeath {
private int errorCode;
public void someMethod() {
if(true) {
final int i = 0;
}
}
}
}

class CustomException extends Exception {}

class CustomMutableException extends Exception {
int errorCode; // violation
}

class ExampleException extends Exception {
public void test() {
Throwable cause = super.getCause();
if (!(cause instanceof java.io.IOException))
throw new IllegalStateException("Test");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
MutableException
format = ^.*Failure$
extendedClassNameFormat = ^.*ThreadDeath$
*/

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

public class InputMutableException3 {
public class FooException extends Exception {
private final int finalErrorCode;
private int errorCode = 1;

public FooException() {
finalErrorCode = 1;
}

public class FooExceptionThisIsNot extends RuntimeException {
private final int finalErrorCode;
private int errorCode = 1;
/** constructor */
public FooExceptionThisIsNot() {
finalErrorCode = 1;
}
}
}

public class BarError extends Throwable {
private int errorCode;
}

public class BazDoesNotExtendError {
private int errorCode;
}

public class CustomProblem extends ThreadDeath {
private int errorCode;

public class CustomFailure extends ThreadDeath {
private int errorCode; // violation
public void someMethod() {
if(true) {
final int i = 0;
}
}
}
}

class CustomException extends Exception {}

class CustomMutableException extends Exception {
int errorCode;
}

class ExampleException extends Exception {
public void test() {
Throwable cause = super.getCause();
if (!(cause instanceof java.io.IOException))
throw new IllegalStateException("Test");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/*
MutableException
format = (default)^.*Exception$|^.*Error$|^.*Throwable$
extendedClassNameFormat = (default)^.*Exception$|^.*Error$|^.*Throwable$
*/

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

import java.util.concurrent.atomic.AtomicReference;

/**
* Convenience class for holding an {@link Exception} in a thread-safe way // NPE is not expected
*/
public class InputMutableExceptionClassExtendsGenericClass extends AtomicReference<Exception> {
public class InputMutableExceptionClassExtendsGenericClass // ok
extends AtomicReference<Exception> {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/*
MutableException
format = (default)^.*Exception$|^.*Error$|^.*Throwable$
extendedClassNameFormat = (default)^.*Exception$|^.*Error$|^.*Throwable$
*/

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

public class InputMutableExceptionMultipleInputs {

public class BarError extends Throwable {
private int errorCode;
private int errorCode; // violation
}

class CustomMutableException extends java.lang.Exception {
int errorCode;
int errorCode; // violation
final int errorCount = 6;
}

Expand Down

0 comments on commit 175c5ed

Please sign in to comment.