Author: britter
Date: Sun Dec 28 21:40:39 2014
New Revision: 1648256

URL: http://svn.apache.org/r1648256
Log:
Refactory ByteSource tests to be parameterized tests

Modified:
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingTest.java
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceDataTest.java
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceTest.java

Modified: 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingTest.java?rev=1648256&r1=1648255&r2=1648256&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingTest.java
 (original)
+++ 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/ImagingTest.java
 Sun Dec 28 21:40:39 2014
@@ -72,7 +72,7 @@ public abstract class ImagingTest implem
         return images.get(0);
     }
 
-    protected List<File> getTestImages() throws IOException, 
ImageReadException {
+    protected static List<File> getTestImages() throws IOException, 
ImageReadException {
         return getTestImages(null, -1);
     }
 
@@ -104,7 +104,7 @@ public abstract class ImagingTest implem
         new FileSystemTraversal().traverseFiles(imagesFolder, visitor);
     }
 
-    protected List<File> getTestImages(final ImageFilter filter, final int max)
+    protected static List<File> getTestImages(final ImageFilter filter, final 
int max)
             throws IOException, ImageReadException {
         final List<File> images = new ArrayList<File>();
 

Modified: 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceDataTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceDataTest.java?rev=1648256&r1=1648255&r2=1648256&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceDataTest.java
 (original)
+++ 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceDataTest.java
 Sun Dec 28 21:40:39 2014
@@ -25,13 +25,29 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collection;
 
 import org.apache.commons.imaging.util.IoUtils;
 import org.apache.commons.io.IOUtils;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
+@RunWith(Parameterized.class)
 public class ByteSourceDataTest extends ByteSourceTest {
 
+    private byte[] testByteArray;
+
+    @Parameterized.Parameters
+    public static Collection<byte[]> data() {
+        return Arrays.asList(getTestByteArrays());
+    }
+
+    public ByteSourceDataTest(byte[] testByteArray) {
+        this.testByteArray = testByteArray;
+    }
+
     private interface ByteSourceFactory {
         public ByteSource getByteSource(byte src[]) throws IOException;
     }
@@ -131,18 +147,15 @@ public class ByteSourceDataTest extends
     }
 
     @Test
-    public void test() throws Exception {
-        final ByteSourceFactory byteSourceFactories[] = {
-                new ByteSourceFileFactory(),
-                new ByteSourceInputStreamFileFactory(),
-                new ByteSourceInputStreamRawFactory(), };
-
-        final byte testByteArrays[][] = getTestByteArrays();
-
-        for (final byte[] testByteArray : testByteArrays) {
-            for (final ByteSourceFactory byteSourceFactory : 
byteSourceFactories) {
-                writeAndReadBytes(byteSourceFactory, testByteArray);
-            }
-        }
+    public void testByteSourceFileFactory() throws Exception {
+        writeAndReadBytes(new ByteSourceFileFactory(), testByteArray);
+    }
+    @Test
+    public void testByteSourceInputStreamFileFactory() throws Exception {
+        writeAndReadBytes(new ByteSourceInputStreamFileFactory(), 
testByteArray);
+    }
+    @Test
+    public void testByteSourceInputStreamRawFactory() throws Exception {
+        writeAndReadBytes(new ByteSourceInputStreamRawFactory(), 
testByteArray);
     }
 }

Modified: 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java?rev=1648256&r1=1648255&r2=1648256&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java
 (original)
+++ 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java
 Sun Dec 28 21:40:39 2014
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -40,59 +41,68 @@ import org.apache.commons.imaging.Imagin
 import org.apache.commons.imaging.util.Debug;
 import org.apache.commons.io.FileUtils;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
+@RunWith(Parameterized.class)
 public class ByteSourceImageTest extends ByteSourceTest {
 
+    private File imageFile;
+
+    @Parameterized.Parameters
+    public static Collection<File> data() throws Exception {
+        return getTestImages();
+    }
+
+    public ByteSourceImageTest(File imageFile) {
+        this.imageFile = imageFile;
+    }
+
     @Test
     public void test() throws Exception {
-        final List<File> imageFiles = getTestImages();
-        for (int i = 0; i < imageFiles.size(); i++) {
+        Debug.debug("imageFile", imageFile);
+        assertNotNull(imageFile);
+
+        final byte imageFileBytes[] = FileUtils.readFileToByteArray(imageFile);
+        assertNotNull(imageFileBytes);
+        assertTrue(imageFileBytes.length == imageFile.length());
+
+        if (imageFile.getName().toLowerCase().endsWith(".ico")
+                || imageFile.getName().toLowerCase().endsWith(".tga")
+                || imageFile.getName().toLowerCase().endsWith(".jb2")
+                || imageFile.getName().toLowerCase().endsWith(".pcx")
+                || imageFile.getName().toLowerCase().endsWith(".dcx")
+                || imageFile.getName().toLowerCase().endsWith(".psd")
+                || imageFile.getName().toLowerCase().endsWith(".wbmp")
+                || imageFile.getName().toLowerCase().endsWith(".xbm")
+                || imageFile.getName().toLowerCase().endsWith(".xpm")) {
+            // these formats can't be parsed without a filename hint.
+            // they have ambiguous "magic number" signatures.
+            return;
+        }
+
+        checkGuessFormat(imageFile, imageFileBytes);
+
+        if (imageFile.getName().toLowerCase().endsWith(".png")
+                && imageFile.getParentFile().getName()
+                        .equalsIgnoreCase("pngsuite")
+                && imageFile.getName().toLowerCase().startsWith("x")) {
+            return;
+        }
+
+        checkGetICCProfileBytes(imageFile, imageFileBytes);
+
+        if (!imageFile.getParentFile().getName().toLowerCase()
+                .equals("@broken")) {
+            checkGetImageInfo(imageFile, imageFileBytes);
+        }
+
+        checkGetImageSize(imageFile, imageFileBytes);
 
-            final File imageFile = imageFiles.get(i);
-            Debug.debug("imageFile", imageFile);
-            assertNotNull(imageFile);
-
-            final byte imageFileBytes[] = 
FileUtils.readFileToByteArray(imageFile);
-            assertNotNull(imageFileBytes);
-            assertTrue(imageFileBytes.length == imageFile.length());
-
-            if (imageFile.getName().toLowerCase().endsWith(".ico")
-                    || imageFile.getName().toLowerCase().endsWith(".tga")
-                    || imageFile.getName().toLowerCase().endsWith(".jb2")
-                    || imageFile.getName().toLowerCase().endsWith(".pcx")
-                    || imageFile.getName().toLowerCase().endsWith(".dcx")
-                    || imageFile.getName().toLowerCase().endsWith(".psd")
-                    || imageFile.getName().toLowerCase().endsWith(".wbmp")
-                    || imageFile.getName().toLowerCase().endsWith(".xbm")
-                    || imageFile.getName().toLowerCase().endsWith(".xpm")) {
-                // these formats can't be parsed without a filename hint.
-                // they have ambiguous "magic number" signatures.
-                continue;
-            }
-
-            checkGuessFormat(imageFile, imageFileBytes);
-
-            if (imageFile.getName().toLowerCase().endsWith(".png")
-                    && imageFile.getParentFile().getName()
-                            .equalsIgnoreCase("pngsuite")
-                    && imageFile.getName().toLowerCase().startsWith("x")) {
-                continue;
-            }
-
-            checkGetICCProfileBytes(imageFile, imageFileBytes);
-
-            if (!imageFile.getParentFile().getName().toLowerCase()
-                    .equals("@broken")) {
-                checkGetImageInfo(imageFile, imageFileBytes);
-            }
-
-            checkGetImageSize(imageFile, imageFileBytes);
-
-            final ImageFormat imageFormat = Imaging.guessFormat(imageFile);
-            if (ImageFormats.JPEG != imageFormat
-                    && ImageFormats.UNKNOWN != imageFormat) {
-                checkGetBufferedImage(imageFile, imageFileBytes);
-            }
+        final ImageFormat imageFormat = Imaging.guessFormat(imageFile);
+        if (ImageFormats.JPEG != imageFormat
+                && ImageFormats.UNKNOWN != imageFormat) {
+            checkGetBufferedImage(imageFile, imageFileBytes);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceTest.java?rev=1648256&r1=1648255&r2=1648256&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceTest.java
 (original)
+++ 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceTest.java
 Sun Dec 28 21:40:39 2014
@@ -51,7 +51,7 @@ public abstract class ByteSourceTest ext
         return file;
     }
 
-    protected byte[][] getTestByteArrays() {
+    protected static byte[][] getTestByteArrays() {
         final byte emptyArray[] = (new byte[0]);
 
         final byte single[] = new byte[1];


Reply via email to