mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-03-20 00:00:03 -04:00
Test case clean-up + minor fixes.
This commit is contained in:
@@ -5,7 +5,6 @@ import com.twelvemonkeys.lang.ObjectAbstractTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -25,17 +24,13 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase {
|
||||
return createDecoder();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = NullPointerException.class)
|
||||
public final void testNullDecode() throws IOException {
|
||||
Decoder decoder = createDecoder();
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]);
|
||||
|
||||
try {
|
||||
decoder.decode(bytes, null);
|
||||
fail("null should throw NullPointerException");
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
}
|
||||
decoder.decode(bytes, null);
|
||||
fail("null should throw NullPointerException");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,7 +39,7 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase {
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[0]);
|
||||
|
||||
try {
|
||||
int count = decoder.decode(bytes, new byte[2]);
|
||||
int count = decoder.decode(bytes, new byte[128]);
|
||||
assertEquals("Should not be able to read any bytes", 0, count);
|
||||
}
|
||||
catch (EOFException allowed) {
|
||||
@@ -68,27 +63,21 @@ public abstract class DecoderAbstractTestCase extends ObjectAbstractTestCase {
|
||||
byte[] encoded = outBytes.toByteArray();
|
||||
|
||||
byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createDecoder()));
|
||||
assertTrue(Arrays.equals(data, decoded));
|
||||
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
|
||||
|
||||
InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createDecoder());
|
||||
outBytes = new ByteArrayOutputStream();
|
||||
/*
|
||||
byte[] buffer = new byte[3];
|
||||
for (int n = in.read(buffer); n > 0; n = in.read(buffer)) {
|
||||
outBytes.write(buffer, 0, n);
|
||||
}
|
||||
*/
|
||||
FileUtil.copy(in, outBytes);
|
||||
|
||||
outBytes.close();
|
||||
in.close();
|
||||
|
||||
decoded = outBytes.toByteArray();
|
||||
assertTrue(Arrays.equals(data, decoded));
|
||||
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testStreams() throws Exception {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 1; i < 100; i++) {
|
||||
try {
|
||||
runStreamTest(i);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import com.twelvemonkeys.io.enc.Decoder;
|
||||
import com.twelvemonkeys.io.enc.Encoder;
|
||||
import com.twelvemonkeys.io.enc.PackBitsDecoder;
|
||||
import com.twelvemonkeys.io.enc.PackBitsEncoder;
|
||||
|
||||
/**
|
||||
* PackBitsDecoderTest
|
||||
* <p/>
|
||||
|
||||
Reference in New Issue
Block a user