Major test overhaul, now uses JUnit 4 annotation style tests.

This commit is contained in:
Harald Kuhr 2011-10-18 20:16:32 +02:00
parent 4b77d1c22a
commit 9cafe4d9a9
26 changed files with 350 additions and 104 deletions

View File

@ -2,6 +2,7 @@ package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.StringUtil; import com.twelvemonkeys.lang.StringUtil;
import com.twelvemonkeys.util.CollectionUtil; import com.twelvemonkeys.util.CollectionUtil;
import org.junit.Test;
import java.io.Reader; import java.io.Reader;
import java.io.IOException; import java.io.IOException;
@ -9,6 +10,8 @@ import java.io.StringReader;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import static org.junit.Assert.*;
/** /**
* CompoundReaderTestCase * CompoundReaderTestCase
* <p/> * <p/>
@ -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 $ * @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 { public class CompoundReaderTestCase extends ReaderAbstractTestCase {
protected Reader makeReader(String pInput) { protected Reader makeReader(String pInput) {
// Split // Split
String[] input = StringUtil.toStringArray(pInput, " "); String[] input = StringUtil.toStringArray(pInput, " ");
@ -36,6 +38,7 @@ public class CompoundReaderTestCase extends ReaderAbstractTestCase {
return new CompoundReader(readers.iterator()); return new CompoundReader(readers.iterator());
} }
@Test
public void testNullConstructor() { public void testNullConstructor() {
try { try {
new CompoundReader(null); new CompoundReader(null);
@ -46,11 +49,13 @@ public class CompoundReaderTestCase extends ReaderAbstractTestCase {
} }
} }
@Test
public void testEmptyIteratorConstructor() throws IOException { public void testEmptyIteratorConstructor() throws IOException {
Reader reader = new CompoundReader(CollectionUtil.iterator(new Reader[0])); Reader reader = new CompoundReader(CollectionUtil.iterator(new Reader[0]));
assertEquals(-1, reader.read()); assertEquals(-1, reader.read());
} }
@Test
public void testIteratorWithNullConstructor() throws IOException { public void testIteratorWithNullConstructor() throws IOException {
try { try {
new CompoundReader(CollectionUtil.iterator(new Reader[] {null})); new CompoundReader(CollectionUtil.iterator(new Reader[] {null}));

View File

@ -1,8 +1,12 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import static org.junit.Assert.assertEquals;
/** /**
* FastByteArrayOutputStreamTestCase * FastByteArrayOutputStreamTestCase
* <p/> * <p/>
@ -16,6 +20,7 @@ public class FastByteArrayOutputStreamTestCase extends OutputStreamAbstractTestC
return new FastByteArrayOutputStream(256); return new FastByteArrayOutputStream(256);
} }
@Test
public void testCreateInputStream() throws IOException { public void testCreateInputStream() throws IOException {
FastByteArrayOutputStream out = makeObject(); FastByteArrayOutputStream out = makeObject();

View File

@ -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 $ * @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 class FileCacheSeekableStreamTestCase extends SeekableInputStreamAbstractTestCase {
public FileCacheSeekableStreamTestCase(String name) {
super(name);
}
protected SeekableInputStream makeInputStream(final InputStream pStream) { protected SeekableInputStream makeInputStream(final InputStream pStream) {
try { try {
return new FileCacheSeekableStream(pStream); return new FileCacheSeekableStream(pStream);

View File

@ -1,7 +1,11 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.*; import java.io.*;
import static org.junit.Assert.*;
/** /**
* MemoryCacheSeekableStreamTestCase * MemoryCacheSeekableStreamTestCase
* <p/> * <p/>
@ -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 $ * @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 class FileSeekableStreamTestCase extends SeekableInputStreamAbstractTestCase {
public FileSeekableStreamTestCase(String name) {
super(name);
}
protected SeekableInputStream makeInputStream(final InputStream pStream) { protected SeekableInputStream makeInputStream(final InputStream pStream) {
try { try {
return new FileSeekableStream(createFileWithContent(pStream)); return new FileSeekableStream(createFileWithContent(pStream));
@ -37,11 +37,13 @@ public class FileSeekableStreamTestCase extends SeekableInputStreamAbstractTestC
return temp; return temp;
} }
@Test
@Override @Override
public void testCloseUnderlyingStream() throws IOException { public void testCloseUnderlyingStream() throws IOException {
// There is no underlying stream here... // There is no underlying stream here...
} }
@Test
public void testCloseUnderlyingFile() throws IOException { public void testCloseUnderlyingFile() throws IOException {
final boolean[] closed = new boolean[1]; final boolean[] closed = new boolean[1];

View File

@ -17,12 +17,15 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.ObjectAbstractTestCase; import com.twelvemonkeys.lang.ObjectAbstractTestCase;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Random; import java.util.Random;
import static org.junit.Assert.*;
/** /**
* InputStreamAbstractTestCase * InputStreamAbstractTestCase
* <p/> * <p/>
@ -38,10 +41,6 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
final static private long SEED = 29487982745l; final static private long SEED = 29487982745l;
final static Random sRandom = new Random(SEED); final static Random sRandom = new Random(SEED);
public InputStreamAbstractTestCase(String name) {
super(name);
}
protected final Object makeObject() { protected final Object makeObject() {
return makeInputStream(); return makeInputStream();
} }
@ -71,6 +70,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
return bytes; return bytes;
} }
@Test
public void testRead() throws Exception { public void testRead() throws Exception {
int size = 5; int size = 5;
InputStream input = makeInputStream(makeOrderedArray(size)); InputStream input = makeInputStream(makeOrderedArray(size));
@ -90,6 +90,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testAvailable() throws Exception { public void testAvailable() throws Exception {
InputStream input = makeInputStream(1); InputStream input = makeInputStream(1);
assertFalse("Unexpected EOF", input.read() < 0); 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()); assertEquals("Available after End of File", 0, input.available());
} }
@Test
public void testReadByteArray() throws Exception { public void testReadByteArray() throws Exception {
byte[] bytes = new byte[10]; byte[] bytes = new byte[10];
byte[] data = makeOrderedArray(15); byte[] data = makeOrderedArray(15);
@ -145,6 +147,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testEOF() throws Exception { public void testEOF() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(2)); InputStream input = makeInputStream(makeOrderedArray(2));
assertEquals("Read 1", 0, input.read()); assertEquals("Read 1", 0, input.read());
@ -154,6 +157,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
assertEquals("Read 5", -1, input.read()); assertEquals("Read 5", -1, input.read());
} }
@Test
public void testMarkResetUnsupported() throws IOException { public void testMarkResetUnsupported() throws IOException {
InputStream input = makeInputStream(10); InputStream input = makeInputStream(10);
if (input.markSupported()) { if (input.markSupported()) {
@ -176,6 +180,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testResetNoMark() throws Exception { public void testResetNoMark() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(10)); InputStream input = makeInputStream(makeOrderedArray(10));
@ -196,6 +201,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testMarkReset() throws Exception { public void testMarkReset() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(25)); InputStream input = makeInputStream(makeOrderedArray(25));
@ -226,6 +232,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testResetAfterReadLimit() throws Exception { public void testResetAfterReadLimit() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(25)); InputStream input = makeInputStream(makeOrderedArray(25));
@ -257,6 +264,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testResetAfterReset() throws Exception { public void testResetAfterReset() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(25)); InputStream input = makeInputStream(makeOrderedArray(25));
@ -274,9 +282,9 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
assertTrue("Expected to read positive value", read >= 0); assertTrue("Expected to read positive value", read >= 0);
input.reset(); 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 { try {
input.reset(); input.reset();
assertEquals("Re-read of reset data should be same", read, input.read()); 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 { public void testSkip() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(10)); InputStream input = makeInputStream(makeOrderedArray(10));
@ -302,6 +311,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
assertEquals("Unexpected value read after EOF", -1, input.read()); assertEquals("Unexpected value read after EOF", -1, input.read());
} }
@Test
public void testSanityOrdered() throws IOException { public void testSanityOrdered() throws IOException {
// This is to sanity check that the test itself is correct... // This is to sanity check that the test itself is correct...
byte[] bytes = makeOrderedArray(25); byte[] bytes = makeOrderedArray(25);
@ -314,6 +324,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testSanityOrdered2() throws IOException { public void testSanityOrdered2() throws IOException {
// This is to sanity check that the test itself is correct... // This is to sanity check that the test itself is correct...
byte[] bytes = makeOrderedArray(25); byte[] bytes = makeOrderedArray(25);
@ -332,6 +343,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testSanityNegative() throws IOException { public void testSanityNegative() throws IOException {
// This is to sanity check that the test itself is correct... // This is to sanity check that the test itself is correct...
byte[] bytes = new byte[25]; byte[] bytes = new byte[25];
@ -347,6 +359,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testSanityNegative2() throws IOException { public void testSanityNegative2() throws IOException {
// This is to sanity check that the test itself is correct... // This is to sanity check that the test itself is correct...
byte[] bytes = new byte[25]; byte[] bytes = new byte[25];
@ -368,6 +381,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testSanityRandom() throws IOException { public void testSanityRandom() throws IOException {
// This is to sanity check that the test itself is correct... // This is to sanity check that the test itself is correct...
byte[] bytes = makeRandomArray(25); byte[] bytes = makeRandomArray(25);
@ -380,6 +394,7 @@ public abstract class InputStreamAbstractTestCase extends ObjectAbstractTestCase
} }
} }
@Test
public void testSanityRandom2() throws IOException { public void testSanityRandom2() throws IOException {
// This is to sanity check that the test itself is correct... // This is to sanity check that the test itself is correct...
byte[] bytes = makeRandomArray(25); byte[] bytes = makeRandomArray(25);

View File

@ -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 $ * @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 class MemoryCacheSeekableStreamTestCase extends SeekableInputStreamAbstractTestCase {
public MemoryCacheSeekableStreamTestCase(String name) {
super(name);
}
protected SeekableInputStream makeInputStream(final InputStream pStream) { protected SeekableInputStream makeInputStream(final InputStream pStream) {
return new MemoryCacheSeekableStream(pStream); return new MemoryCacheSeekableStream(pStream);
} }

View File

@ -1,10 +1,13 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.ObjectAbstractTestCase; import com.twelvemonkeys.lang.ObjectAbstractTestCase;
import org.junit.Test;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.*;
/** /**
* InputStreamAbstractTestCase * InputStreamAbstractTestCase
* <p/> * <p/>
@ -15,6 +18,7 @@ import java.io.IOException;
public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCase { public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCase {
protected abstract OutputStream makeObject(); protected abstract OutputStream makeObject();
@Test
public void testWrite() throws IOException { public void testWrite() throws IOException {
OutputStream os = makeObject(); OutputStream os = makeObject();
@ -23,12 +27,14 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testWriteByteArray() throws IOException { public void testWriteByteArray() throws IOException {
OutputStream os = makeObject(); OutputStream os = makeObject();
os.write(new byte[256]); os.write(new byte[256]);
} }
@Test
public void testWriteByteArrayNull() { public void testWriteByteArrayNull() {
OutputStream os = makeObject(); OutputStream os = makeObject();
try { 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]; byte[] input = new byte[256];
OutputStream os = makeObject(); OutputStream os = makeObject();
@ -65,7 +72,8 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
public void testWriteByteArrayZeroLenght() { @Test
public void testWriteByteArrayZeroLength() {
OutputStream os = makeObject(); OutputStream os = makeObject();
try { try {
os.write(new byte[1], 0, 0); 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(); OutputStream os = makeObject();
try { try {
os.write(null, 5, 10); os.write(null, 5, 10);
@ -92,6 +101,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testWriteByteArrayNegativeOffset() { public void testWriteByteArrayNegativeOffset() {
OutputStream os = makeObject(); OutputStream os = makeObject();
try { try {
@ -109,6 +119,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testWriteByteArrayNegativeLength() { public void testWriteByteArrayNegativeLength() {
OutputStream os = makeObject(); OutputStream os = makeObject();
try { try {
@ -126,6 +137,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testWriteByteArrayOffsetOutOfBounds() { public void testWriteByteArrayOffsetOutOfBounds() {
OutputStream os = makeObject(); OutputStream os = makeObject();
try { try {
@ -143,6 +155,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testWriteByteArrayLengthOutOfBounds() { public void testWriteByteArrayLengthOutOfBounds() {
OutputStream os = makeObject(); OutputStream os = makeObject();
try { try {
@ -160,14 +173,17 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testFlush() { public void testFlush() {
// TODO: Implement // TODO: Implement
} }
@Test
public void testClose() { public void testClose() {
// TODO: Implement // TODO: Implement
} }
@Test
public void testWriteAfterClose() throws IOException { public void testWriteAfterClose() throws IOException {
OutputStream os = makeObject(); OutputStream os = makeObject();
@ -200,6 +216,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testFlushAfterClose() throws IOException { public void testFlushAfterClose() throws IOException {
OutputStream os = makeObject(); OutputStream os = makeObject();
@ -221,6 +238,7 @@ public abstract class OutputStreamAbstractTestCase extends ObjectAbstractTestCas
} }
} }
@Test
public void testCloseAfterClose() throws IOException { public void testCloseAfterClose() throws IOException {
OutputStream os = makeObject(); OutputStream os = makeObject();

View File

@ -1,10 +1,13 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.ObjectAbstractTestCase; import com.twelvemonkeys.lang.ObjectAbstractTestCase;
import org.junit.Test;
import java.io.Reader; import java.io.Reader;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.*;
/** /**
* ReaderAbstractTestCase * ReaderAbstractTestCase
* <p/> * <p/>
@ -36,6 +39,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase {
protected abstract Reader makeReader(String pInput); protected abstract Reader makeReader(String pInput);
@Test
public void testRead() throws IOException { public void testRead() throws IOException {
Reader reader = makeReader(); Reader reader = makeReader();
@ -51,6 +55,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase {
assertEquals(mInput, buffer.toString()); assertEquals(mInput, buffer.toString());
} }
@Test
public void testReadBuffer() throws IOException { public void testReadBuffer() throws IOException {
Reader reader = makeReader(); Reader reader = makeReader();
@ -70,6 +75,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase {
assertEquals(mInput, new String(chars)); assertEquals(mInput, new String(chars));
} }
@Test
public void testSkipToEnd() throws IOException { public void testSkipToEnd() throws IOException {
Reader reader = makeReader(); Reader reader = makeReader();
@ -83,6 +89,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase {
assertEquals(0, toSkip); assertEquals(0, toSkip);
} }
@Test
public void testSkipToEndAndRead() throws IOException { public void testSkipToEndAndRead() throws IOException {
Reader reader = makeReader(); 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) // TODO: It's possible to support reset and not mark (resets to beginning of stream, for example)
@Test
public void testResetMarkSupported() throws IOException { public void testResetMarkSupported() throws IOException {
Reader reader = makeReader(); Reader reader = makeReader();
@ -154,6 +162,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase {
} }
} }
@Test
public void testResetMarkNotSupported() throws IOException { public void testResetMarkNotSupported() throws IOException {
Reader reader = makeReader(); Reader reader = makeReader();
@ -198,7 +207,7 @@ public abstract class ReaderAbstractTestCase extends ObjectAbstractTestCase {
} }
} }
@Test
public void testReadAfterClose() throws IOException { public void testReadAfterClose() throws IOException {
Reader reader = makeReader("foo bar"); Reader reader = makeReader("foo bar");

View File

@ -1,6 +1,8 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import junit.framework.TestCase; import org.junit.Test;
import static org.junit.Assert.*;
/** /**
* SeekableAbstractTestCase * SeekableAbstractTestCase
@ -9,14 +11,16 @@ import junit.framework.TestCase;
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a> * @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/io/SeekableAbstractTestCase.java#1 $ * @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(); protected abstract Seekable createSeekable();
@Test
public void testFail() { 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() { public void testSeekable() {
assertTrue(createSeekable() instanceof Seekable); assertTrue(createSeekable() instanceof Seekable);
} }

View File

@ -1,10 +1,14 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import static org.junit.Assert.*;
/** /**
* SeekableInputStreamAbstractTestCase * SeekableInputStreamAbstractTestCase
* <p/> * <p/>
@ -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 $ * @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 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 //// 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() { protected Seekable createSeekable() {
return makeInputStream(); return makeInputStream();
} }
@ -41,6 +40,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
protected abstract SeekableInputStream makeInputStream(InputStream pStream); protected abstract SeekableInputStream makeInputStream(InputStream pStream);
@Test
@Override @Override
public void testResetAfterReset() throws Exception { public void testResetAfterReset() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(25)); InputStream input = makeInputStream(makeOrderedArray(25));
@ -59,9 +59,9 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
assertTrue("Expected to read positive value", read >= 0); assertTrue("Expected to read positive value", read >= 0);
input.reset(); 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 { try {
input.reset(); input.reset();
assertEquals("Re-read of reset data should be first", 0, input.read()); 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() { public void testSeekable() {
mSeekableTestCase.testSeekable(); seekableTestCase.testSeekable();
} }
@Test
public void testFlushBeyondCurrentPos() throws Exception { public void testFlushBeyondCurrentPos() throws Exception {
SeekableInputStream seekable = makeInputStream(20); SeekableInputStream seekable = makeInputStream(20);
@ -88,6 +90,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
} }
} }
@Test
public void testSeek() throws Exception { public void testSeek() throws Exception {
SeekableInputStream seekable = makeInputStream(55); SeekableInputStream seekable = makeInputStream(55);
int pos = 37; int pos = 37;
@ -97,6 +100,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
assertEquals("Stream positon should match seeked position", pos, streamPos); assertEquals("Stream positon should match seeked position", pos, streamPos);
} }
@Test
public void testSeekFlush() throws Exception { public void testSeekFlush() throws Exception {
SeekableInputStream seekable = makeInputStream(133); SeekableInputStream seekable = makeInputStream(133);
int pos = 45; int pos = 45;
@ -114,6 +118,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
} }
} }
@Test
public void testMarkFlushReset() throws Exception { public void testMarkFlushReset() throws Exception {
SeekableInputStream seekable = makeInputStream(77); SeekableInputStream seekable = makeInputStream(77);
@ -134,6 +139,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
assertEquals(position, seekable.getStreamPosition()); assertEquals(position, seekable.getStreamPosition());
} }
@Test
public void testSeekSkipRead() throws Exception { public void testSeekSkipRead() throws Exception {
SeekableInputStream seekable = makeInputStream(133); SeekableInputStream seekable = makeInputStream(133);
int pos = 45; 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(); System.out.println();
pSeekable.seek(pStr.length()); pSeekable.seek(pStr.length());
FileUtil.read(pSeekable); FileUtil.read(pSeekable);
@ -330,6 +336,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
} }
*/ */
@Test
public void testReadResetReadDirectBufferBug() throws IOException { public void testReadResetReadDirectBufferBug() throws IOException {
// Make sure we use the exact size of the buffer // Make sure we use the exact size of the buffer
final int size = 1024; final int size = 1024;
@ -365,6 +372,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
assertTrue(rangeEquals(bytes, size, result, 0, size)); assertTrue(rangeEquals(bytes, size, result, 0, size));
} }
@Test
public void testReadAllByteValuesRegression() throws IOException { public void testReadAllByteValuesRegression() throws IOException {
final int size = 128; final int size = 128;
@ -401,6 +409,7 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
} }
@Test
public void testCloseUnderlyingStream() throws IOException { public void testCloseUnderlyingStream() throws IOException {
final boolean[] closed = new boolean[1]; final boolean[] closed = new boolean[1];
@ -476,5 +485,4 @@ public abstract class SeekableInputStreamAbstractTestCase extends InputStreamAbs
return true; return true;
} }
} }

View File

@ -1,10 +1,13 @@
package com.twelvemonkeys.io; package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.StringUtil; import com.twelvemonkeys.lang.StringUtil;
import org.junit.Test;
import java.io.Reader; import java.io.Reader;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.*;
/** /**
* StringArrayReaderTestCase * StringArrayReaderTestCase
* <p/> * <p/>
@ -28,6 +31,7 @@ public class StringArrayReaderTestCase extends ReaderAbstractTestCase {
return new StringArrayReader(input); return new StringArrayReader(input);
} }
@Test
public void testNullConstructor() { public void testNullConstructor() {
try { try {
new StringArrayReader(null); new StringArrayReader(null);
@ -38,15 +42,15 @@ public class StringArrayReaderTestCase extends ReaderAbstractTestCase {
} }
} }
@Test
public void testEmptyArrayConstructor() throws IOException { public void testEmptyArrayConstructor() throws IOException {
Reader reader = new StringArrayReader(new String[0]); Reader reader = new StringArrayReader(new String[0]);
assertEquals(-1, reader.read()); assertEquals(-1, reader.read());
} }
@Test
public void testEmptyStringConstructor() throws IOException { public void testEmptyStringConstructor() throws IOException {
Reader reader = new StringArrayReader(new String[] {""}); Reader reader = new StringArrayReader(new String[] {""});
assertEquals(-1, reader.read()); assertEquals(-1, reader.read());
} }
} }

View File

@ -2,9 +2,12 @@ package com.twelvemonkeys.io.enc;
import com.twelvemonkeys.io.FileUtil; import com.twelvemonkeys.io.FileUtil;
import org.junit.Test;
import java.io.*; import java.io.*;
import static org.junit.Assert.*;
/** /**
* Base64DecoderTest * Base64DecoderTest
* <p/> * <p/>
@ -22,6 +25,7 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase {
return new Base64Encoder(); return new Base64Encoder();
} }
@Test
public void testEmptyDecode2() throws IOException { public void testEmptyDecode2() throws IOException {
String data = ""; String data = "";
@ -33,6 +37,7 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase {
assertEquals("Strings does not match", "", new String(bytes.toByteArray())); assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
} }
@Test
public void testShortDecode() throws IOException { public void testShortDecode() throws IOException {
String data = "dGVzdA=="; String data = "dGVzdA==";
@ -44,6 +49,7 @@ public class Base64DecoderTestCase extends DecoderAbstractTestCase {
assertEquals("Strings does not match", "test", new String(bytes.toByteArray())); assertEquals("Strings does not match", "test", new String(bytes.toByteArray()));
} }
@Test
public void testLongDecode() throws IOException { public void testLongDecode() throws IOException {
String data = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" + String data = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" +
"c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" + "c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" +

View File

@ -1,7 +1,11 @@
package com.twelvemonkeys.io.enc; package com.twelvemonkeys.io.enc;
import org.junit.Test;
import java.io.*; import java.io.*;
import static org.junit.Assert.*;
/** /**
* Base64EncoderTest * Base64EncoderTest
* <p/> * <p/>
@ -19,6 +23,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase {
return new Base64Decoder(); return new Base64Decoder();
} }
@Test
public void testNegativeEncode() throws IOException { public void testNegativeEncode() throws IOException {
Encoder encoder = createEncoder(); Encoder encoder = createEncoder();
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@ -31,6 +36,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase {
} }
} }
@Test
public void testEmptyEncode() throws IOException { public void testEmptyEncode() throws IOException {
String data = ""; String data = "";
@ -41,6 +47,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase {
assertEquals("Strings does not match", "", new String(bytes.toByteArray())); assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
} }
@Test
public void testShortEncode() throws IOException { public void testShortEncode() throws IOException {
String data = "test"; String data = "test";
@ -51,6 +58,7 @@ public class Base64EncoderTestCase extends EncoderAbstractTestCase {
assertEquals("Strings does not match", "dGVzdA==", new String(bytes.toByteArray())); assertEquals("Strings does not match", "dGVzdA==", new String(bytes.toByteArray()));
} }
@Test
public void testLongEncode() throws IOException { public void testLongEncode() throws IOException {
String data = "Lorem ipsum dolor sit amet, consectetuer adipiscing " + String data = "Lorem ipsum dolor sit amet, consectetuer adipiscing " +
"elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " + "elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " +

View File

@ -2,10 +2,13 @@ package com.twelvemonkeys.io.enc;
import com.twelvemonkeys.io.FileUtil; import com.twelvemonkeys.io.FileUtil;
import com.twelvemonkeys.lang.ObjectAbstractTestCase; import com.twelvemonkeys.lang.ObjectAbstractTestCase;
import org.junit.Test;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.Assert.*;
/** /**
* AbstractDecoderTest * AbstractDecoderTest
* <p/> * <p/>
@ -22,6 +25,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase {
return createDecoder(); return createDecoder();
} }
@Test
public final void testNullDecode() throws IOException { public final void testNullDecode() throws IOException {
Decoder decoder = createDecoder(); Decoder decoder = createDecoder();
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]); ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]);
@ -34,6 +38,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase {
} }
} }
@Test
public final void testEmptyDecode() throws IOException { public final void testEmptyDecode() throws IOException {
Decoder decoder = createDecoder(); Decoder decoder = createDecoder();
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[0]); ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[0]);
@ -81,6 +86,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase {
assertTrue(Arrays.equals(data, decoded)); assertTrue(Arrays.equals(data, decoded));
} }
@Test
public final void testStreams() throws Exception { public final void testStreams() throws Exception {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
try { try {

View File

@ -2,11 +2,14 @@ package com.twelvemonkeys.io.enc;
import com.twelvemonkeys.io.FileUtil; import com.twelvemonkeys.io.FileUtil;
import com.twelvemonkeys.lang.ObjectAbstractTestCase; import com.twelvemonkeys.lang.ObjectAbstractTestCase;
import org.junit.Test;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
import static org.junit.Assert.*;
/** /**
* AbstractEncoderTest * AbstractEncoderTest
* <p/> * <p/>
@ -26,6 +29,7 @@ public abstract class EncoderAbstractTestCase extends ObjectAbstractTestCase {
return createEncoder(); return createEncoder();
} }
@Test
public final void testNullEncode() throws IOException { public final void testNullEncode() throws IOException {
Encoder encoder = createEncoder(); Encoder encoder = createEncoder();
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@ -79,6 +83,7 @@ public abstract class EncoderAbstractTestCase extends ObjectAbstractTestCase {
assertTrue(Arrays.equals(data, decoded)); assertTrue(Arrays.equals(data, decoded));
} }
@Test
public final void testStreams() throws Exception { public final void testStreams() throws Exception {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
try { try {

View File

@ -1,6 +1,7 @@
package com.twelvemonkeys.io.ole2; package com.twelvemonkeys.io.ole2;
import junit.framework.TestCase; import com.twelvemonkeys.io.MemoryCacheSeekableStream;
import org.junit.Test;
import javax.imageio.stream.MemoryCacheImageInputStream; import javax.imageio.stream.MemoryCacheImageInputStream;
import java.io.File; import java.io.File;
@ -9,6 +10,10 @@ import java.io.InputStream;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.SortedSet;
import java.util.TreeSet;
import static org.junit.Assert.*;
/** /**
* CompoundDocumentTestCase * CompoundDocumentTestCase
@ -17,9 +22,89 @@ import java.nio.ByteOrder;
* @author last modified by $Author: haku $ * @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 $ * @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<Entry> children = new TreeSet<Entry>(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<Entry> 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 { public void testReadCatalogInputStream() throws IOException {
InputStream input = getClass().getResourceAsStream("/Thumbs-camera.db"); InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
assertNotNull("Missing test resource!", input); assertNotNull("Missing test resource!", input);
@ -33,8 +118,25 @@ public class CompoundDocumentTestCase extends TestCase {
assertNotNull("Input stream may not be null", catalog.getInputStream()); 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 { public void testReadCatalogImageInputStream() throws IOException {
InputStream input = getClass().getResourceAsStream("/Thumbs-camera.db"); InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
assertNotNull("Missing test resource!", input); assertNotNull("Missing test resource!", input);
@ -53,25 +155,4 @@ public class CompoundDocumentTestCase extends TestCase {
assertNotNull(catalog); assertNotNull(catalog);
assertNotNull("Input stream may not be null", catalog.getInputStream()); 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());
}
} }

View File

@ -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 <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @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();
}
}

View File

@ -1,9 +1,11 @@
package com.twelvemonkeys.lang; package com.twelvemonkeys.lang;
import junit.framework.TestCase; import org.junit.Test;
import java.lang.reflect.Method;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import static org.junit.Assert.*;
/** /**
* AbstractObjectTestCase * AbstractObjectTestCase
@ -12,7 +14,7 @@ import java.io.*;
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a> * @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java#1 $ * @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: See com.tm.util.ObjectAbstractTestCase
// TODO: The idea is that this should be some generic base-class that // TODO: The idea is that this should be some generic base-class that
// implements the basic object tests // implements the basic object tests
@ -20,19 +22,6 @@ public abstract class ObjectAbstractTestCase extends TestCase {
// TODO: Create Serializable test similar way // TODO: Create Serializable test similar way
// TODO: Create Comparable 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. * Returns an instance of the class we are testing.
* Implement this method to return the object to test. * 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); //protected abstract Object makeEqualObject(Object pObject);
@Test
public void testToString() { public void testToString() {
assertNotNull(makeObject().toString()); assertNotNull(makeObject().toString());
// TODO: What more can we test? // TODO: What more can we test?
} }
// TODO: assert that either BOTH or NONE of equals/hashcode is overridden // TODO: assert that either BOTH or NONE of equals/hashcode is overridden
@Test
public void testEqualsHashCode(){ public void testEqualsHashCode(){
Object obj = makeObject(); Object obj = makeObject();
Class cl = obj.getClass(); Class cl = obj.getClass();
if (isEqualsOverriden(cl)) { if (isEqualsOverriden(cl)) {
assertTrue("Class " + cl.getName() assertTrue("Class " + cl.getName() + " implements equals but not hashCode", isHashCodeOverriden(cl));
+ " implements equals but not hashCode", isHashCodeOverriden(cl));
} }
else if (isHashCodeOverriden(cl)) { else if (isHashCodeOverriden(cl)) {
assertTrue("Class " + cl.getName() assertTrue("Class " + cl.getName() + " implements hashCode but not equals", isEqualsOverriden(cl));
+ " implements hashCode but not equals", isEqualsOverriden(cl));
} }
} }
@ -85,11 +74,13 @@ public abstract class ObjectAbstractTestCase extends TestCase {
} }
} }
@Test
public void testObjectEqualsSelf() { public void testObjectEqualsSelf() {
Object obj = makeObject(); Object obj = makeObject();
assertEquals("An Object should equal itself", obj, obj); assertEquals("An Object should equal itself", obj, obj);
} }
@Test
public void testEqualsNull() { public void testEqualsNull() {
Object obj = makeObject(); Object obj = makeObject();
// NOTE: Makes sure this doesn't throw NPE either // 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)); assertFalse("An object should never equal null", obj.equals(null));
} }
@Test
public void testObjectHashCodeEqualsSelfHashCode() { public void testObjectHashCodeEqualsSelfHashCode() {
Object obj = makeObject(); Object obj = makeObject();
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode()); assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
} }
@Test
public void testObjectHashCodeEqualsContract() { public void testObjectHashCodeEqualsContract() {
Object obj1 = makeObject(); Object obj1 = makeObject();
if (obj1.equals(obj1)) { if (obj1.equals(obj1)) {
@ -129,6 +122,7 @@ public abstract class ObjectAbstractTestCase extends TestCase {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Cloneable interface // Cloneable interface
@Test
public void testClone() throws Exception { public void testClone() throws Exception {
Object obj = makeObject(); Object obj = makeObject();
if (obj instanceof Cloneable) { if (obj instanceof Cloneable) {
@ -184,6 +178,7 @@ public abstract class ObjectAbstractTestCase extends TestCase {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Serializable interface // Serializable interface
@Test
public void testSerializeDeserializeThenCompare() throws Exception { public void testSerializeDeserializeThenCompare() throws Exception {
Object obj = makeObject(); Object obj = makeObject();
if (obj instanceof Serializable) { if (obj instanceof Serializable) {
@ -223,6 +218,7 @@ public abstract class ObjectAbstractTestCase extends TestCase {
* @throws java.io.IOException * @throws java.io.IOException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
@Test
public void testSimpleSerialization() throws Exception { public void testSimpleSerialization() throws Exception {
Object o = makeObject(); Object o = makeObject();
if (o instanceof Serializable) { if (o instanceof Serializable) {
@ -305,14 +301,6 @@ public abstract class ObjectAbstractTestCase extends TestCase {
} }
public static final class SanityTestTestCase extends ObjectAbstractTestCase { public static final class SanityTestTestCase extends ObjectAbstractTestCase {
/**
* Creates a {@code TestCase}.
*
*/
public SanityTestTestCase() {
super(SanityTestTestCase.class.getName());
}
protected Object makeObject() { protected Object makeObject() {
return new Cloneable() {}; return new Cloneable() {};
} }

View File

@ -1,6 +1,7 @@
package com.twelvemonkeys.util.convert; package com.twelvemonkeys.util.convert;
import com.twelvemonkeys.lang.DateUtil; import com.twelvemonkeys.lang.DateUtil;
import org.junit.Test;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
@ -44,6 +45,7 @@ public class DateConverterTestCase extends PropertyConverterAbstractTestCase {
}; };
} }
@Test
@Override @Override
public void testConvert() { public void testConvert() {
TimeZone old = TimeZone.getDefault(); TimeZone old = TimeZone.getDefault();

View File

@ -1,9 +1,12 @@
package com.twelvemonkeys.util.convert; package com.twelvemonkeys.util.convert;
import com.twelvemonkeys.lang.ObjectAbstractTestCase; import com.twelvemonkeys.lang.ObjectAbstractTestCase;
import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.Assert.*;
/** /**
* PropertyConverterAbstractTestCase * PropertyConverterAbstractTestCase
* <p/> * <p/>
@ -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 $ * @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 { public abstract class PropertyConverterAbstractTestCase extends ObjectAbstractTestCase {
protected Object makeObject() { protected Object makeObject() {
return makePropertyConverter(); return makePropertyConverter();
} }
@ -22,8 +24,8 @@ public abstract class PropertyConverterAbstractTestCase extends ObjectAbstractTe
protected abstract Conversion[] getTestConversions(); protected abstract Conversion[] getTestConversions();
@Test
public void testConvert() { public void testConvert() {
PropertyConverter converter = makePropertyConverter(); PropertyConverter converter = makePropertyConverter();
Conversion[] tests = getTestConversions(); Conversion[] tests = getTestConversions();

View File

@ -29,11 +29,14 @@
package com.twelvemonkeys.imageio.util; package com.twelvemonkeys.imageio.util;
import com.twelvemonkeys.io.InputStreamAbstractTestCase; import com.twelvemonkeys.io.InputStreamAbstractTestCase;
import org.junit.Test;
import javax.imageio.stream.MemoryCacheImageInputStream; import javax.imageio.stream.MemoryCacheImageInputStream;
import java.io.InputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.*;
/** /**
* IIOInputStreamAdapter * 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$ * @version $Id: IIOInputStreamAdapter.java,v 1.0 Apr 11, 2008 1:04:42 PM haraldk Exp$
*/ */
public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase { public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase {
public IIOInputStreamAdapterTestCase(String name) {
super(name);
}
protected InputStream makeInputStream(byte[] pBytes) { protected InputStream makeInputStream(byte[] pBytes) {
return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length); return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length);
} }
@Test
public void testReadSubstreamOpenEnd() throws IOException { public void testReadSubstreamOpenEnd() throws IOException {
byte[] bytes = new byte[20]; byte[] bytes = new byte[20];
@ -74,6 +75,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase {
input.close(); input.close();
} }
@Test
public void testReadSubstream() throws IOException { public void testReadSubstream() throws IOException {
byte[] bytes = new byte[20]; byte[] bytes = new byte[20];
@ -92,6 +94,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase {
input.close(); input.close();
} }
@Test
public void testReadSubstreamRepositionOnClose() throws IOException { public void testReadSubstreamRepositionOnClose() throws IOException {
byte[] bytes = new byte[20]; byte[] bytes = new byte[20];
@ -111,6 +114,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase {
input.close(); input.close();
} }
@Test
public void testSeekBeforeStreamNoEnd() throws IOException { public void testSeekBeforeStreamNoEnd() throws IOException {
byte[] bytes = new byte[20]; byte[] bytes = new byte[20];
@ -124,6 +128,7 @@ public class IIOInputStreamAdapterTestCase extends InputStreamAbstractTestCase {
assertEquals(10, input.getStreamPosition()); assertEquals(10, input.getStreamPosition());
} }
@Test
public void testSeekBeforeStream() throws IOException { public void testSeekBeforeStream() throws IOException {
byte[] bytes = new byte[20]; byte[] bytes = new byte[20];

View File

@ -33,6 +33,8 @@ import org.junit.Test;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import static org.junit.Assert.assertEquals;
/** /**
* JPEGSegmentTest * JPEGSegmentTest
* *

View File

@ -79,7 +79,7 @@ import java.io.*;
* Images are stored using the "opDirectBitsRect" opcode, which directly * Images are stored using the "opDirectBitsRect" opcode, which directly
* stores RGB values (using PackBits run-length encoding). * stores RGB values (using PackBits run-length encoding).
* *
* @author <a href="http://www.cs.hut.fi/~framling/JVG/">Kary Fr<EFBFBD>mling</a> * @author <a href="http://www.cs.hut.fi/~framling/JVG/">Kary Främling</a>
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a> * @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @version $Id: PICTWriter.java,v 1.0 05.apr.2006 15:20:48 haku Exp$ * @version $Id: PICTWriter.java,v 1.0 05.apr.2006 15:20:48 haku Exp$
*/ */

View File

@ -1,10 +1,14 @@
package com.twelvemonkeys.servlet; package com.twelvemonkeys.servlet;
import org.junit.Test;
import javax.servlet.*; import javax.servlet.*;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.*;
/** /**
* GenericFilterTestCase * GenericFilterTestCase
* <p/> * <p/>
@ -18,6 +22,7 @@ public final class GenericFilterTestCase extends FilterAbstractTestCase {
return new GenericFilterImpl(); return new GenericFilterImpl();
} }
@Test
public void testInitOncePerRequest() { public void testInitOncePerRequest() {
// Default FALSE // Default FALSE
GenericFilter filter = new GenericFilterImpl(); GenericFilter filter = new GenericFilterImpl();
@ -63,6 +68,7 @@ public final class GenericFilterTestCase extends FilterAbstractTestCase {
filter.destroy(); filter.destroy();
} }
@Test
public void testFilterOnlyOnce() { public void testFilterOnlyOnce() {
final GenericFilterImpl filter = new GenericFilterImpl(); final GenericFilterImpl filter = new GenericFilterImpl();
filter.setOncePerRequest(true); filter.setOncePerRequest(true);
@ -91,6 +97,7 @@ public final class GenericFilterTestCase extends FilterAbstractTestCase {
filter.destroy(); filter.destroy();
} }
@Test
public void testFilterMultiple() { public void testFilterMultiple() {
final GenericFilterImpl filter = new GenericFilterImpl(); final GenericFilterImpl filter = new GenericFilterImpl();

View File

@ -1,13 +1,15 @@
package com.twelvemonkeys.servlet; package com.twelvemonkeys.servlet;
import com.twelvemonkeys.io.OutputStreamAbstractTestCase; import com.twelvemonkeys.io.OutputStreamAbstractTestCase;
import org.junit.Test;
import javax.servlet.Filter;
import javax.servlet.ServletResponse;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.servlet.Filter; import static org.junit.Assert.*;
import javax.servlet.ServletResponse;
/** /**
* TrimWhiteSpaceFilterTestCase * TrimWhiteSpaceFilterTestCase
@ -23,7 +25,6 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase {
} }
public static final class TrimWSFilterOutputStreamTestCase extends OutputStreamAbstractTestCase { public static final class TrimWSFilterOutputStreamTestCase extends OutputStreamAbstractTestCase {
protected OutputStream makeObject() { protected OutputStream makeObject() {
// NOTE: ByteArrayOutputStream does not implement flush or close... // NOTE: ByteArrayOutputStream does not implement flush or close...
return makeOutputStream(new ByteArrayOutputStream(16)); return makeOutputStream(new ByteArrayOutputStream(16));
@ -33,6 +34,7 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase {
return new TrimWhiteSpaceFilter.TrimWSFilterOutputStream(pWrapped); return new TrimWhiteSpaceFilter.TrimWSFilterOutputStream(pWrapped);
} }
@Test
public void testTrimWSOnlyWS() throws IOException { public void testTrimWSOnlyWS() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(64); ByteArrayOutputStream out = new ByteArrayOutputStream(64);
OutputStream trim = makeOutputStream(out); OutputStream trim = makeOutputStream(out);
@ -46,6 +48,7 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase {
assertEquals("Should be trimmed", "\"\"", '"' + new String(out.toByteArray()) + '"'); assertEquals("Should be trimmed", "\"\"", '"' + new String(out.toByteArray()) + '"');
} }
@Test
public void testTrimWSLeading() throws IOException { public void testTrimWSLeading() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(64); ByteArrayOutputStream out = new ByteArrayOutputStream(64);
OutputStream trim = makeOutputStream(out); OutputStream trim = makeOutputStream(out);
@ -60,6 +63,7 @@ public class TrimWhiteSpaceFilterTestCase extends FilterAbstractTestCase {
assertEquals("Should be trimmed", '"' + trimmed + '"', '"' + new String(out.toByteArray()) + '"'); assertEquals("Should be trimmed", '"' + trimmed + '"', '"' + new String(out.toByteArray()) + '"');
} }
@Test
public void testTrimWSOffsetLength() throws IOException { public void testTrimWSOffsetLength() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(64); ByteArrayOutputStream out = new ByteArrayOutputStream(64);
OutputStream trim = makeOutputStream(out); OutputStream trim = makeOutputStream(out);

View File

@ -341,7 +341,8 @@ public class ImageFilterTestCase {
// NOTE: // NOTE:
// We verify that the image is the same in both ImageFilter implementations, to make sure the image is only // 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) @Test(expected = ServletException.class)