summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorluccioman <luccioman@users.noreply.github.com>2017-08-22 14:06:09 +0200
committerluccioman <luccioman@users.noreply.github.com>2017-08-22 14:06:09 +0200
commit4743a104b5f36d7843dfc2aae65d075d0c95bdb2 (patch)
tree8b6c73d0a4329720440f309a2494022758227a90 /test
parente41d046a9d4cdbcfbbd297da817a853b8415f058 (diff)
Added some unit tests on FileUtils.
Diffstat (limited to 'test')
-rw-r--r--test/java/net/yacy/kelondro/util/FileUtilsTest.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/java/net/yacy/kelondro/util/FileUtilsTest.java b/test/java/net/yacy/kelondro/util/FileUtilsTest.java
index a01341f1b..7d6ced99e 100644
--- a/test/java/net/yacy/kelondro/util/FileUtilsTest.java
+++ b/test/java/net/yacy/kelondro/util/FileUtilsTest.java
@@ -26,6 +26,8 @@ import java.io.ByteArrayOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import org.junit.Assert;
@@ -153,6 +155,60 @@ public class FileUtilsTest {
}
/**
+ * Copy reader : normal case
+ * @throws IOException when a read/write error occurred
+ */
+ @Test
+ public void testCopyReaderWriter() throws IOException {
+ StringReader source = new StringReader("A test string");
+ StringWriter dest = new StringWriter();
+
+ try {
+ FileUtils.copy(source, dest);
+ } finally {
+ source.close();
+ dest.close();
+ }
+ Assert.assertEquals("A test string", dest.toString());
+ }
+
+ /**
+ * Copy reader : empty input
+ * @throws IOException when a read/write error occurred
+ */
+ @Test
+ public void testCopyEmptyReaderWriter() throws IOException {
+ StringReader source = new StringReader("");
+ StringWriter dest = new StringWriter();
+ try {
+ FileUtils.copy(source, dest);
+ } finally {
+ source.close();
+ dest.close();
+ }
+ Assert.assertEquals("", dest.toString());
+ }
+
+ /**
+ * Copy reader : writer with existing content
+ * @throws IOException when a read/write error occurred
+ */
+ @Test
+ public void testCopyReaderWriterNotEmpty() throws IOException {
+ StringReader source = new StringReader("An input String");
+ StringWriter dest = new StringWriter();
+
+ try {
+ dest.write("Non empty out stream.");
+ FileUtils.copy(source, dest);
+ } finally {
+ source.close();
+ dest.close();
+ }
+ Assert.assertEquals("Non empty out stream.An input String", dest.toString());
+ }
+
+ /**
* Test reading n bytes in a stream
* @throws IOException when a read/write error occurred
*/