Skip to content

Commit 3dc2a3d

Browse files
AmitKumarDeoghoriaromani
authored andcommitted
Issue #13345: Enable examples tests for IllegalCatchCheck
1 parent 2a843c0 commit 3dc2a3d

File tree

7 files changed

+213
-145
lines changed

7 files changed

+213
-145
lines changed

src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalCatchCheckExamplesTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919

2020
package com.puppycrawl.tools.checkstyle.checks.coding;
2121

22-
import org.junit.jupiter.api.Disabled;
2322
import org.junit.jupiter.api.Test;
2423

2524
import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
2625

27-
@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
2826
public class IllegalCatchCheckExamplesTest extends AbstractExamplesModuleTestSupport {
2927
@Override
3028
protected String getPackageLocation() {
@@ -34,18 +32,22 @@ protected String getPackageLocation() {
3432
@Test
3533
public void testExample1() throws Exception {
3634
final String[] expected = {
37-
35+
"15:7: " + getCheckMessage(IllegalCatchCheck.MSG_KEY, "Exception"),
36+
"25:7: " + getCheckMessage(IllegalCatchCheck.MSG_KEY, "Exception"),
3837
};
3938

40-
verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
39+
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
4140
}
4241

4342
@Test
4443
public void testExample2() throws Exception {
4544
final String[] expected = {
46-
45+
"26:7: " + getCheckMessage(IllegalCatchCheck.MSG_KEY, "ArithmeticException"),
46+
"37:7: " + getCheckMessage(IllegalCatchCheck.MSG_KEY, "OutOfMemoryError"),
47+
"45:7: " + getCheckMessage(IllegalCatchCheck.MSG_KEY, "ArithmeticException"),
48+
"53:7: " + getCheckMessage(IllegalCatchCheck.MSG_KEY, "OutOfMemoryError"),
4749
};
4850

49-
verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
51+
verifyWithInlineConfigParser(getPath("Example2.java"), expected);
5052
}
5153
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="IllegalCatch"/>
5+
</module>
6+
</module>
7+
*/
8+
package com.puppycrawl.tools.checkstyle.checks.coding.illegalcatch;
9+
10+
// xdoc section -- start
11+
class Example1 {
12+
void exampleMethod1() {
13+
try {
14+
// some code here
15+
} catch (Exception e) {
16+
// violation above, 'Catching 'Exception' is not allowed'
17+
}
18+
}
19+
20+
void exampleMethod2() {
21+
try {
22+
// some code here
23+
} catch (ArithmeticException e) {
24+
25+
} catch (Exception e) {
26+
// violation above, 'Catching 'Exception' is not allowed'
27+
}
28+
}
29+
30+
void exampleMethod3() {
31+
try {
32+
// some code here
33+
} catch (NullPointerException e) {
34+
} catch (OutOfMemoryError e) {
35+
36+
}
37+
}
38+
39+
void exampleMethod4() {
40+
try {
41+
// some code here
42+
} catch (ArithmeticException | NullPointerException e) {
43+
44+
}
45+
}
46+
47+
void exampleMethod5() {
48+
try {
49+
// some code here
50+
} catch (OutOfMemoryError e) {
51+
52+
}
53+
}
54+
}
55+
// xdoc section -- end

src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegalcatch/Example1.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="IllegalCatch">
5+
<property name="illegalClassNames"
6+
value="ArithmeticException,OutOfMemoryError"/>
7+
</module>
8+
</module>
9+
</module>
10+
*/
11+
package com.puppycrawl.tools.checkstyle.checks.coding.illegalcatch;
12+
13+
// xdoc section -- start
14+
class Example2 {
15+
void exampleMethod1() {
16+
try {
17+
// some code here
18+
} catch (Exception e) {
19+
20+
}
21+
}
22+
23+
void exampleMethod2() {
24+
try {
25+
// some code here
26+
} catch (ArithmeticException e) {
27+
// violation above, 'Catching 'ArithmeticException' is not allowed'
28+
} catch(Exception e){
29+
30+
}
31+
}
32+
33+
void exampleMethod3() {
34+
try {
35+
// some code here
36+
} catch (NullPointerException e) {
37+
} catch (OutOfMemoryError e) {
38+
// violation above, 'Catching 'OutOfMemoryError' is not allowed'
39+
}
40+
}
41+
42+
void exampleMethod4() {
43+
try {
44+
// some code here
45+
} catch (ArithmeticException | NullPointerException e) {
46+
// violation above, 'Catching 'ArithmeticException' is not allowed'
47+
}
48+
}
49+
50+
void exampleMethod5(){
51+
try {
52+
// some code here
53+
} catch (OutOfMemoryError e) {
54+
// violation above, 'Catching 'OutOfMemoryError' is not allowed'
55+
}
56+
}
57+
}
58+
// xdoc section -- end

src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegalcatch/Example2.txt

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)