diff options
author | Harald Musum <musum@oath.com> | 2017-11-27 14:22:15 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2017-11-27 14:22:15 +0100 |
commit | 8230eb8c33f41b7253e95e98580648f8da40f12d (patch) | |
tree | a283bbd38a57cf7f71a3b11f9767ec9b56aa67cd /vespajlib/src/test/java/com | |
parent | b87c7b57179497299d3c7011b6b616838361e284 (diff) |
Copy files correctly
Use FileChannel to copy files instead of using Readers and Writers
(makes it work for binary files too)
Diffstat (limited to 'vespajlib/src/test/java/com')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/io/IOUtilsTestCase.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/io/IOUtilsTestCase.java b/vespajlib/src/test/java/com/yahoo/io/IOUtilsTestCase.java index 3a8b0dde1c1..8955bd9ea05 100644 --- a/vespajlib/src/test/java/com/yahoo/io/IOUtilsTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/IOUtilsTestCase.java @@ -1,15 +1,23 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; +import org.junit.Test; + import java.io.*; import java.util.Arrays; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author bratseth */ -public class IOUtilsTestCase extends junit.framework.TestCase { +public class IOUtilsTestCase { + @Test public void testCloseNUllDoesNotFail() { IOUtils.closeWriter(null); IOUtils.closeReader(null); @@ -17,12 +25,14 @@ public class IOUtilsTestCase extends junit.framework.TestCase { IOUtils.closeOutputStream(null); } + @Test public void testFileWriter() throws IOException { IOUtils.writeFile("temp1.txt", "hello",false); assertEquals("hello", IOUtils.readFile(new File("temp1.txt"))); new File("temp1.txt").delete(); } + @Test public void testFileWriterWithoutEncoding() throws IOException { BufferedWriter writer=null; try { @@ -36,6 +46,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { new File("temp2.txt").delete(); } + @Test public void testFileWriterWithoutEncodingFromFileName() throws IOException { BufferedWriter writer=null; try { @@ -49,12 +60,14 @@ public class IOUtilsTestCase extends junit.framework.TestCase { new File("temp3.txt").delete(); } + @Test public void testFileCounting() throws IOException { IOUtils.writeFile("temp4.txt","hello\nworld",false); assertEquals(2,IOUtils.countLines("temp4.txt")); new File("temp4.txt").delete(); } + @Test public void testFileCopy() throws IOException { IOUtils.writeFile("temp5.txt","hello",false); IOUtils.copy(new File("temp5.txt"), new File("temp5copy.txt")); @@ -63,6 +76,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { new File("temp5copy.txt").delete(); } + @Test public void testFileCopyWithLineCap() throws IOException { IOUtils.writeFile("temp6.txt","hello\nyou\nworld",false); IOUtils.copy("temp6.txt","temp6copy.txt",2); @@ -71,6 +85,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { new File("temp6copy.txt").delete(); } + @Test public void testGetLines() throws IOException { IOUtils.writeFile("temp7.txt","hello\nworld",false); List<String> lines=IOUtils.getLines("temp7.txt"); @@ -80,6 +95,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { new File("temp7.txt").delete(); } + @Test public void testFileWriterAppend() throws IOException { boolean append=true; IOUtils.writeFile("temp8.txt", "hello",!append); @@ -95,6 +111,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { new File("temp8.txt").delete(); } + @Test public void testCloseAllReaders() throws IOException { StringReader reader1=new StringReader("hello"); StringReader reader2=new StringReader("world"); @@ -115,6 +132,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { } } + @Test public void testDirCopying() throws IOException { IOUtils.writeFile("temp1/temp1.txt","hello",false); IOUtils.writeFile("temp1/temp2.txt","world",false); @@ -127,6 +145,7 @@ public class IOUtilsTestCase extends junit.framework.TestCase { assertTrue(!new File("temp2").exists()); } + @Test public void testDirCopyingWithFilter() throws IOException { IOUtils.writeFile("temp1/temp1.txt","hello",false); IOUtils.writeFile("temp1/temp2.txt","world",false); |