Upgrade to Junit5 (#1050)

* chore: Update to junit5 for servlet package

* chore: Update to junit5 for contrib package

* chore: Update to junit5 for common-image package

* chore: Update to junit5 for common-lang package

* chore: Update to junit5 for entire project files

* fix: test case for JPEGImageReaderTest failed for java 8 and 11

assertEquals was using old signature of junit4.

* Update common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-bmp/src/test/java/com/twelvemonkeys/imageio/plugins/bmp/BMPImageReaderTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageMetadataTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReaderTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageWriterTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/stream/BufferedChannelImageInputStreamTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/stream/BufferedChannelImageInputStreamTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* refactor: few indentation changes and missed test case

- review change related to missing test annotation
- unwanted new lines inside test case
- duplicate assertions

* refactor: moved the lambda expression to method reference

* review: testNotNullWithParameterNull catch block was never executed.

Added the suggested change

* Apply suggestions from code review

chore: adjust suggested indentation

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageWriterAbstractTest.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>

* refactor: using assertTimeout doesnot kill the execution, even if the timeout happens.

It is better to use assertTimeoutPreemptively in cases, where we really want to kill the execution after timeout.
https://stackoverflow.com/questions/57116801/how-to-fail-a-test-after-a-timeout-is-exceeded-in-junit-5/57116959#57116959

---------

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
This commit is contained in:
Vyshak Puthusseri
2024-11-12 14:43:15 +05:30
committed by GitHub
parent a67fdd4b80
commit 543acce8a3
194 changed files with 2554 additions and 3086 deletions
@@ -32,7 +32,6 @@ package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.StringUtil;
import com.twelvemonkeys.util.CollectionUtil;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
@@ -40,7 +39,8 @@ import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* CompoundReaderTestCase
@@ -30,12 +30,11 @@
package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* FastByteArrayOutputStreamTestCase
@@ -30,11 +30,10 @@
package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.*;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* MemoryCacheSeekableStreamTestCase
@@ -92,13 +91,13 @@ public class FileSeekableStreamTest extends SeekableInputStreamAbstractTest {
try {
FileUtil.read(stream); // Read until EOF
assertEquals("EOF not reached (test case broken)", -1, stream.read());
assertFalse("Underlying stream closed before close", closed[0]);
assertEquals(-1, stream.read(), "EOF not reached (test case broken)");
assertFalse(closed[0], "Underlying stream closed before close");
}
finally {
stream.close();
}
assertTrue("Underlying stream not closed", closed[0]);
assertTrue(closed[0], "Underlying stream not closed");
}
}
@@ -46,14 +46,14 @@
package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.ObjectAbstractTest;
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.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* InputStreamAbstractTestCase
@@ -104,15 +104,15 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
int size = 5;
InputStream input = makeInputStream(makeOrderedArray(size));
for (int i = 0; i < size; i++) {
assertTrue("Check Size [" + i + "]", (size - i) >= input.available());
assertEquals("Check Value [" + i + "]", i, input.read());
assertTrue((size - i) >= input.available(), "Check Size [" + i + "]");
assertEquals(i, input.read(), "Check Value [" + i + "]");
}
assertEquals("Available after contents all read", 0, input.available());
assertEquals(0, input.available(), "Available after contents all read");
// Test reading after the end of file
try {
int result = input.read();
assertEquals("Wrong value read after end of file", -1, result);
assertEquals( -1, result, "Wrong value read after end of file");
}
catch (IOException e) {
fail("Should not have thrown an IOException: " + e.getMessage());
@@ -122,12 +122,12 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
@Test
public void testAvailable() throws Exception {
InputStream input = makeInputStream(1);
assertFalse("Unexpected EOF", input.read() < 0);
assertEquals("Available after contents all read", 0, input.available());
assertFalse(input.read() < 0, "Unexpected EOF");
assertEquals(0, input.available(), "Available after contents all read");
// Check availbale is zero after End of file
assertEquals("End of File", -1, input.read());
assertEquals("Available after End of File", 0, input.available());
assertEquals(-1, input.read(), "End of File");
assertEquals( 0, input.available(), "Available after End of File");
}
@Test
@@ -138,26 +138,26 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
// Read into array
int count1 = input.read(bytes);
assertEquals("Read 1", bytes.length, count1);
assertEquals(bytes.length, count1, "Read 1");
for (int i = 0; i < count1; i++) {
assertEquals("Check Bytes 1", i, bytes[i]);
assertEquals(i, bytes[i], "Check Bytes 1");
}
// Read into array
int count2 = input.read(bytes);
assertEquals("Read 2", 5, count2);
assertEquals(5, count2, "Read 2");
for (int i = 0; i < count2; i++) {
assertEquals("Check Bytes 2", count1 + i, bytes[i]);
assertEquals(count1 + i, bytes[i], "Check Bytes 2");
}
// End of File
int count3 = input.read(bytes);
assertEquals("Read 3 (EOF)", -1, count3);
assertEquals(-1, count3, "Read 3 (EOF)");
// Test reading after the end of file
try {
int result = input.read(bytes);
assertEquals("Wrong value read after end of file", -1, result);
assertEquals(-1, result, "Wrong value read after end of file");
}
catch (IOException e) {
fail("Should not have thrown an IOException: " + e.getMessage());
@@ -170,20 +170,20 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
int offset = 2;
int lth = 4;
int count5 = input.read(bytes, offset, lth);
assertEquals("Read 5", lth, count5);
assertEquals(lth, count5, "Read 5");
for (int i = offset; i < lth; i++) {
assertEquals("Check Bytes 2", i - offset, bytes[i]);
assertEquals(i - offset, bytes[i], "Check Bytes 2");
}
}
@Test
public void testEOF() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(2));
assertEquals("Read 1", 0, input.read());
assertEquals("Read 2", 1, input.read());
assertEquals("Read 3", -1, input.read());
assertEquals("Read 4", -1, input.read());
assertEquals("Read 5", -1, input.read());
assertEquals(0, input.read(), "Read 1");
assertEquals(1, input.read(), "Read 2");
assertEquals(-1, input.read(), "Read 3");
assertEquals(-1, input.read(), "Read 4");
assertEquals(-1, input.read(), "Read 5");
}
@Test
@@ -205,7 +205,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
fail("Should throw IOException");
}
catch (IOException e) {
assertTrue("Wrong messge: " + e.getMessage(), e.getMessage().contains("reset"));
assertTrue(e.getMessage().contains("reset"), "Wrong messge: " + e.getMessage());
}
}
@@ -223,10 +223,10 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
// No mark may either throw exception, or reset to beginning of stream.
try {
input.reset();
assertEquals("Re-read of reset data should be same", 0, input.read());
assertEquals(0, input.read(), "Re-read of reset data should be same");
}
catch (Exception e) {
assertTrue("Wrong no mark IOException message", e.getMessage().contains("mark"));
assertTrue(e.getMessage().contains("mark"), "Wrong no mark IOException message");
}
}
@@ -249,7 +249,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
// Read further
for (int i = 0; i < 3; i++) {
assertEquals("Read After Mark [" + i + "]", (position + i), input.read());
assertEquals((position + i), input.read(), "Read After Mark [" + i + "]");
}
// Reset
@@ -257,7 +257,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
// Read from marked position
for (int i = 0; i < readlimit + 1; i++) {
assertEquals("Read After Reset [" + i + "]", (position + i), input.read());
assertEquals((position + i), input.read(), "Read After Reset [" + i + "]");
}
}
@@ -280,16 +280,16 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
// Read past marked position
for (int i = 0; i < readlimit + 1; i++) {
assertEquals("Read After Reset [" + i + "]", (position + i), input.read());
assertEquals((position + i), input.read(), "Read After Reset [" + i + "]");
}
// Reset after read limit passed, may either throw exception, or reset to last mark
try {
input.reset();
assertEquals("Re-read of reset data should be same", 1, input.read());
assertEquals(1, input.read(), "Re-read of reset data should be same");
}
catch (Exception e) {
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
}
}
@@ -302,29 +302,29 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
}
int first = input.read();
assertTrue("Expected to read positive value", first >= 0);
assertTrue(first >= 0, "Expected to read positive value");
int readlimit = 5;
// Mark
input.mark(readlimit);
int read = input.read();
assertTrue("Expected to read positive value", read >= 0);
assertTrue(read >= 0, "Expected to read positive value");
assertTrue(input.read() >= 0);
assertTrue(input.read() >= 0);
input.reset();
assertEquals("Expected value read differs from actual", read, input.read());
assertEquals(read, input.read(), "Expected value read differs from actual");
// Reset after read limit passed, may either throw exception, or reset to last good mark
try {
input.reset();
int reRead = input.read();
assertTrue("Re-read of reset data should be same as initially marked or first", reRead == read || reRead == first);
assertTrue(reRead == read || reRead == first, "Re-read of reset data should be same as initially marked or first");
}
catch (Exception e) {
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
}
}
@@ -332,17 +332,17 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
public void testSkip() throws Exception {
InputStream input = makeInputStream(makeOrderedArray(10));
assertEquals("Unexpected value read", 0, input.read());
assertEquals("Unexpected value read", 1, input.read());
assertEquals("Unexpected number of bytes skipped", 5, input.skip(5));
assertEquals("Unexpected value read", 7, input.read());
assertEquals(0, input.read(), "Unexpected value read");
assertEquals(1, input.read(), "Unexpected value read");
assertEquals(5, input.skip(5), "Unexpected number of bytes skipped");
assertEquals(7, input.read(), "Unexpected value read");
assertEquals("Unexpected number of bytes skipped", 2, input.skip(5)); // only 2 left to skip
assertEquals("Unexpected value read after EOF", -1, input.read());
assertEquals(2, input.skip(5), "Unexpected number of bytes skipped"); // only 2 left to skip
assertEquals(-1, input.read(), "Unexpected value read after EOF");
// Spec says skip might return 0 or negative after EOF...
assertTrue("Positive value skipped after EOF", input.skip(5) <= 0); // End of file
assertEquals("Unexpected value read after EOF", -1, input.read());
assertTrue(input.skip(5) <= 0, "Positive value skipped after EOF"); // End of file
assertEquals(-1, input.read(), "Unexpected value read after EOF");
}
@Test
@@ -30,12 +30,11 @@
package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* LittleEndianDataInputStreamTest
@@ -31,13 +31,12 @@
package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.ObjectAbstractTest;
import org.junit.Test;
import java.io.IOException;
import java.io.OutputStream;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* InputStreamAbstractTestCase
@@ -31,12 +31,12 @@
package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.ObjectAbstractTest;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* ReaderAbstractTestCase
@@ -112,7 +112,7 @@ public abstract class ReaderAbstractTest extends ObjectAbstractTest {
int toSkip = mInput.length();
while (toSkip > 0) {
long skipped = reader.skip(toSkip);
assertFalse("Skipped < 0", skipped < 0);
assertFalse(skipped < 0, "Skipped < 0");
toSkip -= skipped;
}
@@ -30,10 +30,8 @@
package com.twelvemonkeys.io;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* SeekableAbstractTestCase
@@ -30,14 +30,13 @@
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.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* SeekableInputStreamAbstractTest
@@ -79,25 +78,25 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
return; // Not supported, skip test
}
assertTrue("Expected to read positive value", input.read() >= 0);
assertTrue(input.read() >= 0, "Expected to read positive value");
int readlimit = 5;
// Mark
input.mark(readlimit);
int read = input.read();
assertTrue("Expected to read positive value", read >= 0);
assertTrue(read >= 0, "Expected to read positive value");
input.reset();
assertEquals("Expected value read differs from actual", read, input.read());
assertEquals(read, input.read(), "Expected value read differs from actual");
// 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());
assertEquals(0, input.read(), "Re-read of reset data should be first");
}
catch (Exception e) {
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
}
}
@@ -127,7 +126,7 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
seekable.seek(pos);
long streamPos = seekable.getStreamPosition();
assertEquals("Stream positon should match seeked position", pos, streamPos);
assertEquals(pos, streamPos, "Stream positon should match seeked position");
}
@Test
@@ -137,7 +136,7 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
seekable.seek(pos);
seekable.flushBefore(pos);
long flushedPos = seekable.getFlushedPosition();
assertEquals("Flushed positon should match position", pos, flushedPos);
assertEquals(pos, flushedPos, "Flushed positon should match position");
try {
seekable.seek(pos - 1);
@@ -382,13 +381,13 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
int val;
val = stream.read();
assertFalse("Unexepected EOF", val == -1);
assertFalse(val == -1, "Unexepected EOF");
val = stream.read();
assertFalse("Unexepected EOF", val == -1);
assertFalse(val == -1, "Unexepected EOF");
val = stream.read();
assertFalse("Unexepected EOF", val == -1);
assertFalse(val == -1, "Unexepected EOF");
val = stream.read();
assertFalse("Unexepected EOF", val == -1);
assertFalse(val == -1, "Unexepected EOF");
stream.seek(0);
@@ -422,19 +421,19 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
stream.seek(0);
for (int i = 0; i < bytes.length; i += 2) {
assertEquals("Wrong stream position", i, stream.getStreamPosition());
assertEquals(i, stream.getStreamPosition(), "Wrong stream position");
int count = stream.read(buffer, 0, 2);
assertEquals(2, count);
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], buffer[0]);
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i + 1], buffer[1]);
assertEquals(bytes[i], buffer[0], String.format("Wrong value read at pos %d", stream.getStreamPosition()));
assertEquals(bytes[i + 1], buffer[1], String.format("Wrong value read at pos %d", stream.getStreamPosition()));
}
stream.seek(0);
for (int i = 0; i < bytes.length; i++) {
assertEquals("Wrong stream position", i, stream.getStreamPosition());
assertEquals(i, stream.getStreamPosition(), "Wrong stream position");
int actual = stream.read();
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i] & 0xff, actual);
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], (byte) actual);
assertEquals(bytes[i] & 0xff, actual, String.format("Wrong value read at pos %d", stream.getStreamPosition()));
assertEquals(bytes[i], (byte) actual, String.format("Wrong value read at pos %d", stream.getStreamPosition()));
}
}
@@ -456,14 +455,14 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
try {
FileUtil.read(stream); // Read until EOF
assertEquals("EOF not reached (test case broken)", -1, stream.read());
assertFalse("Underlying stream closed before close", closed[0]);
assertEquals(-1, stream.read(), "EOF not reached (test case broken)");
assertFalse(closed[0], "Underlying stream closed before close");
}
finally {
stream.close();
}
assertTrue("Underlying stream not closed", closed[0]);
assertTrue(closed[0], "Underlying stream not closed");
}
@@ -31,12 +31,12 @@
package com.twelvemonkeys.io;
import com.twelvemonkeys.lang.StringUtil;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* StringArrayReaderTestCase
@@ -1,15 +1,14 @@
package com.twelvemonkeys.io;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.Arrays;
import java.util.Random;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* SubStreamTest.
@@ -23,14 +22,18 @@ public class SubStreamTest {
private final Random rng = new Random(2918475687L);
@SuppressWarnings("resource")
@Test(expected = IllegalArgumentException.class)
@Test
public void testCreateNullStream() {
new SubStream(null, 42);
assertThrows(IllegalArgumentException.class, () -> {
new SubStream(null, 42);
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testCreateNegativeLength() {
new SubStream(new ByteArrayInputStream(new byte[1]), -1);
assertThrows(IllegalArgumentException.class, () -> {
new SubStream(new ByteArrayInputStream(new byte[1]), -1);
});
}
@Test
@@ -100,15 +103,17 @@ public class SubStreamTest {
}
@SuppressWarnings("EmptyTryBlock")
@Test(timeout = 500L)
@Test
public void testCloseConsumesAllShortStream() throws IOException {
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[13]);
assertTimeoutPreemptively(Duration.ofMillis(500), () -> {
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[13]);
try (InputStream ignore = new SubStream(stream, 42)) {
// Nothing here...
}
try (InputStream ignore = new SubStream(stream, 42)) {
// Nothing here...
}
assertEquals(0, stream.available());
assertEquals(-1, stream.read());
assertEquals(0, stream.available());
assertEquals(-1, stream.read());
});
}
}
@@ -31,15 +31,13 @@
package com.twelvemonkeys.io.enc;
import com.twelvemonkeys.io.FileUtil;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Base64DecoderTest
* <p/>
@@ -66,7 +64,7 @@ public class Base64DecoderTest extends DecoderAbstractTest {
FileUtil.copy(in, bytes);
assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
assertEquals("", new String(bytes.toByteArray()), "Strings does not match");
}
@Test
@@ -78,7 +76,7 @@ public class Base64DecoderTest extends DecoderAbstractTest {
FileUtil.copy(in, bytes);
assertEquals("Strings does not match", "test", new String(bytes.toByteArray()));
assertEquals("test", new String(bytes.toByteArray()), "Strings does not match");
}
@Test
@@ -93,11 +91,12 @@ public class Base64DecoderTest extends DecoderAbstractTest {
FileUtil.copy(in, bytes);
assertEquals("Strings does not match",
assertEquals(
"Lorem ipsum dolor sit amet, consectetuer adipiscing " +
"elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " +
"dapibus laoreet purus. Nunc viverra dictum nisl. Integer " +
"ullamcorper, nisi in dictum amet.",
new String(bytes.toByteArray()));
new String(bytes.toByteArray()),
"Strings does not match");
}
}
@@ -30,13 +30,12 @@
package com.twelvemonkeys.io.enc;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Base64EncoderTest
@@ -63,7 +62,7 @@ public class Base64EncoderTest extends EncoderAbstractTest {
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
out.write(data.getBytes());
assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
assertEquals("", new String(bytes.toByteArray()), "Strings does not match");
}
@Test
@@ -74,7 +73,7 @@ public class Base64EncoderTest extends EncoderAbstractTest {
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
out.write(data.getBytes());
assertEquals("Strings does not match", "dGVzdA==", new String(bytes.toByteArray()));
assertEquals("dGVzdA==", new String(bytes.toByteArray()), "Strings does not match");
}
@Test
@@ -88,11 +87,12 @@ public class Base64EncoderTest extends EncoderAbstractTest {
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
out.write(data.getBytes());
assertEquals("Strings does not match",
assertEquals(
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" +
"c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" +
"b3JlZXQgcHVydXMuIE51bmMgdml2ZXJyYSBkaWN0dW0gbmlzbC4gSW50ZWdlciB1bGxhbWNvcnBlciwg" +
"bmlzaSBpbiBkaWN0dW0gYW1ldC4=",
new String(bytes.toByteArray()));
new String(bytes.toByteArray()),
"Strings does not match");
}
}
@@ -32,12 +32,13 @@ package com.twelvemonkeys.io.enc;
import com.twelvemonkeys.io.FileUtil;
import com.twelvemonkeys.lang.ObjectAbstractTest;
import org.junit.Test;
import java.awt.image.ImageProducer;
import java.io.*;
import java.nio.ByteBuffer;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* AbstractDecoderTest
@@ -55,13 +56,13 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
return createDecoder();
}
@Test(expected = NullPointerException.class)
@Test
public final void testNullDecode() throws IOException {
Decoder decoder = createDecoder();
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]);
decoder.decode(bytes, null);
fail("null should throw NullPointerException");
assertThrows(NullPointerException.class, () -> {
decoder.decode(bytes, null);
});
}
@Test
@@ -71,7 +72,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
try {
int count = decoder.decode(bytes, ByteBuffer.allocate(128));
assertEquals("Should not be able to read any bytes", 0, count);
assertEquals( 0, count, "Should not be able to read any bytes");
}
catch (EOFException allowed) {
// Okay
@@ -94,7 +95,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
byte[] encoded = outBytes.toByteArray();
byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createDecoder()));
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
assertArrayEquals(data, decoded, String.format("Data %d", pLength));
InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createDecoder());
outBytes = new ByteArrayOutputStream();
@@ -103,7 +104,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
in.close();
decoded = outBytes.toByteArray();
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
assertArrayEquals(data, decoded, String.format("Data %d", pLength));
}
@Test
@@ -30,7 +30,6 @@
package com.twelvemonkeys.io.enc;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -39,7 +38,8 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DecoderStreamTest {
@@ -33,13 +33,12 @@ package com.twelvemonkeys.io.enc;
import com.twelvemonkeys.io.FileUtil;
import com.twelvemonkeys.lang.ObjectAbstractTest;
import org.junit.Test;
import java.io.*;
import java.util.Random;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* AbstractEncoderTest
@@ -30,8 +30,6 @@
package com.twelvemonkeys.io.enc;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -39,7 +37,8 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
import static org.junit.Assert.assertArrayEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class EncoderStreamTest {
@@ -31,9 +31,9 @@
package com.twelvemonkeys.io.ole2;
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
import org.junit.Test;
import javax.imageio.stream.MemoryCacheImageInputStream;
import java.awt.image.ImageProducer;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -43,8 +43,8 @@ import java.nio.ByteOrder;
import java.util.SortedSet;
import java.util.TreeSet;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* CompoundDocumentTestCase
*
@@ -59,8 +59,8 @@ public class CompoundDocumentTest {
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());
assertNotNull(input, "Missing test resource!");
assertEquals( "file", input.getProtocol(), "Test resource not a file:// resource");
try {
return new CompoundDocument(new File(input.toURI()));
@@ -103,7 +103,7 @@ public class CompoundDocumentTest {
}
}
@Test(expected = UnsupportedOperationException.class)
@Test
public void testChildEntriesUnmodifiable() throws IOException {
try (CompoundDocument document = createTestDocument()) {
Entry root = document.getRootEntry();
@@ -111,9 +111,10 @@ public class CompoundDocumentTest {
assertNotNull(root);
SortedSet<Entry> children = root.getChildEntries();
// Should not be allowed, as it modifies the internal structure
children.remove(children.first());
assertThrows(UnsupportedOperationException.class, () -> {
// Should not be allowed, as it modifies the internal structure
children.remove(children.first());
});
}
}
@@ -128,7 +129,7 @@ public class CompoundDocumentTest {
Entry catalog = root.getChildEntry("Catalog");
assertNotNull(catalog);
assertNotNull("Input stream may not be null", catalog.getInputStream());
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
}
}
@@ -136,7 +137,7 @@ public class CompoundDocumentTest {
public void testReadCatalogInputStream() throws IOException {
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
assertNotNull("Missing test resource!", input);
assertNotNull(input, "Missing test resource!");
CompoundDocument document = new CompoundDocument(input);
Entry root = document.getRootEntry();
@@ -145,14 +146,14 @@ public class CompoundDocumentTest {
Entry catalog = root.getChildEntry("Catalog");
assertNotNull(catalog);
assertNotNull("Input stream may not be null", catalog.getInputStream());
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
}
@Test
public void testReadCatalogSeekableStream() throws IOException {
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
assertNotNull("Missing test resource!", input);
assertNotNull(input, "Missing test resource!");
CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input));
Entry root = document.getRootEntry();
@@ -161,14 +162,14 @@ public class CompoundDocumentTest {
Entry catalog = root.getChildEntry("Catalog");
assertNotNull(catalog);
assertNotNull("Input stream may not be null", catalog.getInputStream());
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
}
@Test
public void testReadCatalogImageInputStream() throws IOException {
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
assertNotNull("Missing test resource!", input);
assertNotNull(input, "Missing test resource!");
MemoryCacheImageInputStream stream = new MemoryCacheImageInputStream(input);
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
@@ -183,6 +184,6 @@ public class CompoundDocumentTest {
Entry catalog = root.getChildEntry("Catalog");
assertNotNull(catalog);
assertNotNull("Input stream may not be null", catalog.getInputStream());
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
}
}
@@ -31,7 +31,7 @@
package com.twelvemonkeys.io.ole2;
import com.twelvemonkeys.io.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -33,7 +33,6 @@ package com.twelvemonkeys.io.ole2;
import com.twelvemonkeys.io.InputStreamAbstractTest;
import com.twelvemonkeys.io.LittleEndianDataOutputStream;
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -42,7 +41,8 @@ import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* CompoundDocument_StreamTestCase
@@ -165,8 +165,8 @@ public class CompoundDocument_StreamTest extends InputStreamAbstractTest {
count++;
}
assertFalse("Short stream", count < 32);
assertFalse("Stream overrun", count > 32);
assertFalse(count < 32, "Short stream");
assertFalse(count > 32, "Stream overrun");
}
@Test
@@ -30,9 +30,8 @@
package com.twelvemonkeys.net;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* HTTPUtilTest