1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io.output;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import java.io.IOException;
23 import java.io.StringWriter;
24 import java.io.UncheckedIOException;
25 import java.nio.charset.Charset;
26
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Disabled;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34 public class UncheckedFilterOutputStreamTest {
35
36 private IOException exception;
37
38 private UncheckedFilterOutputStream brokenWriter;
39 private UncheckedFilterOutputStream stringWriter;
40
41 @SuppressWarnings("resource")
42 @BeforeEach
43 public void setUp() throws IOException {
44 exception = new IOException("test exception");
45 brokenWriter = UncheckedFilterOutputStream.builder().setOutputStream(new BrokenOutputStream(exception)).get();
46 stringWriter = UncheckedFilterOutputStream.builder()
47 .setOutputStream(WriterOutputStream.builder().setWriter(new StringWriter()).setCharset(Charset.defaultCharset()).get()).get();
48 }
49
50 @Test
51 public void testClose() {
52 stringWriter.close();
53 }
54
55 @Test
56 public void testCloseThrows() {
57 assertEquals(exception, assertThrows(UncheckedIOException.class, () -> brokenWriter.close()).getCause());
58 }
59
60 @Test
61 public void testEquals() {
62 stringWriter.equals(null);
63 }
64
65 @Test
66 @Disabled("What should happen here?")
67 public void testEqualsThrows() {
68 assertEquals(exception, assertThrows(UncheckedIOException.class, () -> brokenWriter.equals(null)).getCause());
69 }
70
71 @Test
72 public void testFlush() {
73 stringWriter.flush();
74 }
75
76 @Test
77 public void testFlushThrows() {
78 assertEquals(exception, assertThrows(UncheckedIOException.class, () -> brokenWriter.flush()).getCause());
79 }
80
81 @Test
82 public void testHashCode() {
83 stringWriter.hashCode();
84 }
85
86 @Test
87 @Disabled("What should happen here?")
88 public void testHashCodeThrows() {
89 assertEquals(exception, assertThrows(UncheckedIOException.class, () -> brokenWriter.hashCode()).getCause());
90 }
91
92 @Test
93 public void testToString() {
94 stringWriter.toString();
95 }
96
97 @Test
98 @Disabled("What should happen here?")
99 public void testToStringThrows() {
100 assertEquals(exception, assertThrows(UncheckedIOException.class, () -> brokenWriter.toString()).getCause());
101 }
102
103 @Test
104 public void testWriteInt() {
105 stringWriter.write(1);
106 }
107
108 @Test
109 public void testWriteIntThrows() {
110 assertEquals(exception, assertThrows(UncheckedIOException.class, () -> brokenWriter.write(1)).getCause());
111 }
112
113 }