reta commented on a change in pull request #755:
URL: https://github.com/apache/cxf/pull/755#discussion_r590907534
##########
File path: core/src/test/java/org/apache/cxf/helpers/IOUtilsTest.java
##########
@@ -29,32 +29,77 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class IOUtilsTest {
-
@Test
public void testIsEmpty() throws Exception {
- assertTrue(IOUtils.isEmpty(new ByteArrayInputStream(new byte[]{})));
+ assertTrue(IOUtils.isEmpty(new ByteArrayInputStream(new byte[] {})));
}
+
@Test
public void testNonEmpty() throws Exception {
InputStream is = new ByteArrayInputStream("Hello".getBytes());
assertFalse(IOUtils.isEmpty(is));
assertEquals("Hello", IOUtils.toString(is));
}
+
@Test
public void testNonEmptyWithPushBack() throws Exception {
- InputStream is = new PushbackInputStream(
- new ByteArrayInputStream("Hello".getBytes()));
+ InputStream is = new PushbackInputStream(new
ByteArrayInputStream("Hello".getBytes()));
assertFalse(IOUtils.isEmpty(is));
assertEquals("Hello", IOUtils.toString(is));
}
+
@Test
public void testInputStreamWithNoMark() throws Exception {
String data = "this is some data";
InputStream is = new UnMarkedInputStream(data.getBytes());
assertFalse(IOUtils.isEmpty(is));
assertEquals(data, IOUtils.toString(is));
}
-}
\ No newline at end of file
+
+ @Test
+ public void testCopy() throws IOException {
+ byte[] inBytes = "Foo".getBytes(IOUtils.UTF8_CHARSET);
+ ByteArrayInputStream is = new ByteArrayInputStream(inBytes);
+ ByteArrayOutputStream os = new ByteArrayOutputStream(inBytes.length);
+ IOUtils.copy(is, os);
+ byte[] outBytes = os.toByteArray();
+ String expectedString = new String(outBytes, IOUtils.UTF8_CHARSET);
+ assertEquals("Foo", expectedString);
+ }
+
+ @Test(expected = IOException.class)
+ public void testCopyAndCloseInput() throws IOException {
+ InputStream is = getClass().getResourceAsStream("/wsdl/foo.wsdl");
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ IOUtils.copyAndCloseInput(is, os);
+ is.read();
+ fail("InputStream should be closed");
+ }
+
+ @Test
+ public void testCopyAtLeast() throws IOException {
Review comment:
Would be good to have 3 test cases:
- >= size of the stream
- == size of the stream
- <= size of the stream
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]