@Test public void testCopyFile_File_File() throws Exception { System.out.println("copyFile"); File in = new File(testDir + "20100618/test1.txt"); File out = new File(testDir + "20100618/test2.txt"); IOUtils.copyFile(in, out); String a = IOUtils.readFile(out.getCanonicalPath()); String b = IOUtils.readFile(in.getCanonicalPath()); assertEquals(a, b); }
/** Test of saveObject method, of class IOUtils. */ @Test public void testSaveLoadObject() { System.out.println("saveObject"); String[] saveObj = {"blah", "blah1", "blah2"}; String addr = testDir + "20100618/obj1.oats"; IOUtils.saveObject(saveObj, addr); String[] result = (String[]) IOUtils.loadObject(addr); assertEquals(saveObj, result); }
@Test public void testCopyFile_String_String() throws Exception { System.out.println("copyFile"); String in = testDir + "20100618/test1.txt"; String out = testDir + "20100618/test2.txt"; IOUtils.copyFile(in, out); String a = IOUtils.readFile(out); String b = IOUtils.readFile(in); assertEquals(a, b); }
/** Test of writeString2File method, of class IOUtils. */ @Test public void testWriteString2File() throws Exception { System.out.println("writeString2File"); String expected = "blah blah blah\n"; String addr = testDir + "20100618/test1.txt"; IOUtils.writeString2File(expected, addr); String actual = IOUtils.readFile(addr); assertEquals(expected, actual); }
/** Test of StringArrToFile method, of class IOUtils. */ @Test public void testStringArrToFile() { System.out.println("StringArrToFile"); String[] sortedLines = {"line1", "line2", "line3"}; String addr2 = testDir + "20100618/stringArrToFile.txt"; String newline = "\n"; IOUtils.StringArrToFile(sortedLines, addr2, newline); String result = IOUtils.readFile(addr2); System.out.println(result); String expected = "line1\nline2\nline3\n"; assertEquals(expected, result); }
@Test public void testCloseQuietlySocketOpen() { final Socket s = new Socket(); assertFalse(s.isClosed()); IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
@Test public void testCloseQuietlyServerSocketOpen() throws IOException { final ServerSocket s = new ServerSocket(0); assertFalse(s.isClosed()); IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
@Test public void testCloseQuietlyImageInputStreamClosed() throws IOException { final ImageInputStream in = new MemoryCacheImageInputStream(new ClosedInputStream()); in.close(); IOUtils.closeQuietly(in); }
@Test public void testFileNameExtention() { System.out.println("fileNameExtention"); File srcImg = new File(testDir + "20110116/frame0001.jpg"); String expResult = "jpg"; String result = IOUtils.fileNameExtention(srcImg); assertEquals(expResult, result); }
@Test public void testReadFile() { System.out.println("readFile"); String in = testDir + "20100618/test1.txt"; String expResult = "blah blah blah\n"; String result = IOUtils.readFile(in); assertEquals(expResult, result); }
@Test public void testFileNameExtention_File() { System.out.println("testFileNameExtention_File"); File file = new File("/temp1.jpgs"); String expected = "jpgs"; String result = IOUtils.fileNameExtention(file); assertEquals(expected, result); }
/** Test of fileToString method, of class IOUtils. */ @Test public void testFileToString() throws Exception { System.out.println("fileToString"); String filename = testDir + "20100618/test3.txt"; String expResult = "abfk1\n"; String result = IOUtils.fileToString(filename); assertEquals(expResult, result); }
@Test public void testCloseQuietlySocketClosed() throws IOException { final Socket s = new Socket(); s.close(); assertTrue(s.isClosed()); IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
/** Test of intArr2Str method, of class IOUtils. */ @Test public void testIntArr2Str() { System.out.println("intArr2Str"); int[] idxRing = {1, 2, 3}; String expResult = "1 2 3"; String result = IOUtils.intArr2Str(idxRing); assertEquals(expResult, result); }
@Test public void testReadClosed() throws IOException { final InputStream in = new ClosedInputStream(); final byte[] buf = new byte[1]; final int count = IOUtils.read(in, buf); assertEquals(-1, count); assertArrayEquals(new byte[1], buf); }
@Test public void testImagesInDir_File_boolean() { System.out.println("test Images In Dir File Boolean"); System.out.println("imagesInDir"); File dir = new File(this.testDir + "20101015/"); boolean traverse_subdirs = false; File[] expResult = {new File(testDir + "20101015/test1.jpg")}; File[] result = IOUtils.imagesInDir(dir, traverse_subdirs); assertEquals(expResult, result); }
@Test public void testTouch() { System.out.println("touch"); File file = new File(testDir + "20101015/touch"); // System.out.println(file.toString()); file.delete(); IOUtils.touch(file); assertTrue(file.exists()); file.delete(); }
@Test public void testReadFull() throws IOException { final byte[] expected = new byte[100]; Arrays.fill(expected, (byte) 1); final InputStream in = new ByteArrayInputStream(expected); final byte[] actual = new byte[100]; final int count = IOUtils.read(in, actual); assertEquals(expected.length, count); assertArrayEquals(expected, actual); }
@Test public void testCloseQuietlyZipFileOpen() throws IOException { final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip"); IOUtils.closeQuietly(zf); try { zf.size(); fail(); } catch (IllegalStateException e) { // This is the expected behavior of size(). } }
@Test public void testReadShort() throws IOException { final byte[] expected = new byte[50]; Arrays.fill(expected, (byte) 1); final InputStream in = new ByteArrayInputStream(expected); final byte[] actual = new byte[100]; final int count = IOUtils.read(in, actual); assertEquals(50, count); assertArrayEquals(expected, Arrays.copyOfRange(actual, 0, count)); assertArrayEquals(new byte[50], Arrays.copyOfRange(actual, count, 100)); }
@Test public void testCloseQuietlyImageInputStreamOpen() { final ImageInputStream in = new MemoryCacheImageInputStream(new NullInputStream(1000)); IOUtils.closeQuietly(in); try { in.close(); fail(); } catch (IOException e) { // This, oddly, the expected behavior of close(). } }
@Test public void testCloseQuietlyCloseableOk() throws IOException { final Closeable c = context.mock(Closeable.class); context.checking( new Expectations() { { oneOf(c).close(); } }); IOUtils.closeQuietly(c); }
@Test public void testImagesInDir_String_boolean() { System.out.println("imagesInDir"); String dirAddr = this.testDir + "20101015/"; boolean traverse_subdirs = false; File e1 = new File(dirAddr + "test1.jpg"); File[] expected = {e1}; File[] result = IOUtils.imagesInDir(dirAddr, traverse_subdirs); assertEquals(expected.length, result.length); Arrays.sort(expected); Arrays.sort(result); assertEquals(expected[0].getAbsoluteFile(), result[0].getAbsoluteFile()); }
@Test public void testCopyLargeFileChannels() throws IOException { final File ifile = new File("test/VASSAL/tools/io/IOUtilsTest.java"); final File ofile = new File("test/VASSAL/tools/io/test.out"); try { final FileInputStream in = new FileInputStream(ifile); final FileOutputStream out = new FileOutputStream(ofile); final long count = IOUtils.copy(in, out); assertEquals(ifile.length(), count); assertTrue(FileUtils.contentEquals(ifile, ofile)); } finally { ofile.delete(); } }
@Test public void testCopyBuffer() throws IOException { final byte[] buf = new byte[1024]; final byte[] expected = new byte[10000]; final long seed = System.currentTimeMillis(); final Random rng = new Random(seed); rng.nextBytes(expected); final ByteArrayInputStream in = new ByteArrayInputStream(expected); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int count = IOUtils.copy(in, out, buf); assertEquals("seed == " + seed, expected.length, count); assertArrayEquals("seed == " + seed, expected, out.toByteArray()); }
@Test public void testCloseQuietlySocketNull() { IOUtils.closeQuietly((Socket) null); }
@Test public void testCloseQuietlyZipFileClosed() throws IOException { final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip"); zf.close(); IOUtils.closeQuietly(zf); }
@Test public void testCloseQuietlyZipFileNull() { IOUtils.closeQuietly((ZipFile) null); }
@Test public void testCloseQuietlyImageInputStreamNull() { IOUtils.closeQuietly((ImageInputStream) null); }
@Test public void testCloseQuietlyCloseableNull() { IOUtils.closeQuietly((Closeable) null); }