Browse Source

Skip ImageTest if JPEG codec from com/sun/image/codec isn't available in the Java runtime.

OpenJDK even in Java 8 (update 222) doesn't include these codecs. Oracle JDK has it in
Java 8, but not in subsequent Java releases.
master
Jaikiran Pai 5 years ago
parent
commit
3a1ff0d804
2 changed files with 18 additions and 7 deletions
  1. +7
    -6
      src/etc/testcases/taskdefs/optional/image/image.xml
  2. +11
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java

+ 7
- 6
src/etc/testcases/taskdefs/optional/image/image.xml View File

@@ -23,47 +23,48 @@
<target name="setUp">
<mkdir dir="${output}"/>
<property name="src.dir" location="${basedir}/src"/>
<available classname="com.sun.image.codec.jpeg.JPEGCodec" property="jpeg.codec.available"/>
</target>

<target name="main" depends="testSimpleScale">
</target>

<!-- this should produce a single file in the dest dir -->
<target name="testSimpleScale" depends="setUp">
<target name="testSimpleScale" depends="setUp" if="jpeg.codec.available">
<image includes="*.jpg" srcdir="${src.dir}" destdir="${output}" overwrite="no" failonerror="no">
<scale width="300" proportions="width"/>
</image>
</target>

<!-- this should put some text in the log -->
<target name="testEchoToLog" depends="setUp">
<target name="testEchoToLog" depends="setUp" if="jpeg.codec.available">
<image includes="*.jpg" srcdir="${src.dir}" destdir="${output}" overwrite="no" failonerror="no">
<scale width="300" proportions="width"/>
</image>
</target>

<!-- this should produce a single file in the dest dir -->
<target name="testFailOnError" depends="setUp">
<target name="testFailOnError" depends="setUp" if="jpeg.codec.available">
<image includes="*.jpg" srcdir="${src.dir}" destdir="${output}" overwrite="no" failonerror="yes">
<scale width="300" proportions="width"/>
</image>
</target>

<!-- this should produce a single file in the dest dir, overwriting any existing file -->
<target name="testOverwriteTrue" depends="setUp">
<target name="testOverwriteTrue" depends="setUp" if="jpeg.codec.available">
<image includes="*.jpg" srcdir="${src.dir}" destdir="${output}" overwrite="true" failonerror="no">
<scale width="300" proportions="width"/>
</image>
</target>

<!-- this should not overwrite the existing file -->
<target name="testOverwriteFalse" depends="setUp">
<target name="testOverwriteFalse" depends="setUp" if="jpeg.codec.available">
<image includes="*.jpg" srcdir="${src.dir}" destdir="${output}" overwrite="false" failonerror="no">
<scale width="300" proportions="width"/>
</image>
</target>

<target name="testSimpleScaleWithMapper" depends="setUp">
<target name="testSimpleScaleWithMapper" depends="setUp" if="jpeg.codec.available">
<image includes="*.jpg" srcdir="${src.dir}"
destdir="${output}" overwrite="no" failonerror="no">
<scale width="300" proportions="width"/>


+ 11
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java View File

@@ -34,6 +34,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;

/**
@@ -63,14 +64,17 @@ public class ImageTest {
@Test
public void testEchoToLog() {
buildRule.executeTarget("testEchoToLog");
assumeNotNull("JPEG codec is unavailable in classpath",
buildRule.getProject().getProperty("jpeg.codec.available"));
assertThat(buildRule.getLog(), containsString("Processing File"));
}

@Test
public void testSimpleScale() {
buildRule.executeTarget("testSimpleScale");
assumeNotNull("JPEG codec is unavailable in classpath",
buildRule.getProject().getProperty("jpeg.codec.available"));
assertThat(buildRule.getLog(), containsString("Processing File"));

File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
assertTrue("Did not create " + f.getAbsolutePath(), f.exists());
}
@@ -78,6 +82,8 @@ public class ImageTest {
@Test
public void testOverwriteTrue() {
buildRule.executeTarget("testSimpleScale");
assumeNotNull("JPEG codec is unavailable in classpath",
buildRule.getProject().getProperty("jpeg.codec.available"));
assertThat(buildRule.getLog(), containsString("Processing File"));
File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
assumeTrue("Could not change file modification date",
@@ -93,6 +99,8 @@ public class ImageTest {
@Test
public void testOverwriteFalse() {
buildRule.executeTarget("testSimpleScale");
assumeNotNull("JPEG codec is unavailable in classpath",
buildRule.getProject().getProperty("jpeg.codec.available"));
assertThat(buildRule.getLog(), containsString("Processing File"));
File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
long lastModified = f.lastModified();
@@ -106,6 +114,8 @@ public class ImageTest {
@Test
public void testSimpleScaleWithMapper() {
buildRule.executeTarget("testSimpleScaleWithMapper");
assumeNotNull("JPEG codec is unavailable in classpath",
buildRule.getProject().getProperty("jpeg.codec.available"));
assertThat(buildRule.getLog(), containsString("Processing File"));
File f = new File(buildRule.getOutputDir(), "scaled-" + LARGEIMAGE);
assertTrue("Did not create " + f.getAbsolutePath(), f.exists());


Loading…
Cancel
Save