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 children = new TreeSet(root.getChildEntries()); + assertEquals(25, children.size()); + + // Weirdness in the file format, name is *written backwards* 1-24 + Catalog + for (String name : "1,2,3,4,5,6,7,8,9,01,02,11,12,21,22,31,32,41,42,51,61,71,81,91,Catalog".split(",")) { + assertEquals(name, children.first().getName()); + children.remove(children.first()); + } + } + + @Test(expected = UnsupportedOperationException.class) + public void testChildEntriesUnmodifiable() throws IOException { + CompoundDocument document = createTestDocument(); + + Entry root = document.getRootEntry(); + + assertNotNull(root); + + SortedSet children = root.getChildEntries(); + + // Should not be allowed, as it modifies the internal structure + children.remove(children.first()); + } + + @Test + public void testReadThumbsCatalogFile() throws IOException { + CompoundDocument document = createTestDocument(); + + Entry root = document.getRootEntry(); + + assertNotNull(root); + assertEquals(25, root.getChildEntries().size()); + + Entry catalog = root.getChildEntry("Catalog"); + + assertNotNull(catalog); + assertNotNull("Input stream may not be null", catalog.getInputStream()); + } + + @Test public void testReadCatalogInputStream() throws IOException { - InputStream input = getClass().getResourceAsStream("/Thumbs-camera.db"); + InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); @@ -33,8 +118,25 @@ public class CompoundDocumentTestCase extends TestCase { assertNotNull("Input stream may not be null", catalog.getInputStream()); } + @Test + public void testReadCatalogSeekableStream() throws IOException { + InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); + + assertNotNull("Missing test resource!", input); + + CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input)); + Entry root = document.getRootEntry(); + assertNotNull(root); + assertEquals(25, root.getChildEntries().size()); + + Entry catalog = root.getChildEntry("Catalog"); + assertNotNull(catalog); + assertNotNull("Input stream may not be null", catalog.getInputStream()); + } + + @Test public void testReadCatalogImageInputStream() throws IOException { - InputStream input = getClass().getResourceAsStream("/Thumbs-camera.db"); + InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); @@ -53,25 +155,4 @@ public class CompoundDocumentTestCase extends TestCase { assertNotNull(catalog); assertNotNull("Input stream may not be null", catalog.getInputStream()); } - - public void testReadThumbsCatalogFile() throws IOException, URISyntaxException { - URL input = getClass().getResource("/Thumbs-camera.db"); - - assertNotNull("Missing test resource!", input); - assertEquals("Test resource not a file:// resource", "file", input.getProtocol()); - - File file = new File(input.toURI()); - - CompoundDocument document = new CompoundDocument(file); - - Entry root = document.getRootEntry(); - - assertNotNull(root); - assertEquals(25, root.getChildEntries().size()); - - Entry catalog = root.getChildEntry("Catalog"); - - assertNotNull(catalog); - assertNotNull("Input stream may not be null", catalog.getInputStream()); - } } diff --git a/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocument_SeekableLittleEndianDataInputStreamTestCase.java b/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocument_SeekableLittleEndianDataInputStreamTestCase.java new file mode 100644 index 00000000..c53f56c6 --- /dev/null +++ b/common/common-io/src/test/java/com/twelvemonkeys/io/ole2/CompoundDocument_SeekableLittleEndianDataInputStreamTestCase.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, Harald Kuhr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name "TwelveMonkeys" nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.twelvemonkeys.io.ole2; + +import com.twelvemonkeys.io.*; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.ByteArrayInputStream; + +/** + * CompoundDocument_SeekableLittleEndianDataInputStreamTestCase + * + * @author Harald Kuhr + * @author last modified by $Author: haraldk$ + * @version $Id: CompoundDocument_SeekableLittleEndianDataInputStreamTestCase.java,v 1.0 18.10.11 16:35 haraldk Exp$ + */ +public class CompoundDocument_SeekableLittleEndianDataInputStreamTestCase extends InputStreamAbstractTestCase implements SeekableInterfaceTest { + private final SeekableInterfaceTest seekableTest = new SeekableAbstractTestCase() { + @Override + protected Seekable createSeekable() { + return (Seekable) makeInputStream(); + } + }; + + @Override + protected CompoundDocument.SeekableLittleEndianDataInputStream makeInputStream(byte[] pBytes) { + return new CompoundDocument.SeekableLittleEndianDataInputStream(new MemoryCacheSeekableStream(new ByteArrayInputStream(pBytes))); + } + + @Test + public void testSeekable() { + seekableTest.testSeekable(); + } + + @Ignore("Incompatible contracts, must be revised") @Test + @Override + public void testResetAfterReset() throws Exception { + super.testResetAfterReset(); + } +} diff --git a/common/common-lang/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java b/common/common-lang/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java index 17cd3c8c..6ed3f622 100755 --- a/common/common-lang/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java +++ b/common/common-lang/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java @@ -1,9 +1,11 @@ package com.twelvemonkeys.lang; -import junit.framework.TestCase; +import org.junit.Test; -import java.lang.reflect.Method; import java.io.*; +import java.lang.reflect.Method; + +import static org.junit.Assert.*; /** * AbstractObjectTestCase @@ -12,7 +14,7 @@ import java.io.*; * @author Harald Kuhr * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java#1 $ */ -public abstract class ObjectAbstractTestCase extends TestCase { +public abstract class ObjectAbstractTestCase { // TODO: See com.tm.util.ObjectAbstractTestCase // TODO: The idea is that this should be some generic base-class that // implements the basic object tests @@ -20,19 +22,6 @@ public abstract class ObjectAbstractTestCase extends TestCase { // TODO: Create Serializable test similar way // TODO: Create Comparable test similar way - /** - * Creates a {@code TestCase}. - * - * @param testName the test class name - */ - protected ObjectAbstractTestCase(String testName) { - super(testName); - } - - protected ObjectAbstractTestCase() { - super(); - } - /** * Returns an instance of the class we are testing. * Implement this method to return the object to test. @@ -47,23 +36,23 @@ public abstract class ObjectAbstractTestCase extends TestCase { //protected abstract Object makeEqualObject(Object pObject); + @Test public void testToString() { assertNotNull(makeObject().toString()); // TODO: What more can we test? } // TODO: assert that either BOTH or NONE of equals/hashcode is overridden + @Test public void testEqualsHashCode(){ Object obj = makeObject(); Class cl = obj.getClass(); if (isEqualsOverriden(cl)) { - assertTrue("Class " + cl.getName() - + " implements equals but not hashCode", isHashCodeOverriden(cl)); + assertTrue("Class " + cl.getName() + " implements equals but not hashCode", isHashCodeOverriden(cl)); } else if (isHashCodeOverriden(cl)) { - assertTrue("Class " + cl.getName() - + " implements hashCode but not equals", isEqualsOverriden(cl)); + assertTrue("Class " + cl.getName() + " implements hashCode but not equals", isEqualsOverriden(cl)); } } @@ -85,11 +74,13 @@ public abstract class ObjectAbstractTestCase extends TestCase { } } + @Test public void testObjectEqualsSelf() { Object obj = makeObject(); assertEquals("An Object should equal itself", obj, obj); } + @Test public void testEqualsNull() { Object obj = makeObject(); // NOTE: Makes sure this doesn't throw NPE either @@ -97,11 +88,13 @@ public abstract class ObjectAbstractTestCase extends TestCase { assertFalse("An object should never equal null", obj.equals(null)); } + @Test public void testObjectHashCodeEqualsSelfHashCode() { Object obj = makeObject(); assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode()); } + @Test public void testObjectHashCodeEqualsContract() { Object obj1 = makeObject(); if (obj1.equals(obj1)) { @@ -129,6 +122,7 @@ public abstract class ObjectAbstractTestCase extends TestCase { //////////////////////////////////////////////////////////////////////////// // Cloneable interface + @Test public void testClone() throws Exception { Object obj = makeObject(); if (obj instanceof Cloneable) { @@ -184,6 +178,7 @@ public abstract class ObjectAbstractTestCase extends TestCase { /////////////////////////////////////////////////////////////////////////// // Serializable interface + @Test public void testSerializeDeserializeThenCompare() throws Exception { Object obj = makeObject(); if (obj instanceof Serializable) { @@ -223,6 +218,7 @@ public abstract class ObjectAbstractTestCase extends TestCase { * @throws java.io.IOException * @throws ClassNotFoundException */ + @Test public void testSimpleSerialization() throws Exception { Object o = makeObject(); if (o instanceof Serializable) { @@ -305,14 +301,6 @@ public abstract class ObjectAbstractTestCase extends TestCase { } public static final class SanityTestTestCase extends ObjectAbstractTestCase { - /** - * Creates a {@code TestCase}. - * - */ - public SanityTestTestCase() { - super(SanityTestTestCase.class.getName()); - } - protected Object makeObject() { return new Cloneable() {}; } diff --git a/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/DateConverterTestCase.java b/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/DateConverterTestCase.java index 006acde8..c04fb798 100755 --- a/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/DateConverterTestCase.java +++ b/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/DateConverterTestCase.java @@ -1,6 +1,7 @@ package com.twelvemonkeys.util.convert; import com.twelvemonkeys.lang.DateUtil; +import org.junit.Test; import java.text.DateFormat; import java.util.Date; @@ -44,6 +45,7 @@ public class DateConverterTestCase extends PropertyConverterAbstractTestCase { }; } + @Test @Override public void testConvert() { TimeZone old = TimeZone.getDefault(); diff --git a/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java b/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java index 28987aa6..32d2e748 100755 --- a/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java +++ b/common/common-lang/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java @@ -1,9 +1,12 @@ package com.twelvemonkeys.util.convert; import com.twelvemonkeys.lang.ObjectAbstractTestCase; +import org.junit.Test; import java.util.Arrays; +import static org.junit.Assert.*; + /** * PropertyConverterAbstractTestCase *

@@ -13,7 +16,6 @@ import java.util.Arrays; * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java#2 $ */ public abstract class PropertyConverterAbstractTestCase extends ObjectAbstractTestCase { - protected Object makeObject() { return makePropertyConverter(); } @@ -22,8 +24,8 @@ public abstract class PropertyConverterAbstractTestCase extends ObjectAbstractTe protected abstract Conversion[] getTestConversions(); + @Test public void testConvert() { - PropertyConverter converter = makePropertyConverter(); Conversion[] tests = getTestConversions(); diff --git a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/IIOInputStreamAdapterTestCase.java b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/IIOInputStreamAdapterTestCase.java index b010109f..753d5240 100755 --- a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/IIOInputStreamAdapterTestCase.java +++ b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/IIOInputStreamAdapterTestCase.java @@ -29,11 +29,14 @@ package com.twelvemonkeys.imageio.util; import com.twelvemonkeys.io.InputStreamAbstractTestCase; +import org.junit.Test; import javax.imageio.stream.MemoryCacheImageInputStream; -import java.io.InputStream; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.*; /** * IIOInputStreamAdapter @@ -43,14 +46,12 @@ import java.io.IOException; * @version $Id: IIOInputStreamAdapter.java,v 1.0 Apr 11, 2008 1:04:42 PM haraldk Exp$ */ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase { - public IIOInputStreamAdapterTestCase(String name) { - super(name); - } protected InputStream makeInputStream(byte[] pBytes) { return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length); } + @Test public void testReadSubstreamOpenEnd() throws IOException { byte[] bytes = new byte[20]; @@ -74,6 +75,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase { input.close(); } + @Test public void testReadSubstream() throws IOException { byte[] bytes = new byte[20]; @@ -92,6 +94,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase { input.close(); } + @Test public void testReadSubstreamRepositionOnClose() throws IOException { byte[] bytes = new byte[20]; @@ -111,6 +114,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase { input.close(); } + @Test public void testSeekBeforeStreamNoEnd() throws IOException { byte[] bytes = new byte[20]; @@ -124,6 +128,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase { assertEquals(10, input.getStreamPosition()); } + @Test public void testSeekBeforeStream() throws IOException { byte[] bytes = new byte[20]; diff --git a/imageio/imageio-metadata/src/test/java/com/twelvemonkeys/imageio/metadata/jpeg/JPEGSegmentTest.java b/imageio/imageio-metadata/src/test/java/com/twelvemonkeys/imageio/metadata/jpeg/JPEGSegmentTest.java index 0f0e76fa..85be7581 100644 --- a/imageio/imageio-metadata/src/test/java/com/twelvemonkeys/imageio/metadata/jpeg/JPEGSegmentTest.java +++ b/imageio/imageio-metadata/src/test/java/com/twelvemonkeys/imageio/metadata/jpeg/JPEGSegmentTest.java @@ -33,6 +33,8 @@ import org.junit.Test; import java.nio.charset.Charset; +import static org.junit.Assert.assertEquals; + /** * JPEGSegmentTest * diff --git a/imageio/imageio-pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageWriter.java b/imageio/imageio-pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageWriter.java index e2a21a17..a1f4a405 100755 --- a/imageio/imageio-pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageWriter.java +++ b/imageio/imageio-pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageWriter.java @@ -79,7 +79,7 @@ import java.io.*; * Images are stored using the "opDirectBitsRect" opcode, which directly * stores RGB values (using PackBits run-length encoding). * - * @author Kary Fr�mling + * @author Kary Främling * @author Harald Kuhr * @version $Id: PICTWriter.java,v 1.0 05.apr.2006 15:20:48 haku Exp$ */ diff --git a/servlet/src/test/java/com/twelvemonkeys/servlet/GenericFilterTestCase.java b/servlet/src/test/java/com/twelvemonkeys/servlet/GenericFilterTestCase.java index a76575c1..1e04e19b 100755 --- a/servlet/src/test/java/com/twelvemonkeys/servlet/GenericFilterTestCase.java +++ b/servlet/src/test/java/com/twelvemonkeys/servlet/GenericFilterTestCase.java @@ -1,10 +1,14 @@ package com.twelvemonkeys.servlet; +import org.junit.Test; + import javax.servlet.*; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static org.junit.Assert.*; + /** * GenericFilterTestCase *

@@ -18,6 +22,7 @@ public final class GenericFilterTestCase extends FilterAbstractTestCase { return new GenericFilterImpl(); } + @Test public void testInitOncePerRequest() { // Default FALSE GenericFilter filter = new GenericFilterImpl(); @@ -63,6 +68,7 @@ public final class GenericFilterTestCase extends FilterAbstractTestCase { filter.destroy(); } + @Test public void testFilterOnlyOnce() { final GenericFilterImpl filter = new GenericFilterImpl(); filter.setOncePerRequest(true); @@ -91,6 +97,7 @@ public final class GenericFilterTestCase extends FilterAbstractTestCase { filter.destroy(); } + @Test public void testFilterMultiple() { final GenericFilterImpl filter = new GenericFilterImpl(); diff --git a/servlet/src/test/java/com/twelvemonkeys/servlet/TrimWhiteSpaceFilterTestCase.java b/servlet/src/test/java/com/twelvemonkeys/servlet/TrimWhiteSpaceFilterTestCase.java index dc3f283f..20bcca89 100755 --- a/servlet/src/test/java/com/twelvemonkeys/servlet/TrimWhiteSpaceFilterTestCase.java +++ b/servlet/src/test/java/com/twelvemonkeys/servlet/TrimWhiteSpaceFilterTestCase.java @@ -1,13 +1,15 @@ package com.twelvemonkeys.servlet; import com.twelvemonkeys.io.OutputStreamAbstractTestCase; +import org.junit.Test; +import javax.servlet.Filter; +import javax.servlet.ServletResponse; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import javax.servlet.Filter; -import javax.servlet.ServletResponse; +import static org.junit.Assert.*; /** * TrimWhiteSpaceFilterTestCase @@ -23,7 +25,6 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase { } public static final class TrimWSFilterOutputStreamTestCase extends OutputStreamAbstractTestCase { - protected OutputStream makeObject() { // NOTE: ByteArrayOutputStream does not implement flush or close... return makeOutputStream(new ByteArrayOutputStream(16)); @@ -33,6 +34,7 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase { return new TrimWhiteSpaceFilter.TrimWSFilterOutputStream(pWrapped); } + @Test public void testTrimWSOnlyWS() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(64); OutputStream trim = makeOutputStream(out); @@ -46,6 +48,7 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase { assertEquals("Should be trimmed", "\"\"", '"' + new String(out.toByteArray()) + '"'); } + @Test public void testTrimWSLeading() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(64); OutputStream trim = makeOutputStream(out); @@ -60,6 +63,7 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase { assertEquals("Should be trimmed", '"' + trimmed + '"', '"' + new String(out.toByteArray()) + '"'); } + @Test public void testTrimWSOffsetLength() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(64); OutputStream trim = makeOutputStream(out); diff --git a/servlet/src/test/java/com/twelvemonkeys/servlet/image/ImageFilterTestCase.java b/servlet/src/test/java/com/twelvemonkeys/servlet/image/ImageFilterTestCase.java index c4e4d3cb..ebb8dce8 100644 --- a/servlet/src/test/java/com/twelvemonkeys/servlet/image/ImageFilterTestCase.java +++ b/servlet/src/test/java/com/twelvemonkeys/servlet/image/ImageFilterTestCase.java @@ -341,7 +341,8 @@ public class ImageFilterTestCase { // NOTE: // We verify that the image is the same in both ImageFilter implementations, to make sure the image is only - // decoded once, then encoded once + // decoded once, then encoded once. + // But this test is not necessarily 100% reliable... } @Test(expected = ServletException.class)