Skip to content

Commit f0a6ba5

Browse files
Fix FileChannelWriterTest and VirtualFileTest for JUnit 5 (#10713)
1 parent fd2243b commit f0a6ba5

File tree

2 files changed

+266
-254
lines changed

2 files changed

+266
-254
lines changed

core/src/test/java/hudson/util/FileChannelWriterTest.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,53 @@
22

33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.equalTo;
5-
import static org.junit.Assert.assertThrows;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
66

7-
import java.io.File;
87
import java.io.IOException;
98
import java.nio.channels.ClosedChannelException;
109
import java.nio.charset.StandardCharsets;
1110
import java.nio.file.Files;
11+
import java.nio.file.Path;
1212
import java.nio.file.StandardOpenOption;
13-
import org.junit.Before;
14-
import org.junit.Rule;
15-
import org.junit.Test;
16-
import org.junit.rules.TemporaryFolder;
17-
18-
public class FileChannelWriterTest {
19-
@Rule
20-
public TemporaryFolder temporaryFolder = new TemporaryFolder();
21-
22-
File file;
23-
FileChannelWriter writer;
24-
25-
@Before
26-
public void setUp() throws Exception {
27-
file = temporaryFolder.newFile();
28-
writer = new FileChannelWriter(file.toPath(), StandardCharsets.UTF_8, true, true, StandardOpenOption.WRITE);
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
16+
class FileChannelWriterTest {
17+
18+
private Path file;
19+
private FileChannelWriter writer;
20+
21+
@BeforeEach
22+
void setUp() throws Exception {
23+
file = Files.createTempFile("junit", null);
24+
writer = new FileChannelWriter(file, StandardCharsets.UTF_8, true, true, StandardOpenOption.WRITE);
2925
}
3026

3127
@Test
32-
public void write() throws Exception {
28+
void write() throws Exception {
3329
writer.write("helloooo");
3430
writer.close();
3531

3632
assertContent("helloooo");
3733
}
3834

39-
4035
@Test
41-
public void flush() throws Exception {
36+
void flush() throws Exception {
4237
writer.write("hello é è à".toCharArray());
4338

4439
writer.flush();
4540
assertContent("hello é è à");
4641
}
4742

4843
@Test
49-
public void close() throws Exception {
44+
void close() throws Exception {
5045
writer.write("helloooo");
5146
writer.close();
5247

5348
assertThrows(ClosedChannelException.class, () -> writer.write("helloooo"));
5449
}
5550

56-
5751
private void assertContent(String string) throws IOException {
58-
assertThat(Files.readString(file.toPath(), StandardCharsets.UTF_8), equalTo(string));
52+
assertThat(Files.readString(file, StandardCharsets.UTF_8), equalTo(string));
5953
}
6054
}

0 commit comments

Comments
 (0)