[Japi-cvs] SF.net SVN: japi:[1007] libs/io/trunk/src/tst
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2009-02-21 23:22:20
|
Revision: 1007
http://japi.svn.sourceforge.net/japi/?rev=1007&view=rev
Author: christianhujer
Date: 2009-02-21 22:03:37 +0000 (Sat, 21 Feb 2009)
Log Message:
-----------
Added unit tests for japi-lib-io.
Added Paths:
-----------
libs/io/trunk/src/tst/test/
libs/io/trunk/src/tst/test/net/
libs/io/trunk/src/tst/test/net/sf/
libs/io/trunk/src/tst/test/net/sf/japi/
libs/io/trunk/src/tst/test/net/sf/japi/io/
libs/io/trunk/src/tst/test/net/sf/japi/io/CopierTest.java
libs/io/trunk/src/tst/test/net/sf/japi/io/IOUtilsTest.java
Added: libs/io/trunk/src/tst/test/net/sf/japi/io/CopierTest.java
===================================================================
--- libs/io/trunk/src/tst/test/net/sf/japi/io/CopierTest.java (rev 0)
+++ libs/io/trunk/src/tst/test/net/sf/japi/io/CopierTest.java 2009-02-21 22:03:37 UTC (rev 1007)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 Christian Hujer.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package test.net.sf.japi.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+import net.sf.japi.io.Copier;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link Copier}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class CopierTest {
+
+ /** Tests that Copier copies from one stream to another. */
+ @Test
+ public void testCopy() {
+ final byte[] input = { 0x00, 0x01, 0x7F, 0x03, 0x40 };
+ final byte[] verification = input.clone();
+ Assert.assertNotSame("Expecting verification to be a new array.", input, verification);
+ final ByteArrayInputStream in = new ByteArrayInputStream(input);
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final Copier testling = new Copier(in, out);
+ testling.run();
+ final byte[] output = out.toByteArray();
+ Assert.assertTrue("Expecting input to be unchanged.", Arrays.equals(verification, input));
+ Assert.assertTrue("Expecting output to be like input.", Arrays.equals(verification, output));
+ Assert.assertNotSame("Expecting output to be a new array.", input, output);
+ Assert.assertNotSame("Expecting output to be a new array.", verification, output);
+ }
+}
Property changes on: libs/io/trunk/src/tst/test/net/sf/japi/io/CopierTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/io/trunk/src/tst/test/net/sf/japi/io/IOUtilsTest.java
===================================================================
--- libs/io/trunk/src/tst/test/net/sf/japi/io/IOUtilsTest.java (rev 0)
+++ libs/io/trunk/src/tst/test/net/sf/japi/io/IOUtilsTest.java 2009-02-21 22:03:37 UTC (rev 1007)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2009 Christian Hujer.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package test.net.sf.japi.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import net.sf.japi.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link IOUtils}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class IOUtilsTest {
+
+ /** Tests that {@link IOUtils#copy(InputStream, OutputStream)} works.
+ * @throws IOException (unexpected)
+ */
+ @Test
+ public void testCopy() throws IOException {
+ final byte[] input = { 0x00, 0x01, 0x7F, 0x03, 0x40 };
+ final byte[] verification = input.clone();
+ Assert.assertNotSame("Expecting verification to be a new array.", input, verification);
+ final ByteArrayInputStream in = new ByteArrayInputStream(input);
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(in, out);
+ final byte[] output = out.toByteArray();
+ Assert.assertTrue("Expecting input to be unchanged.", Arrays.equals(verification, input));
+ Assert.assertTrue("Expecting output to be like input.", Arrays.equals(verification, output));
+ Assert.assertNotSame("Expecting output to be a new array.", input, output);
+ Assert.assertNotSame("Expecting output to be a new array.", verification, output);
+ }
+
+ /** Tests that {@link IOUtils#lines(Reader)} works. */
+ @Test
+ public void testLines() throws IOException {
+ final String input = "line1\nline2\nline3";
+ final Reader in = new StringReader(input);
+ final Iterable<String> lineIterable = IOUtils.lines(in);
+ final Iterator<String> lineIterator = lineIterable.iterator();
+ Assert.assertTrue(lineIterator.hasNext());
+ Assert.assertEquals("line1", lineIterator.next());
+ try {
+ lineIterator.remove();
+ Assert.fail();
+ } catch (final UnsupportedOperationException ignore) {
+ }
+ Assert.assertTrue(lineIterator.hasNext());
+ Assert.assertEquals("line2", lineIterator.next());
+ Assert.assertTrue(lineIterator.hasNext());
+ Assert.assertEquals("line3", lineIterator.next());
+ Assert.assertFalse(lineIterator.hasNext());
+ try {
+ lineIterator.next();
+ Assert.fail();
+ } catch (final NoSuchElementException ignore) {
+ }
+ }
+}
Property changes on: libs/io/trunk/src/tst/test/net/sf/japi/io/IOUtilsTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|