Skip to content

Commit 5abe7b1

Browse files
committed
Rewrite test using JUnit 5 APIs.
1 parent b785d75 commit 5abe7b1

1 file changed

Lines changed: 15 additions & 34 deletions

File tree

src/test/java/org/apache/commons/io/output/BrokenWriterTest.java

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.apache.commons.io.output;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
import static org.junit.jupiter.api.Assertions.fail;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2121

2222
import java.io.IOException;
2323
import java.io.Writer;
@@ -32,56 +32,37 @@ public class BrokenWriterTest {
3232

3333
private IOException exception;
3434

35-
private Writer writer;
35+
private Writer brokenWriter;
3636

3737
@BeforeEach
3838
public void setUp() {
3939
exception = new IOException("test exception");
40-
writer = new BrokenWriter(exception);
40+
brokenWriter = new BrokenWriter(exception);
4141
}
4242

4343
@Test
44-
public void testWrite() {
45-
try {
46-
writer.write(1);
47-
fail("Expected exception not thrown.");
48-
} catch (final IOException e) {
49-
assertEquals(exception, e);
50-
}
44+
public void testWriteInt() {
45+
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write(1)));
46+
}
5147

52-
try {
53-
writer.write(new char[1]);
54-
fail("Expected exception not thrown.");
55-
} catch (final IOException e) {
56-
assertEquals(exception, e);
57-
}
48+
@Test
49+
public void testWriteCharArray() {
50+
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write(new char[1])));
51+
}
5852

59-
try {
60-
writer.write(new char[1], 0, 1);
61-
fail("Expected exception not thrown.");
62-
} catch (final IOException e) {
63-
assertEquals(exception, e);
64-
}
53+
@Test
54+
public void testWriteCharArrayIndexed() {
55+
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write(new char[1], 0, 1)));
6556
}
6657

6758
@Test
6859
public void testFlush() {
69-
try {
70-
writer.flush();
71-
fail("Expected exception not thrown.");
72-
} catch (final IOException e) {
73-
assertEquals(exception, e);
74-
}
60+
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.flush()));
7561
}
7662

7763
@Test
7864
public void testClose() {
79-
try {
80-
writer.close();
81-
fail("Expected exception not thrown.");
82-
} catch (final IOException e) {
83-
assertEquals(exception, e);
84-
}
65+
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.close()));
8566
}
8667

8768
}

0 commit comments

Comments
 (0)