diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/CompoundReaderTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/CompoundReaderTestCase.java index 5419741a..a3a4ed2f 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/CompoundReaderTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/CompoundReaderTestCase.java @@ -2,6 +2,7 @@ package com.twelvemonkeys.io; import com.twelvemonkeys.lang.StringUtil; import com.twelvemonkeys.util.CollectionUtil; +import org.junit.Test; import java.io.Reader; import java.io.IOException; @@ -9,6 +10,8 @@ import java.io.StringReader; import java.util.List; import java.util.ArrayList; +import static org.junit.Assert.*; + /** * CompoundReaderTestCase *
@@ -18,7 +21,6 @@ import java.util.ArrayList; * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/CompoundReaderTestCase.java#2 $ */ public class CompoundReaderTestCase extends ReaderAbstractTestCase { - protected Reader makeReader(String pInput) { // Split String[] input = StringUtil.toStringArray(pInput, " "); @@ -36,6 +38,7 @@ public class CompoundReaderTestCase extends ReaderAbstractTestCase { return new CompoundReader(readers.iterator()); } + @Test public void testNullConstructor() { try { new CompoundReader(null); @@ -46,11 +49,13 @@ public class CompoundReaderTestCase extends ReaderAbstractTestCase { } } + @Test public void testEmptyIteratorConstructor() throws IOException { Reader reader = new CompoundReader(CollectionUtil.iterator(new Reader[0])); assertEquals(-1, reader.read()); } + @Test public void testIteratorWithNullConstructor() throws IOException { try { new CompoundReader(CollectionUtil.iterator(new Reader[] {null})); diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/FastByteArrayOutputStreamTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/FastByteArrayOutputStreamTestCase.java index 389184bf..95f09ccf 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/FastByteArrayOutputStreamTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/FastByteArrayOutputStreamTestCase.java @@ -1,8 +1,12 @@ package com.twelvemonkeys.io; +import org.junit.Test; + import java.io.IOException; import java.io.InputStream; +import static org.junit.Assert.assertEquals; + /** * FastByteArrayOutputStreamTestCase * @@ -16,6 +20,7 @@ public class FastByteArrayOutputStreamTestCase extends OutputStreamAbstractTestC return new FastByteArrayOutputStream(256); } + @Test public void testCreateInputStream() throws IOException { FastByteArrayOutputStream out = makeObject(); diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/FileCacheSeekableStreamTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/FileCacheSeekableStreamTestCase.java index 3f66aa38..d12e9ca5 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/FileCacheSeekableStreamTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/FileCacheSeekableStreamTestCase.java @@ -11,10 +11,6 @@ import java.io.InputStream; * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/FileCacheSeekableStreamTestCase.java#3 $ */ public class FileCacheSeekableStreamTestCase extends SeekableInputStreamAbstractTestCase { - public FileCacheSeekableStreamTestCase(String name) { - super(name); - } - protected SeekableInputStream makeInputStream(final InputStream pStream) { try { return new FileCacheSeekableStream(pStream); diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/FileSeekableStreamTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/FileSeekableStreamTestCase.java index 6dbb401e..65f3c989 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/FileSeekableStreamTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/FileSeekableStreamTestCase.java @@ -1,7 +1,11 @@ package com.twelvemonkeys.io; +import org.junit.Test; + import java.io.*; +import static org.junit.Assert.*; + /** * MemoryCacheSeekableStreamTestCase * @@ -10,10 +14,6 @@ import java.io.*; * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/FileSeekableStreamTestCase.java#3 $ */ public class FileSeekableStreamTestCase extends SeekableInputStreamAbstractTestCase { - public FileSeekableStreamTestCase(String name) { - super(name); - } - protected SeekableInputStream makeInputStream(final InputStream pStream) { try { return new FileSeekableStream(createFileWithContent(pStream)); @@ -37,11 +37,13 @@ public class FileSeekableStreamTestCase extends SeekableInputStreamAbstractTestC return temp; } + @Test @Override public void testCloseUnderlyingStream() throws IOException { // There is no underlying stream here... } + @Test public void testCloseUnderlyingFile() throws IOException { final boolean[] closed = new boolean[1]; diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTestCase.java index 70e862cb..3688c7bd 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTestCase.java @@ -17,12 +17,15 @@ package com.twelvemonkeys.io; import com.twelvemonkeys.lang.ObjectAbstractTestCase; +import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Random; +import static org.junit.Assert.*; + /** * InputStreamAbstractTestCase * @@ -38,10 +41,6 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase final static private long SEED = 29487982745l; final static Random sRandom = new Random(SEED); - public InputStreamAbstractTestCase(String name) { - super(name); - } - protected final Object makeObject() { return makeInputStream(); } @@ -71,6 +70,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase return bytes; } + @Test public void testRead() throws Exception { int size = 5; InputStream input = makeInputStream(makeOrderedArray(size)); @@ -90,6 +90,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testAvailable() throws Exception { InputStream input = makeInputStream(1); assertFalse("Unexpected EOF", input.read() < 0); @@ -100,6 +101,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase assertEquals("Available after End of File", 0, input.available()); } + @Test public void testReadByteArray() throws Exception { byte[] bytes = new byte[10]; byte[] data = makeOrderedArray(15); @@ -145,6 +147,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testEOF() throws Exception { InputStream input = makeInputStream(makeOrderedArray(2)); assertEquals("Read 1", 0, input.read()); @@ -154,6 +157,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase assertEquals("Read 5", -1, input.read()); } + @Test public void testMarkResetUnsupported() throws IOException { InputStream input = makeInputStream(10); if (input.markSupported()) { @@ -176,6 +180,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testResetNoMark() throws Exception { InputStream input = makeInputStream(makeOrderedArray(10)); @@ -196,6 +201,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testMarkReset() throws Exception { InputStream input = makeInputStream(makeOrderedArray(25)); @@ -226,6 +232,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testResetAfterReadLimit() throws Exception { InputStream input = makeInputStream(makeOrderedArray(25)); @@ -257,6 +264,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testResetAfterReset() throws Exception { InputStream input = makeInputStream(makeOrderedArray(25)); @@ -274,9 +282,9 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase assertTrue("Expected to read positive value", read >= 0); input.reset(); - assertEquals("Expected value read differes from actual", read, input.read()); + assertEquals("Expected value read differs from actual", read, input.read()); - // Reset after read limit passed, may either throw exception, or reset to last mark + // Reset after read limit passed, may either throw exception, or reset to last good mark try { input.reset(); assertEquals("Re-read of reset data should be same", read, input.read()); @@ -286,6 +294,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testSkip() throws Exception { InputStream input = makeInputStream(makeOrderedArray(10)); @@ -302,6 +311,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase assertEquals("Unexpected value read after EOF", -1, input.read()); } + @Test public void testSanityOrdered() throws IOException { // This is to sanity check that the test itself is correct... byte[] bytes = makeOrderedArray(25); @@ -314,6 +324,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testSanityOrdered2() throws IOException { // This is to sanity check that the test itself is correct... byte[] bytes = makeOrderedArray(25); @@ -332,6 +343,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testSanityNegative() throws IOException { // This is to sanity check that the test itself is correct... byte[] bytes = new byte[25]; @@ -347,6 +359,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testSanityNegative2() throws IOException { // This is to sanity check that the test itself is correct... byte[] bytes = new byte[25]; @@ -368,6 +381,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testSanityRandom() throws IOException { // This is to sanity check that the test itself is correct... byte[] bytes = makeRandomArray(25); @@ -380,6 +394,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase } } + @Test public void testSanityRandom2() throws IOException { // This is to sanity check that the test itself is correct... byte[] bytes = makeRandomArray(25); diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/MemoryCacheSeekableStreamTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/MemoryCacheSeekableStreamTestCase.java index e0ee5289..53387cb5 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/MemoryCacheSeekableStreamTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/MemoryCacheSeekableStreamTestCase.java @@ -10,10 +10,6 @@ import java.io.InputStream; * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/MemoryCacheSeekableStreamTestCase.java#2 $ */ public class MemoryCacheSeekableStreamTestCase extends SeekableInputStreamAbstractTestCase { - public MemoryCacheSeekableStreamTestCase(String name) { - super(name); - } - protected SeekableInputStream makeInputStream(final InputStream pStream) { return new MemoryCacheSeekableStream(pStream); } diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/OutputStreamAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/OutputStreamAbstractTestCase.java index 4ed2568b..d3405dae 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/OutputStreamAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/OutputStreamAbstractTestCase.java @@ -1,10 +1,13 @@ package com.twelvemonkeys.io; import com.twelvemonkeys.lang.ObjectAbstractTestCase; +import org.junit.Test; import java.io.OutputStream; import java.io.IOException; +import static org.junit.Assert.*; + /** * InputStreamAbstractTestCase * @@ -15,6 +18,7 @@ import java.io.IOException; public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCase { protected abstract OutputStream makeObject(); + @Test public void testWrite() throws IOException { OutputStream os = makeObject(); @@ -23,12 +27,14 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testWriteByteArray() throws IOException { OutputStream os = makeObject(); os.write(new byte[256]); } + @Test public void testWriteByteArrayNull() { OutputStream os = makeObject(); try { @@ -46,7 +52,8 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } - public void testWriteByteArrayOffsetLenght() throws IOException { + @Test + public void testWriteByteArrayOffsetLength() throws IOException { byte[] input = new byte[256]; OutputStream os = makeObject(); @@ -65,7 +72,8 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } - public void testWriteByteArrayZeroLenght() { + @Test + public void testWriteByteArrayZeroLength() { OutputStream os = makeObject(); try { os.write(new byte[1], 0, 0); @@ -75,7 +83,8 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } - public void testWriteByteArrayOffsetLenghtNull() { + @Test + public void testWriteByteArrayOffsetLengthNull() { OutputStream os = makeObject(); try { os.write(null, 5, 10); @@ -92,6 +101,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testWriteByteArrayNegativeOffset() { OutputStream os = makeObject(); try { @@ -109,6 +119,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testWriteByteArrayNegativeLength() { OutputStream os = makeObject(); try { @@ -126,6 +137,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testWriteByteArrayOffsetOutOfBounds() { OutputStream os = makeObject(); try { @@ -143,6 +155,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testWriteByteArrayLengthOutOfBounds() { OutputStream os = makeObject(); try { @@ -160,14 +173,17 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testFlush() { // TODO: Implement } + @Test public void testClose() { // TODO: Implement } + @Test public void testWriteAfterClose() throws IOException { OutputStream os = makeObject(); @@ -200,6 +216,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testFlushAfterClose() throws IOException { OutputStream os = makeObject(); @@ -221,6 +238,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas } } + @Test public void testCloseAfterClose() throws IOException { OutputStream os = makeObject(); diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/ReaderAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/ReaderAbstractTestCase.java index cee9bc6f..cf9e63d5 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/ReaderAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/ReaderAbstractTestCase.java @@ -1,10 +1,13 @@ package com.twelvemonkeys.io; import com.twelvemonkeys.lang.ObjectAbstractTestCase; +import org.junit.Test; import java.io.Reader; import java.io.IOException; +import static org.junit.Assert.*; + /** * ReaderAbstractTestCase * @@ -36,6 +39,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { protected abstract Reader makeReader(String pInput); + @Test public void testRead() throws IOException { Reader reader = makeReader(); @@ -51,6 +55,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { assertEquals(mInput, buffer.toString()); } + @Test public void testReadBuffer() throws IOException { Reader reader = makeReader(); @@ -70,6 +75,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { assertEquals(mInput, new String(chars)); } + @Test public void testSkipToEnd() throws IOException { Reader reader = makeReader(); @@ -83,6 +89,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { assertEquals(0, toSkip); } + @Test public void testSkipToEndAndRead() throws IOException { Reader reader = makeReader(); @@ -95,6 +102,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { } // TODO: It's possible to support reset and not mark (resets to beginning of stream, for example) + @Test public void testResetMarkSupported() throws IOException { Reader reader = makeReader(); @@ -154,6 +162,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { } } + @Test public void testResetMarkNotSupported() throws IOException { Reader reader = makeReader(); @@ -198,7 +207,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase { } } - + @Test public void testReadAfterClose() throws IOException { Reader reader = makeReader("foo bar"); diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableAbstractTestCase.java index 61b471ab..28dfb036 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableAbstractTestCase.java @@ -1,6 +1,8 @@ package com.twelvemonkeys.io; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.*; /** * SeekableAbstractTestCase @@ -9,14 +11,16 @@ import junit.framework.TestCase; * @author Harald Kuhr * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/SeekableAbstractTestCase.java#1 $ */ -public abstract class SeekableAbstractTestCase extends TestCase implements SeekableInterfaceTest { +public abstract class SeekableAbstractTestCase implements SeekableInterfaceTest { protected abstract Seekable createSeekable(); + @Test public void testFail() { - fail(); + fail("Do not create stand-alone test classes based on this class. Instead, create an inner class and delegate to it."); } + @Test public void testSeekable() { assertTrue(createSeekable() instanceof Seekable); } diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableInputStreamAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableInputStreamAbstractTestCase.java index f0c0b844..7a995e49 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableInputStreamAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/SeekableInputStreamAbstractTestCase.java @@ -1,10 +1,14 @@ package com.twelvemonkeys.io; +import org.junit.Test; + import java.io.ByteArrayInputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; +import static org.junit.Assert.*; + /** * SeekableInputStreamAbstractTestCase * @@ -13,13 +17,8 @@ import java.io.InputStream; * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/SeekableInputStreamAbstractTestCase.java#4 $ */ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbstractTestCase implements SeekableInterfaceTest { - - public SeekableInputStreamAbstractTestCase(String name) { - super(name); - } - //// TODO: Figure out a better way of creating interface tests without duplicating code - final SeekableAbstractTestCase mSeekableTestCase = new SeekableAbstractTestCase() { + final SeekableAbstractTestCase seekableTestCase = new SeekableAbstractTestCase() { protected Seekable createSeekable() { return makeInputStream(); } @@ -41,6 +40,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs protected abstract SeekableInputStream makeInputStream(InputStream pStream); + @Test @Override public void testResetAfterReset() throws Exception { InputStream input = makeInputStream(makeOrderedArray(25)); @@ -59,9 +59,9 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs assertTrue("Expected to read positive value", read >= 0); input.reset(); - assertEquals("Expected value read differes from actual", read, input.read()); + assertEquals("Expected value read differs from actual", read, input.read()); - // Reset after read limit passed, may either throw exception, or reset to last mark + // Reset after read limit passed, may either throw exception, or reset to last good mark try { input.reset(); assertEquals("Re-read of reset data should be first", 0, input.read()); @@ -71,10 +71,12 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs } } + @Test public void testSeekable() { - mSeekableTestCase.testSeekable(); + seekableTestCase.testSeekable(); } + @Test public void testFlushBeyondCurrentPos() throws Exception { SeekableInputStream seekable = makeInputStream(20); @@ -88,6 +90,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs } } + @Test public void testSeek() throws Exception { SeekableInputStream seekable = makeInputStream(55); int pos = 37; @@ -97,6 +100,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs assertEquals("Stream positon should match seeked position", pos, streamPos); } + @Test public void testSeekFlush() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; @@ -114,6 +118,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs } } + @Test public void testMarkFlushReset() throws Exception { SeekableInputStream seekable = makeInputStream(77); @@ -134,6 +139,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs assertEquals(position, seekable.getStreamPosition()); } + @Test public void testSeekSkipRead() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; @@ -147,7 +153,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs } } - public void testSeekSkip(SeekableInputStream pSeekable, String pStr) throws IOException { + protected void testSeekSkip(SeekableInputStream pSeekable, String pStr) throws IOException { System.out.println(); pSeekable.seek(pStr.length()); FileUtil.read(pSeekable); @@ -330,6 +336,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs } */ + @Test public void testReadResetReadDirectBufferBug() throws IOException { // Make sure we use the exact size of the buffer final int size = 1024; @@ -365,6 +372,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs assertTrue(rangeEquals(bytes, size, result, 0, size)); } + @Test public void testReadAllByteValuesRegression() throws IOException { final int size = 128; @@ -401,6 +409,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs } + @Test public void testCloseUnderlyingStream() throws IOException { final boolean[] closed = new boolean[1]; @@ -476,5 +485,4 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs return true; } - } diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/StringArrayReaderTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/StringArrayReaderTestCase.java index 42af1ddf..cf1594c9 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/StringArrayReaderTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/StringArrayReaderTestCase.java @@ -1,10 +1,13 @@ package com.twelvemonkeys.io; import com.twelvemonkeys.lang.StringUtil; +import org.junit.Test; import java.io.Reader; import java.io.IOException; +import static org.junit.Assert.*; + /** * StringArrayReaderTestCase * @@ -28,6 +31,7 @@ public class StringArrayReaderTestCase extends ReaderAbstractTestCase { return new StringArrayReader(input); } + @Test public void testNullConstructor() { try { new StringArrayReader(null); @@ -38,15 +42,15 @@ public class StringArrayReaderTestCase extends ReaderAbstractTestCase { } } + @Test public void testEmptyArrayConstructor() throws IOException { Reader reader = new StringArrayReader(new String[0]); assertEquals(-1, reader.read()); } + @Test public void testEmptyStringConstructor() throws IOException { Reader reader = new StringArrayReader(new String[] {""}); assertEquals(-1, reader.read()); } - - } diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64DecoderTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64DecoderTestCase.java index 3a304437..922bf5b5 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64DecoderTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64DecoderTestCase.java @@ -2,9 +2,12 @@ package com.twelvemonkeys.io.enc; import com.twelvemonkeys.io.FileUtil; +import org.junit.Test; import java.io.*; +import static org.junit.Assert.*; + /** * Base64DecoderTest * @@ -22,6 +25,7 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase { return new Base64Encoder(); } + @Test public void testEmptyDecode2() throws IOException { String data = ""; @@ -33,6 +37,7 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase { assertEquals("Strings does not match", "", new String(bytes.toByteArray())); } + @Test public void testShortDecode() throws IOException { String data = "dGVzdA=="; @@ -44,6 +49,7 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase { assertEquals("Strings does not match", "test", new String(bytes.toByteArray())); } + @Test public void testLongDecode() throws IOException { String data = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" + "c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" + @@ -62,4 +68,4 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase { "ullamcorper, nisi in dictum amet.", new String(bytes.toByteArray())); } -} +} \ No newline at end of file diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64EncoderTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64EncoderTestCase.java index c8331751..c1177538 100644 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64EncoderTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/Base64EncoderTestCase.java @@ -1,7 +1,11 @@ package com.twelvemonkeys.io.enc; +import org.junit.Test; + import java.io.*; +import static org.junit.Assert.*; + /** * Base64EncoderTest * @@ -19,6 +23,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase { return new Base64Decoder(); } + @Test public void testNegativeEncode() throws IOException { Encoder encoder = createEncoder(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); @@ -31,6 +36,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase { } } + @Test public void testEmptyEncode() throws IOException { String data = ""; @@ -41,6 +47,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase { assertEquals("Strings does not match", "", new String(bytes.toByteArray())); } + @Test public void testShortEncode() throws IOException { String data = "test"; @@ -51,6 +58,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase { assertEquals("Strings does not match", "dGVzdA==", new String(bytes.toByteArray())); } + @Test public void testLongEncode() throws IOException { String data = "Lorem ipsum dolor sit amet, consectetuer adipiscing " + "elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " + diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/DecoderAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/DecoderAbstractTestCase.java index 6522363e..d4578897 100644 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/DecoderAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/DecoderAbstractTestCase.java @@ -2,10 +2,13 @@ package com.twelvemonkeys.io.enc; import com.twelvemonkeys.io.FileUtil; import com.twelvemonkeys.lang.ObjectAbstractTestCase; +import org.junit.Test; import java.io.*; import java.util.Arrays; +import static org.junit.Assert.*; + /** * AbstractDecoderTest * @@ -22,6 +25,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase { return createDecoder(); } + @Test public final void testNullDecode() throws IOException { Decoder decoder = createDecoder(); ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]); @@ -34,6 +38,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase { } } + @Test public final void testEmptyDecode() throws IOException { Decoder decoder = createDecoder(); ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[0]); @@ -81,6 +86,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase { assertTrue(Arrays.equals(data, decoded)); } + @Test public final void testStreams() throws Exception { for (int i = 0; i < 100; i++) { try { diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/EncoderAbstractTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/EncoderAbstractTestCase.java index 32266fe6..8bf50fc2 100644 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/enc/EncoderAbstractTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/enc/EncoderAbstractTestCase.java @@ -2,11 +2,14 @@ package com.twelvemonkeys.io.enc; import com.twelvemonkeys.io.FileUtil; import com.twelvemonkeys.lang.ObjectAbstractTestCase; +import org.junit.Test; import java.io.*; import java.util.Arrays; import java.util.Random; +import static org.junit.Assert.*; + /** * AbstractEncoderTest * @@ -26,6 +29,7 @@ public abstract class EncoderAbstractTestCase extends ObjectAbstractTestCase { return createEncoder(); } + @Test public final void testNullEncode() throws IOException { Encoder encoder = createEncoder(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); @@ -79,6 +83,7 @@ public abstract class EncoderAbstractTestCase extends ObjectAbstractTestCase { assertTrue(Arrays.equals(data, decoded)); } + @Test public final void testStreams() throws Exception { for (int i = 0; i < 100; i++) { try { diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocumentTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocumentTestCase.java index 24d9b3da..ccbf18da 100755 --- a/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocumentTestCase.java +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocumentTestCase.java @@ -1,6 +1,7 @@ package com.twelvemonkeys.io.ole2; -import junit.framework.TestCase; +import com.twelvemonkeys.io.MemoryCacheSeekableStream; +import org.junit.Test; import javax.imageio.stream.MemoryCacheImageInputStream; import java.io.File; @@ -9,6 +10,10 @@ import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; import java.nio.ByteOrder; +import java.util.SortedSet; +import java.util.TreeSet; + +import static org.junit.Assert.*; /** * CompoundDocumentTestCase @@ -17,9 +22,89 @@ import java.nio.ByteOrder; * @author last modified by $Author: haku $ * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocumentTestCase.java#1 $ */ -public class CompoundDocumentTestCase extends TestCase { +public class CompoundDocumentTestCase { + + private static final String SAMPLE_DATA = "/Thumbs-camera.db"; + + protected final CompoundDocument createTestDocument() throws IOException { + URL input = getClass().getResource(SAMPLE_DATA); + + assertNotNull("Missing test resource!", input); + assertEquals("Test resource not a file:// resource", "file", input.getProtocol()); + + try { + return new CompoundDocument(new File(input.toURI())); + } + catch (URISyntaxException e) { + throw new AssertionError(e); + } + } + + @Test + public void testRoot() throws IOException { + CompoundDocument document = createTestDocument(); + + Entry root = document.getRootEntry(); + + assertNotNull(root); + assertEquals("Root Entry", root.getName()); + assertTrue(root.isRoot()); + assertFalse(root.isFile()); + assertFalse(root.isDirectory()); + assertEquals(0, root.length()); + assertNull(root.getInputStream()); + } + + @Test + public void testContents() throws IOException { + CompoundDocument document = createTestDocument(); + + Entry root = document.getRootEntry(); + + assertNotNull(root); + + SortedSet