Skip to content

Commit 0554b2d

Browse files
committed
Restore ArrayStoreExceptionToTypeNotPresentExceptionTest
1 parent 1936b5c commit 0554b2d

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.test.RecipeSpec;
21+
import org.openrewrite.test.RewriteTest;
22+
23+
import static org.openrewrite.java.Assertions.java;
24+
25+
class ArrayStoreExceptionToTypeNotPresentExceptionTest implements RewriteTest {
26+
27+
@Override
28+
public void defaults(RecipeSpec spec) {
29+
spec.recipe(new ArrayStoreExceptionToTypeNotPresentException());
30+
}
31+
32+
@DocumentExample
33+
@Test
34+
void replaceCaughtException() {
35+
rewriteRun(
36+
//language=java
37+
java(
38+
"""
39+
import java.lang.annotation.*;
40+
import java.util.*;
41+
42+
public class Test {
43+
public void testMethod() {
44+
try {
45+
Object o = "test";
46+
o.getClass().getAnnotation(Override.class);
47+
} catch (ArrayStoreException e) {
48+
System.out.println("Caught Exception");
49+
}
50+
try {
51+
Object.class.getAnnotation(Override.class);
52+
} catch (ArrayStoreException e) {
53+
System.out.println("Caught ArrayStoreException");
54+
}
55+
}
56+
}
57+
""",
58+
"""
59+
import java.lang.annotation.*;
60+
import java.util.*;
61+
62+
public class Test {
63+
public void testMethod() {
64+
try {
65+
Object o = "test";
66+
o.getClass().getAnnotation(Override.class);
67+
} catch (TypeNotPresentException e) {
68+
System.out.println("Caught Exception");
69+
}
70+
try {
71+
Object.class.getAnnotation(Override.class);
72+
} catch (TypeNotPresentException e) {
73+
System.out.println("Caught ArrayStoreException");
74+
}
75+
}
76+
}
77+
"""
78+
)
79+
);
80+
}
81+
82+
@Test
83+
void retainOtherCaughtExceptions() {
84+
rewriteRun(
85+
//language=java
86+
java(
87+
"""
88+
public class Test {
89+
public void testMethod() {
90+
try {
91+
Object o = "test";
92+
o.getClass().getAnnotation(Override.class);
93+
} catch (NullPointerException e) {
94+
System.out.println("Caught Exception");
95+
}
96+
}
97+
}
98+
"""
99+
)
100+
);
101+
}
102+
103+
@Test
104+
void retainArrayStoreExceptionWithoutClassGetAnnotation() {
105+
rewriteRun(
106+
//language=java
107+
java(
108+
"""
109+
public class Test {
110+
public void testMethod() {
111+
try {
112+
Object o = "test";
113+
} catch (ArrayStoreException e) {
114+
System.out.println("Caught Exception");
115+
}
116+
}
117+
}
118+
"""
119+
)
120+
);
121+
}
122+
}

0 commit comments

Comments
 (0)