Skip to content

Commit a8f1193

Browse files
committed
Add unit test for JUnit6BestPractices
1 parent 22b9122 commit a8f1193

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2026 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (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://docs.moderne.io/licensing/moderne-source-available-license
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.testing.junit;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.InMemoryExecutionContext;
21+
import org.openrewrite.java.JavaParser;
22+
import org.openrewrite.test.RecipeSpec;
23+
import org.openrewrite.test.RewriteTest;
24+
25+
import static org.openrewrite.java.Assertions.java;
26+
import static org.openrewrite.java.Assertions.javaVersion;
27+
28+
class JUnit6BestPracticesTest implements RewriteTest {
29+
30+
@Override
31+
public void defaults(RecipeSpec spec) {
32+
spec
33+
.parser(JavaParser.fromJavaVersion()
34+
.classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5"))
35+
.recipeFromResources("org.openrewrite.java.testing.junit.JUnit6BestPractices");
36+
}
37+
38+
@DocumentExample
39+
@Test
40+
void migrateMethodOrdererAlphanumeric() {
41+
rewriteRun(
42+
java(
43+
"""
44+
import org.junit.jupiter.api.MethodOrderer;
45+
import org.junit.jupiter.api.TestMethodOrder;
46+
import org.junit.jupiter.api.Test;
47+
48+
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
49+
public class MyTest {
50+
@Test
51+
public void test1() {
52+
}
53+
54+
@Test
55+
public void test2() {
56+
}
57+
}
58+
""",
59+
"""
60+
import org.junit.jupiter.api.MethodOrderer;
61+
import org.junit.jupiter.api.TestMethodOrder;
62+
import org.junit.jupiter.api.Test;
63+
64+
@TestMethodOrder(MethodOrderer.MethodName.class)
65+
class MyTest {
66+
@Test
67+
void test1() {
68+
}
69+
70+
@Test
71+
void test2() {
72+
}
73+
}
74+
""",
75+
spec -> spec.markers(javaVersion(17))
76+
)
77+
);
78+
}
79+
80+
}

0 commit comments

Comments
 (0)