IMAGING-242 Replace Theories with nested loops

Finish the work started in
https://github.com/apache/commons-imaging/pull/59 and convert the
vintage @Theories to Jupiter @MethodSources.

Note that Jupiter doesn't have a built-in mechanism to create a
Cartesian product between two sources (like @Theories does), so it had
to be explicitly implemented manually.
diff --git a/pom.xml b/pom.xml
index e341557..354d986 100644
--- a/pom.xml
+++ b/pom.xml
@@ -225,25 +225,6 @@
       <version>2.1</version>
       <scope>test</scope>
     </dependency>
-    <!-- the next three dependencies are for tests with theories/datapoints, see IMAGING-242 -->
-    <dependency>
-      <groupId>org.junit.platform</groupId>
-      <artifactId>junit-platform-launcher</artifactId>
-      <version>1.5.2</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter-engine</artifactId>
-      <version>${junit.version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
-      <version>${junit.version}</version>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/BitmapRoundtripTest.java b/src/test/java/org/apache/commons/imaging/roundtrip/BitmapRoundtripTest.java
index dd94354..b2fd050 100644
--- a/src/test/java/org/apache/commons/imaging/roundtrip/BitmapRoundtripTest.java
+++ b/src/test/java/org/apache/commons/imaging/roundtrip/BitmapRoundtripTest.java
@@ -18,16 +18,14 @@
 package org.apache.commons.imaging.roundtrip;
 
 import java.awt.image.BufferedImage;
+import java.util.stream.Stream;
 
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
-@RunWith(Theories.class)
 public class BitmapRoundtripTest extends RoundtripBase {
 
-    @DataPoints
     public static BufferedImage[] images = new BufferedImage[] {
             TestImages.createArgbBitmapImage(1, 1), // minimal
             TestImages.createArgbBitmapImage(2, 2), //
@@ -40,10 +38,12 @@
             TestImages.createBitmapBitmapImage(300, 300), // larger than 256
     };
 
-    @DataPoints
-    public static FormatInfo[] formatInfos = FormatInfo.READ_WRITE_FORMATS;
+    public static Stream<Arguments> testBitmapRoundtrip() {
+        return createRoundtripArguments(images);
+    }
 
-    @Theory
+    @ParameterizedTest
+    @MethodSource
     public void testBitmapRoundtrip(final BufferedImage testImage, final FormatInfo formatInfo) throws Exception {
         roundtrip(formatInfo, testImage, "bitmap", true);
     }
diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/FullColorRoundtrip.java b/src/test/java/org/apache/commons/imaging/roundtrip/FullColorRoundtrip.java
index cf75c14..cc161eb 100644
--- a/src/test/java/org/apache/commons/imaging/roundtrip/FullColorRoundtrip.java
+++ b/src/test/java/org/apache/commons/imaging/roundtrip/FullColorRoundtrip.java
@@ -18,16 +18,14 @@
 package org.apache.commons.imaging.roundtrip;
 
 import java.awt.image.BufferedImage;
+import java.util.stream.Stream;
 
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
-@RunWith(Theories.class)
 public class FullColorRoundtrip extends RoundtripBase {
 
-    @DataPoints
     public static BufferedImage[] images = new BufferedImage[]{
             TestImages.createFullColorImage(1, 1), // minimal
             TestImages.createFullColorImage(2, 2), //
@@ -35,10 +33,12 @@
             TestImages.createFullColorImage(300, 300), // larger than 256
     };
 
-    @DataPoints
-    public static FormatInfo[] formatInfos = FormatInfo.READ_WRITE_FORMATS;
+    public static Stream<Arguments> testFullColorRoundtrip() {
+        return createRoundtripArguments(images);
+    }
 
-    @Theory
+    @ParameterizedTest
+    @MethodSource
     public void testFullColorRoundtrip(final BufferedImage testImage, final FormatInfo formatInfo) throws Exception {
         boolean imageExact = true;
         if (formatInfo.colorSupport == FormatInfo.COLOR_BITMAP) {
diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/GrayscaleRountripTest.java b/src/test/java/org/apache/commons/imaging/roundtrip/GrayscaleRountripTest.java
index 5b60acc..c8feb2c 100644
--- a/src/test/java/org/apache/commons/imaging/roundtrip/GrayscaleRountripTest.java
+++ b/src/test/java/org/apache/commons/imaging/roundtrip/GrayscaleRountripTest.java
@@ -18,16 +18,14 @@
 package org.apache.commons.imaging.roundtrip;
 
 import java.awt.image.BufferedImage;
+import java.util.stream.Stream;
 
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
-@RunWith(Theories.class)
 public class GrayscaleRountripTest extends RoundtripBase {
 
-    @DataPoints
     public static BufferedImage[] images = new BufferedImage[]{
             TestImages.createArgbBitmapImage(1, 1), // minimal
             TestImages.createArgbGrayscaleImage(2, 2), //
@@ -40,10 +38,12 @@
             TestImages.createGrayscaleGrayscaleImage(300, 300), // larger than 256
     };
 
-    @DataPoints
-    public static FormatInfo[] formatInfos = FormatInfo.READ_WRITE_FORMATS;
+    public static Stream<Arguments> testGrayscaleRoundtrip() {
+        return createRoundtripArguments(images);
+    }
 
-    @Theory
+    @ParameterizedTest
+    @MethodSource
     public void testGrayscaleRoundtrip(final BufferedImage testImage, final FormatInfo formatInfo) throws Exception {
             final boolean imageExact = formatInfo.colorSupport != FormatInfo.COLOR_BITMAP;
 
diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/LimitedColorRoundtripTest.java b/src/test/java/org/apache/commons/imaging/roundtrip/LimitedColorRoundtripTest.java
index db2e5be..8e3adae 100644
--- a/src/test/java/org/apache/commons/imaging/roundtrip/LimitedColorRoundtripTest.java
+++ b/src/test/java/org/apache/commons/imaging/roundtrip/LimitedColorRoundtripTest.java
@@ -18,16 +18,14 @@
 package org.apache.commons.imaging.roundtrip;
 
 import java.awt.image.BufferedImage;
+import java.util.stream.Stream;
 
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
-@RunWith(Theories.class)
 public class LimitedColorRoundtripTest extends RoundtripBase {
 
-    @DataPoints
     public static BufferedImage[] images = new BufferedImage[] {
             TestImages.createLimitedColorImage(1, 1), // minimal
             TestImages.createLimitedColorImage(2, 2), //
@@ -35,10 +33,12 @@
             TestImages.createLimitedColorImage(300, 300), // larger than 256
     };
 
-    @DataPoints
-    public static FormatInfo[] formatInfos = FormatInfo.READ_WRITE_FORMATS;
+    public static Stream<Arguments> testLimitedColorRoundtrip() {
+        return createRoundtripArguments(images);
+    }
 
-    @Theory
+    @ParameterizedTest
+    @MethodSource
     public void testLimitedColorRoundtrip(final BufferedImage testImage, final FormatInfo formatInfo) throws Exception {
             boolean imageExact = true;
             if (formatInfo.colorSupport == FormatInfo.COLOR_BITMAP) {
diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/PixelDensityRoundtrip.java b/src/test/java/org/apache/commons/imaging/roundtrip/PixelDensityRoundtrip.java
index 523b681..9032d79 100644
--- a/src/test/java/org/apache/commons/imaging/roundtrip/PixelDensityRoundtrip.java
+++ b/src/test/java/org/apache/commons/imaging/roundtrip/PixelDensityRoundtrip.java
@@ -19,27 +19,28 @@
 
 import java.awt.image.BufferedImage;
 import java.io.File;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.stream.Stream;
 
 import org.apache.commons.imaging.ImageInfo;
 import org.apache.commons.imaging.Imaging;
 import org.apache.commons.imaging.ImagingConstants;
 import org.apache.commons.imaging.PixelDensity;
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-@RunWith(Theories.class)
 public class PixelDensityRoundtrip extends RoundtripBase {
 
-    @DataPoints
-    public static FormatInfo[] formatInfos = FormatInfo.PRESERVING_RESOLUTION_FORMATS;
+    public static Stream<FormatInfo> testPixelDensityRoundtrip() {
+        return Arrays.stream(FormatInfo.PRESERVING_RESOLUTION_FORMATS);
+    }
 
-    @Theory
+    @ParameterizedTest
+    @MethodSource
     public void testPixelDensityRoundtrip(final FormatInfo formatInfo) throws Exception {
         final BufferedImage testImage = TestImages.createFullColorImage(2, 2);
 
diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripBase.java b/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripBase.java
index 635e45e..7511b2f 100644
--- a/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripBase.java
+++ b/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripBase.java
@@ -21,8 +21,10 @@
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.stream.Stream;
 
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImageWriteException;
@@ -31,6 +33,7 @@
 import org.apache.commons.imaging.common.RgbBufferedImageFactory;
 import org.apache.commons.imaging.internal.Debug;
 import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.provider.Arguments;
 
 public class RoundtripBase {
 
@@ -74,4 +77,7 @@
         return File.createTempFile(prefix, suffix, folder);
     }
 
+    public static Stream<Arguments> createRoundtripArguments(BufferedImage[] images) {
+        return Arrays.stream(images).flatMap(i -> Arrays.stream(FormatInfo.READ_WRITE_FORMATS).map(f -> Arguments.of(i, f)));
+    }
 }