Update OutputStreamToByteArrayUnitTest.java
This commit is contained in:
parent
6e7e41cea4
commit
99e54378c3
|
@ -29,12 +29,10 @@ public class OutputStreamToByteArrayUnitTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenByteArrayOutputStream_whenUsingDrainableOutputStream_thenReturnByteArray() throws IOException {
|
public void givenSystemOut_whenUsingDrainableOutputStream_thenReturnByteArray() throws IOException {
|
||||||
String data = "Welcome to Baeldung!";
|
String data = "Welcome to Baeldung!\n";
|
||||||
|
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
||||||
DrainableOutputStream drainableOutputStream = new DrainableOutputStream(byteArrayOutputStream);
|
|
||||||
|
|
||||||
|
DrainableOutputStream drainableOutputStream = new DrainableOutputStream(System.out);
|
||||||
try (drainableOutputStream) {
|
try (drainableOutputStream) {
|
||||||
drainableOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
drainableOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
@ -43,7 +41,6 @@ public class OutputStreamToByteArrayUnitTest {
|
||||||
assertEquals(data, new String(writtenData, StandardCharsets.UTF_8));
|
assertEquals(data, new String(writtenData, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class DrainableOutputStream extends FilterOutputStream {
|
public class DrainableOutputStream extends FilterOutputStream {
|
||||||
private final ByteArrayOutputStream buffer;
|
private final ByteArrayOutputStream buffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue