Skip to content

Commit fa31ef6

Browse files
authored
Merge branch 'main' into additional-assertj-rules-recipes
2 parents 4ba13da + 869f4a9 commit fa31ef6

File tree

6 files changed

+288
-243
lines changed

6 files changed

+288
-243
lines changed

src/main/java/org/openrewrite/java/testing/cleanup/AssertLiteralBooleanToFail.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ void assertTrueBefore(String message) {
4040
}
4141

4242
@AfterTemplate
43-
// This annotation does not get taken into account
44-
// resulting in Assertions.fail(message) being outputted
4543
@UseImportPolicy(value = STATIC_IMPORT_ALWAYS)
4644
void after(String message) {
4745
fail(message);

src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java

Lines changed: 226 additions & 208 deletions
Large diffs are not rendered by default.

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,14 +2960,23 @@ examples:
29602960
import org.junit.Rule
29612961
import org.junit.rules.TemporaryFolder
29622962
2963+
import java.io.File
2964+
import java.io.IOException
2965+
29632966
class AbstractIntegrationTest {
29642967
@TempDir
29652968
File temporaryFolder
29662969
29672970
def setup() {
29682971
projectDir = temporaryFolder.root
2969-
buildFile = File.createTempFile('build.gradle', null, temporaryFolder)
2970-
settingsFile = File.createTempFile('settings.gradle', null, temporaryFolder)
2972+
buildFile = newFile(temporaryFolder, 'build.gradle')
2973+
settingsFile = newFile(temporaryFolder, 'settings.gradle')
2974+
}
2975+
2976+
private static File newFile(File parent, String child) throws IOException {
2977+
File result = new File(parent, child)
2978+
result.createNewFile()
2979+
return result
29712980
}
29722981
}
29732982
language: groovy
@@ -3380,25 +3389,6 @@ examples:
33803389
type: specs.openrewrite.org/v1beta/example
33813390
recipeName: org.openrewrite.java.testing.mockito.Mockito1to5Migration
33823391
examples:
3383-
- description: ''
3384-
sources:
3385-
- before: |
3386-
<project>
3387-
<modelVersion>4.0.0</modelVersion>
3388-
<groupId>com.example</groupId>
3389-
<artifactId>demo</artifactId>
3390-
<version>0.0.1-SNAPSHOT</version>
3391-
<dependencies>
3392-
<dependency>
3393-
<groupId>org.mockito</groupId>
3394-
<artifactId>mockito-inline</artifactId>
3395-
<version>3.11.2</version>
3396-
<scope>test</scope>
3397-
</dependency>
3398-
</dependencies>
3399-
</project>
3400-
path: pom.xml
3401-
language: xml
34023392
- description: ''
34033393
sources:
34043394
- before: |
@@ -3434,6 +3424,25 @@ examples:
34343424
}
34353425
}
34363426
language: java
3427+
- description: ''
3428+
sources:
3429+
- before: |
3430+
<project>
3431+
<modelVersion>4.0.0</modelVersion>
3432+
<groupId>com.example</groupId>
3433+
<artifactId>demo</artifactId>
3434+
<version>0.0.1-SNAPSHOT</version>
3435+
<dependencies>
3436+
<dependency>
3437+
<groupId>org.mockito</groupId>
3438+
<artifactId>mockito-inline</artifactId>
3439+
<version>3.11.2</version>
3440+
<scope>test</scope>
3441+
</dependency>
3442+
</dependencies>
3443+
</project>
3444+
path: pom.xml
3445+
language: xml
34373446
---
34383447
type: specs.openrewrite.org/v1beta/example
34393448
recipeName: org.openrewrite.java.testing.mockito.MockitoBestPractices

src/test/java/org/openrewrite/java/testing/cleanup/AssertLiteralBooleanToFailTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ void test() {
5252
}
5353
""",
5454
"""
55-
import org.junit.jupiter.api.Assertions;
55+
import static org.junit.jupiter.api.Assertions.fail;
5656
5757
public class Test {
5858
void test() {
59-
Assertions.fail("assert false true");
60-
Assertions.fail("assert true false");
59+
fail("assert false true");
60+
fail("assert true false");
6161
}
6262
}
6363
"""
@@ -82,12 +82,12 @@ void test() {
8282
}
8383
""",
8484
"""
85-
import org.junit.jupiter.api.Assertions;
85+
import static org.junit.jupiter.api.Assertions.fail;
8686
8787
public class Test {
8888
void test() {
89-
Assertions.fail("assert false true");
90-
Assertions.fail("assert true false");
89+
fail("assert false true");
90+
fail("assert true false");
9191
}
9292
}
9393
"""

src/test/java/org/openrewrite/java/testing/junit5/JUnit5BestPracticesTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.openrewrite.java.JavaParser;
2323
import org.openrewrite.test.RecipeSpec;
2424
import org.openrewrite.test.RewriteTest;
25-
import org.openrewrite.test.TypeValidation;
2625

2726
import static org.openrewrite.java.Assertions.java;
2827

src/test/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDirTest.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,23 @@ def setup() {
6666
import org.junit.Rule
6767
import org.junit.rules.TemporaryFolder
6868
69+
import java.io.File
70+
import java.io.IOException
71+
6972
class AbstractIntegrationTest {
7073
@TempDir
7174
File temporaryFolder
7275
7376
def setup() {
7477
projectDir = temporaryFolder.root
75-
buildFile = File.createTempFile('build.gradle', null, temporaryFolder)
76-
settingsFile = File.createTempFile('settings.gradle', null, temporaryFolder)
78+
buildFile = newFile(temporaryFolder, 'build.gradle')
79+
settingsFile = newFile(temporaryFolder, 'settings.gradle')
80+
}
81+
82+
private static File newFile(File parent, String child) throws IOException {
83+
File result = new File(parent, child)
84+
result.createNewFile()
85+
return result
7786
}
7887
}
7988
"""
@@ -476,7 +485,13 @@ public class MyTest {
476485
@Test
477486
public void newNamedFileIsCreatedUnderRootFolder() throws IOException {
478487
final String fileName = "SampleFile.txt";
479-
File f = File.createTempFile(fileName, null, tempFolder);
488+
File f = newFile(tempFolder, fileName);
489+
}
490+
491+
private static File newFile(File parent, String child) throws IOException {
492+
File result = new File(parent, child);
493+
result.createNewFile();
494+
return result;
480495
}
481496
}
482497
"""
@@ -531,8 +546,14 @@ public class MyTest {
531546
public void newNamedFileIsCreatedUnderRootFolder() throws IOException {
532547
final String fileName = "SampleFile.txt";
533548
final String otherFileName = "otherText.txt";
534-
File f = File.createTempFile(fileName, null, tempFolder);
535-
File f2 = File.createTempFile(otherFileName, null, tempFolder2);
549+
File f = newFile(tempFolder, fileName);
550+
File f2 = newFile(tempFolder2, otherFileName);
551+
}
552+
553+
private static File newFile(File parent, String child) throws IOException {
554+
File result = new File(parent, child);
555+
result.createNewFile();
556+
return result;
536557
}
537558
}
538559
"""

0 commit comments

Comments
 (0)