mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
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:
committed by
GitHub
parent
a67fdd4b80
commit
543acce8a3
+11
-9
@@ -32,16 +32,16 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SVGImageReaderSpiTest.
|
||||
@@ -83,18 +83,20 @@ public class SVGImageReaderSpiTest {
|
||||
public void canDecodeInput() throws Exception {
|
||||
for (String validInput : VALID_INPUTS) {
|
||||
try (ImageInputStream input = ImageIO.createImageInputStream(getClass().getResource(validInput))) {
|
||||
assertTrue("Can't read valid input: " + validInput, provider.canDecodeInput(input));
|
||||
assertTrue(provider.canDecodeInput(input), "Can't read valid input: " + validInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test will time out, if EOFs are not properly detected, see #275
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
public void canDecodeInputInvalid() throws Exception {
|
||||
for (String invalidInput : INVALID_INPUTS) {
|
||||
try (ImageInputStream input = new ByteArrayImageInputStream(invalidInput.getBytes(StandardCharsets.UTF_8))) {
|
||||
assertFalse("Claims to read invalid input:" + invalidInput, provider.canDecodeInput(input));
|
||||
assertTimeoutPreemptively(Duration.ofMillis(5000), () -> {
|
||||
for (String invalidInput : INVALID_INPUTS) {
|
||||
try (ImageInputStream input = new ByteArrayImageInputStream(invalidInput.getBytes(StandardCharsets.UTF_8))) {
|
||||
assertFalse(provider.canDecodeInput(input), "Claims to read invalid input:" + invalidInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+13
-15
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
@@ -52,10 +49,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -128,18 +124,18 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
int current = image.getRGB(x, y);
|
||||
if (x < quadPoint) {
|
||||
if (y < quadPoint) {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF0000FF, current);
|
||||
assertEquals( 0xFF0000FF, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
else {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFFFF0000, current);
|
||||
assertEquals(0xFFFF0000, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (y < quadPoint) {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF00FF00, current);
|
||||
assertEquals(0xFF00FF00, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
else {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF000000, current);
|
||||
assertEquals(0xFF000000, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,14 +167,14 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
@@ -316,7 +312,7 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = SecurityException.class)
|
||||
@Test
|
||||
public void testDisallowedExternalResources() throws URISyntaxException, IOException {
|
||||
// system-property set to true in surefire-plugin-settings in the pom
|
||||
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
||||
@@ -333,7 +329,9 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
// `reader.read` for `/svg/barChart.svg` should raise
|
||||
// a SecurityException when External Resources are blocked
|
||||
// because the API invocation gets preference
|
||||
reader.read(0, param);
|
||||
assertThrows(SecurityException.class, () -> {
|
||||
reader.read(0, param);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
|
||||
+4
-5
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.wmf;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
@@ -42,6 +39,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* WMFImageReaderTest
|
||||
*
|
||||
@@ -77,14 +76,14 @@ public class WMFImageReaderTest extends ImageReaderAbstractTest<WMFImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
Reference in New Issue
Block a user