mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 11:05:29 -04:00
Major test overhaul, now uses JUnit 4 annotation style tests.
This commit is contained in:
parent
4b77d1c22a
commit
9cafe4d9a9
@ -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
|
||||
* <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 $
|
||||
*/
|
||||
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}));
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -16,6 +20,7 @@ public class FastByteArrayOutputStreamTestCase extends OutputStreamAbstractTestC
|
||||
return new FastByteArrayOutputStream(256);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateInputStream() throws IOException {
|
||||
FastByteArrayOutputStream out = makeObject();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* MemoryCacheSeekableStreamTestCase
|
||||
* <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 $
|
||||
*/
|
||||
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];
|
||||
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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();
|
||||
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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");
|
||||
|
||||
|
@ -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 <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 $
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -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
|
||||
* <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 $
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Base64EncoderTest
|
||||
* <p/>
|
||||
@ -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 " +
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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 {
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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 {
|
||||
|
@ -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<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 {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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 <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 $
|
||||
*/
|
||||
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() {};
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
* <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 $
|
||||
*/
|
||||
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();
|
||||
|
@ -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];
|
||||
|
||||
|
@ -33,6 +33,8 @@ import org.junit.Test;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* JPEGSegmentTest
|
||||
*
|
||||
|
@ -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 <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>
|
||||
* @version $Id: PICTWriter.java,v 1.0 05.apr.2006 15:20:48 haku Exp$
|
||||
*/
|
||||
|
@ -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
|
||||
* <p/>
|
||||
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user