commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1649368 - /commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingGuessFormatTest.java
Date Sun, 04 Jan 2015 17:27:29 GMT
Author: britter
Date: Sun Jan  4 17:27:29 2015
New Revision: 1649368

URL: http://svn.apache.org/r1649368
Log:
Make ImagingGuessFormatTest a parameterized test

Modified:
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingGuessFormatTest.java

Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingGuessFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingGuessFormatTest.java?rev=1649368&r1=1649367&r2=1649368&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingGuessFormatTest.java
(original)
+++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingGuessFormatTest.java
Sun Jan  4 17:27:29 2015
@@ -22,10 +22,15 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
 
 import org.apache.commons.io.FilenameUtils;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
+@RunWith(Parameterized.class)
 public class ImagingGuessFormatTest extends ImagingTest {
 
     public static final String BMP_IMAGE_FILE = "bmp\\1\\Oregon Scientific DS6639 - DSC_0307
- small.bmp";
@@ -40,44 +45,47 @@ public class ImagingGuessFormatTest exte
     public static final String PGM_IMAGE_FILE = "pbm\\1\\Oregon Scientific DS6639 - DSC_0307
- small.pgm";
     public static final String PPM_IMAGE_FILE = "pbm\\1\\Oregon Scientific DS6639 - DSC_0307
- small.ppm";
     public static final String TGA_IMAGE_FILE = "tga\\1\\Oregon Scientific DS6639 - DSC_0307
- small.tga";
+    public static final String UNKNOWN_IMAGE_FILE = "info.txt";
 
-    @Test
-    public void testGuess_all() throws Exception {
-        testGuess(ImageFormats.PNG, PNG_IMAGE_FILE);
-        testGuess(ImageFormats.GIF, GIF_IMAGE_FILE);
-        testGuess(ImageFormats.ICNS, ICNS_IMAGE_FILE);
-        // TODO(cmchen): add ability to sniff ICOs if possible.
-        // testGuess(ImageFormat.IMAGE_FORMAT_ICO, ICO_IMAGE_FILE);
-        testGuess(ImageFormats.TIFF, TIFF_IMAGE_FILE);
-        testGuess(ImageFormats.JPEG, JPEG_IMAGE_FILE);
-        testGuess(ImageFormats.BMP, BMP_IMAGE_FILE);
-        testGuess(ImageFormats.PSD, PSD_IMAGE_FILE);
-        testGuess(ImageFormats.PBM, PBM_IMAGE_FILE);
-        testGuess(ImageFormats.PGM, PGM_IMAGE_FILE);
-        testGuess(ImageFormats.PPM, PPM_IMAGE_FILE);
-        // TODO(cmchen): add ability to sniff TGAs if possible.
-        // testGuess(ImageFormat.IMAGE_FORMAT_TGA, TGA_IMAGE_FILE);
-        // TODO(cmchen): Add test images for these formats.
-        // testGuess(ImageFormat.IMAGE_FORMAT_PNM, PNM_IMAGE_FILE);
-        // testGuess(ImageFormat.IMAGE_FORMAT_JBIG2, JBIG2_IMAGE_FILE);
-    }
+    private final ImageFormats expectedFormat;
+    private final String pathToFile;
 
-    public static final String UNKNOWN_IMAGE_FILE = "info.txt";
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(
+                new Object[] { ImageFormats.PNG, PNG_IMAGE_FILE },
+                new Object[] { ImageFormats.GIF, GIF_IMAGE_FILE },
+                new Object[] { ImageFormats.ICNS, ICNS_IMAGE_FILE },
+                // TODO(cmchen): add ability to sniff ICOs if possible.
+                // new Object[] { ImageFormat.IMAGE_FORMAT_ICO, ICO_IMAGE_FILE },
+                new Object[] { ImageFormats.TIFF, TIFF_IMAGE_FILE },
+                new Object[] { ImageFormats.JPEG, JPEG_IMAGE_FILE },
+                new Object[] { ImageFormats.BMP, BMP_IMAGE_FILE },
+                new Object[] { ImageFormats.PSD, PSD_IMAGE_FILE },
+                new Object[] { ImageFormats.PBM, PBM_IMAGE_FILE },
+                new Object[] { ImageFormats.PGM, PGM_IMAGE_FILE },
+                new Object[] { ImageFormats.PPM, PPM_IMAGE_FILE },
+                // TODO(cmchen): add ability to sniff TGAs if possible.
+                // new Object[] { ImageFormat.IMAGE_FORMAT_TGA, TGA_IMAGE_FILE },
+                // TODO(cmchen): Add test images for these formats.
+                // new Object[] { ImageFormat.IMAGE_FORMAT_PNM, PNM_IMAGE_FILE },
+                // new Object[] { ImageFormat.IMAGE_FORMAT_JBIG2, JBIG2_IMAGE_FILE },
+                new Object[] { ImageFormats.UNKNOWN, UNKNOWN_IMAGE_FILE }
+        );
+    }
 
-    @Test
-    public void testGuess_unknown() throws Exception {
-        testGuess(ImageFormats.UNKNOWN, UNKNOWN_IMAGE_FILE);
+    public ImagingGuessFormatTest(ImageFormats expectedFormat, String pathToFile) {
+        this.expectedFormat = expectedFormat;
+        this.pathToFile = pathToFile;
     }
 
-    public void testGuess(final ImageFormat expectedFormat, String imagePath)
-            throws Exception {
-        imagePath = FilenameUtils.separatorsToSystem(imagePath);
+    @Test
+    public void testGuessFormat() throws Exception {
+        String imagePath = FilenameUtils.separatorsToSystem(pathToFile);
         final File imageFile = new File(TEST_IMAGE_FOLDER, imagePath);
 
-        assertTrue(imageFile.exists());
-        assertTrue(imageFile.isFile());
         final ImageFormat guessedFormat = Imaging.guessFormat(imageFile);
-        assertNotNull(guessedFormat);
-        assertEquals(guessedFormat, expectedFormat);
+        assertEquals(expectedFormat, guessedFormat);
     }
+
 }



Mime
View raw message