Skip to content

Commit 958ee25

Browse files
committed
Add org.junit.jupiter.api.Assertions 'use static import'
1 parent bc47e14 commit 958ee25

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/main/resources/META-INF/rewrite/junit5.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
#
1616
---
1717
type: specs.openrewrite.org/v1beta/recipe
18+
name: org.openrewrite.java.testing.JUnit5
19+
recipeList:
20+
- org.openrewrite.java.UseStaticImport:
21+
methodPattern: "org.junit.jupiter.api.Assertions *(..)"
22+
- org.openrewrite.java.testing.JUnit5Migration
23+
---
24+
type: specs.openrewrite.org/v1beta/recipe
1825
name: org.openrewrite.java.testing.JUnit5Migration
1926
recipeList:
2027
- org.openrewrite.java.ChangeType:
@@ -36,10 +43,10 @@ recipeList:
3643
- org.openrewrite.java.testing.junit5.CategoryToTag
3744
- org.openrewrite.java.testing.junit5.CleanupJUnitImports
3845
- org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows
39-
- org.openrewrite.java.testing.junit5.FindJUnit5
40-
- org.openrewrite.java.testing.junit5.AddJUnitDependencies
4146
- org.openrewrite.java.testing.junit5.MockitoRunnerToMockitoExtension
4247
- org.openrewrite.java.testing.junit5.AddMockitoDependency
4348
- org.openrewrite.java.testing.junit5.TemporaryFolderToTempDir
4449
- org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
4550
- org.openrewrite.java.testing.junit5.UpdateTestAnnotation
51+
- org.openrewrite.java.testing.junit5.FindJUnit5
52+
- org.openrewrite.java.testing.junit5.AddJUnitDependencies
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2020 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.testing.junit5
17+
18+
import org.junit.Test
19+
import org.openrewrite.config.Environment
20+
import org.openrewrite.java.JavaParser
21+
import org.openrewrite.java.JavaRecipeTest
22+
23+
class StaticImportsTest: JavaRecipeTest {
24+
@Test
25+
fun useAssertionsStaticImport() = assertChanged(
26+
parser = JavaParser.fromJavaVersion().build(),
27+
recipe = Environment.builder()
28+
.scanClasspath(emptyList())
29+
.build()
30+
.activateRecipes("org.openrewrite.java.testing.JUnit5"),
31+
before = """
32+
import org.junit.jupiter.api.Assertions;
33+
34+
public class Test {
35+
void method() {
36+
Assertions.assertTrue(true);
37+
}
38+
}
39+
""",
40+
after = """
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
42+
43+
public class Test {
44+
void method() {
45+
assertTrue(true);
46+
}
47+
}
48+
"""
49+
)
50+
}

0 commit comments

Comments
 (0)