BAEL-6398: Java PrintStream to String (#13998)

This commit is contained in:
Azhwani
2023-05-16 08:28:25 +02:00
committed by GitHub
parent e23e9e3aca
commit be747e6e78
2 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package com.baeldung.printstreamtostring;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.junit.Test;
public class PrintStreamToStringUtilUnitTest {
@Test
public void whenUsingByteArrayOutputStreamClass_thenConvert() throws IOException {
assertEquals("test", PrintStreamToStringUtil.usingByteArrayOutputStreamClass("test"));
assertEquals("", PrintStreamToStringUtil.usingByteArrayOutputStreamClass(""));
assertNull(PrintStreamToStringUtil.usingByteArrayOutputStreamClass(null));
}
@Test
public void whenCustomOutputStream_thenConvert() throws IOException {
assertEquals("world", PrintStreamToStringUtil.usingCustomOutputStream("world"));
assertEquals("", PrintStreamToStringUtil.usingCustomOutputStream(""));
assertNull(PrintStreamToStringUtil.usingCustomOutputStream(null));
}
@Test
public void whenUsingApacheCommonsIO_thenConvert() {
assertEquals("hello", PrintStreamToStringUtil.usingApacheCommonsIO("hello"));
assertEquals("", PrintStreamToStringUtil.usingApacheCommonsIO(""));
assertNull(PrintStreamToStringUtil.usingApacheCommonsIO(null));
}
}