Skip to content

Commit afe3910

Browse files
SPSP
authored andcommitted
refactor: using junit 5 in the test
1 parent eb70db2 commit afe3910

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,55 @@
2828
import static org.junit.jupiter.api.Assertions.assertThrows;
2929
import static org.junit.jupiter.api.Assertions.assertTrue;
3030

31-
import java.io.File;
3231
import java.io.IOException;
3332
import java.nio.file.Files;
33+
import java.nio.file.Path;
3434
import lombok.SneakyThrows;
35-
import org.junit.Rule;
3635
import org.junit.jupiter.api.Assertions;
3736
import org.junit.jupiter.api.Test;
38-
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
39-
import org.junit.rules.TemporaryFolder;
37+
import org.junit.jupiter.api.io.TempDir;
4038

4139
/** SimpleFileWriterTest */
42-
@EnableRuleMigrationSupport
4340
class SimpleFileWriterTest {
4441

45-
@Rule public final TemporaryFolder testFolder = new TemporaryFolder();
42+
@TempDir private Path testFolder;
4643

4744
@Test
4845
void testWriterNotNull() throws Exception {
49-
final var temporaryFile = this.testFolder.newFile();
50-
new SimpleFileWriter(temporaryFile.getPath(), Assertions::assertNotNull);
46+
final var temporaryFilePath = Files.createFile(testFolder.resolve("testfile.txt"));
47+
new SimpleFileWriter(temporaryFilePath.toString(), Assertions::assertNotNull);
5148
}
5249

5350
@Test
5451
void testCreatesNonExistentFile() throws Exception {
55-
final var nonExistingFile = new File(this.testFolder.getRoot(), "non-existing-file");
56-
assertFalse(nonExistingFile.exists());
52+
final var nonExistingFilePath = testFolder.resolve("non-existing-file.txt");
53+
assertFalse(nonExistingFilePath.toFile().exists());
5754

58-
new SimpleFileWriter(nonExistingFile.getPath(), Assertions::assertNotNull);
59-
assertTrue(nonExistingFile.exists());
55+
new SimpleFileWriter(nonExistingFilePath.toString(), Assertions::assertNotNull);
56+
assertTrue(nonExistingFilePath.toFile().exists());
6057
}
6158

6259
@Test
6360
void testContentsAreWrittenToFile() throws Exception {
6461
final var testMessage = "Test message";
6562

66-
final var temporaryFile = this.testFolder.newFile();
67-
assertTrue(temporaryFile.exists());
63+
final var temporaryFilePath = Files.createFile(testFolder.resolve("testfile.txt"));
64+
assertTrue(temporaryFilePath.toFile().exists());
6865

69-
new SimpleFileWriter(temporaryFile.getPath(), writer -> writer.write(testMessage));
70-
assertTrue(Files.lines(temporaryFile.toPath()).allMatch(testMessage::equals));
66+
new SimpleFileWriter(temporaryFilePath.toFile().getPath(), writer -> writer.write(testMessage));
67+
assertTrue(Files.lines(temporaryFilePath.toFile().toPath()).allMatch(testMessage::equals));
7168
}
7269

7370
@Test
7471
@SneakyThrows
75-
void testRipplesIoExceptionOccurredWhileWriting() {
72+
void testRipplesIoExceptionOccurredWhileWriting() throws Exception {
7673
var message = "Some error";
77-
final var temporaryFile = this.testFolder.newFile();
74+
final var temporaryFilePath = Files.createFile(testFolder.resolve("testfile.txt"));
7875
assertThrows(
7976
IOException.class,
8077
() ->
8178
new SimpleFileWriter(
82-
temporaryFile.getPath(),
79+
temporaryFilePath.toString(),
8380
writer -> {
8481
throw new IOException("error");
8582
}),

0 commit comments

Comments
 (0)