Skip to content

Commit 2f5f3e4

Browse files
authored
Migrate to junit 5 (#22)
1 parent 8c1527d commit 2f5f3e4

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

parent/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@
108108
</dependency>
109109

110110
<dependency>
111-
<groupId>junit</groupId>
112-
<artifactId>junit</artifactId>
113-
<version>4.13.1</version>
111+
<groupId>org.junit.jupiter</groupId>
112+
<artifactId>junit-jupiter</artifactId>
113+
<version>5.14.3</version>
114114
<scope>test</scope>
115115
</dependency>
116116

processor/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@
4646
</dependency>
4747

4848
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter</artifactId>
5151
<scope>test</scope>
5252
</dependency>
53-
5453
<dependency>
5554
<groupId>org.assertj</groupId>
5655
<artifactId>assertj-core</artifactId>

processor/src/test/java/org/mapstruct/tools/gem/processor/ProcessorTest.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,18 @@
2424
import javax.tools.StandardLocation;
2525
import javax.tools.ToolProvider;
2626

27-
import org.assertj.core.api.JUnitSoftAssertions;
28-
import org.junit.Rule;
29-
import org.junit.Test;
30-
import org.junit.rules.TemporaryFolder;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.io.TempDir;
3129

3230
import static org.assertj.core.api.Assertions.assertThat;
3331

34-
public class ProcessorTest {
32+
class ProcessorTest {
3533

36-
// CHECKSTYLE:OFF
37-
@Rule
38-
public final TemporaryFolder tempDir = new TemporaryFolder(); //NOSONAR
39-
40-
@Rule
41-
public final JUnitSoftAssertions softly = new JUnitSoftAssertions();
42-
// CHECKSTYLE:ON
34+
@TempDir
35+
private File tempDir;
4336

4437
@Test
45-
public void example() throws IOException, ClassNotFoundException {
38+
void example() throws IOException {
4639
StringJavaFileObject src = new StringJavaFileObject(
4740
"org.mapstruct.annotations.processor.GemGenerator",
4841
getSource()
@@ -55,9 +48,9 @@ private void compile(Processor processor, JavaFileObject... compilationUnits) th
5548

5649
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
5750
StandardJavaFileManager fileManager = compiler.getStandardFileManager( diagnostics, null, null );
58-
File classesDir = tempDir.newFolder( "classes" );
51+
File classesDir = newFolder( tempDir, "classes" );
5952
fileManager.setLocation( StandardLocation.CLASS_OUTPUT, Collections.singletonList( classesDir ) );
60-
File generatedDir = tempDir.newFolder( "generated" );
53+
File generatedDir = newFolder( tempDir, "generated" );
6154
fileManager.setLocation( StandardLocation.SOURCE_OUTPUT, Collections.singletonList( generatedDir ) );
6255

6356
JavaCompiler.CompilationTask task = compiler.getTask(
@@ -88,15 +81,15 @@ private void compile(Processor processor, JavaFileObject... compilationUnits) th
8881

8982
protected void assertGeneratedFileContent(String gemName, File generatedDir) {
9083
Path gemPath = generatedDir.toPath().resolve( "org/mapstruct/tools/gem/processor/" + gemName + ".java" );
91-
softly.assertThat( gemPath )
84+
assertThat( gemPath )
9285
.as( gemName )
9386
.exists();
9487

9588
try (InputStream generatedGemStream = new FileInputStream( gemPath.toFile() );
9689
InputStream expectedGemStream = getClass().getClassLoader()
9790
.getResourceAsStream( "fixtures/org/mapstruct/tools/gem/processor/" + gemName + ".java" )
9891
) {
99-
softly.assertThat( generatedGemStream )
92+
assertThat( generatedGemStream )
10093
.as( gemName )
10194
.hasSameContentAs( expectedGemStream );
10295
}
@@ -139,4 +132,12 @@ private String getSource() {
139132
"public class GemGenerator {\n" +
140133
"}";
141134
}
135+
136+
private static File newFolder(File root, String folder) throws IOException {
137+
File result = new File(root, folder);
138+
if (!result.mkdir()) {
139+
throw new IOException("Couldn't create folder " + result);
140+
}
141+
return result;
142+
}
142143
}

0 commit comments

Comments
 (0)