From b1f1f275cf8ad363801827d8d61da3277d069704 Mon Sep 17 00:00:00 2001 From: "joksovic.maja@gmail.com" Date: Sun, 14 Jun 2020 14:15:27 +0200 Subject: [PATCH 1/6] initial commit --- image-processing/pom.xml | 161 ++++++++++-------- .../image/resize/core/Graphics2DExample.java | 25 +++ .../core/ImageScaledInstanceExample.java | 24 +++ .../resize/imagescalr/ImagescalrExample.java | 24 +++ .../image/resize/marvin/MarvinExample.java | 22 +++ .../thumbnailator/ThumbnailatorExample.java | 30 ++++ 6 files changed, 218 insertions(+), 68 deletions(-) create mode 100644 image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java create mode 100644 image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java create mode 100644 image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java create mode 100644 image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java create mode 100644 image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java diff --git a/image-processing/pom.xml b/image-processing/pom.xml index 806cccf351..e2a06e2eed 100644 --- a/image-processing/pom.xml +++ b/image-processing/pom.xml @@ -1,73 +1,98 @@ - - 4.0.0 - image-processing - 1.0-SNAPSHOT - image-processing + + 4.0.0 + image-processing + 1.0-SNAPSHOT + image-processing - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - - net.imagej - ij - ${ij.version} - - - commons-logging - commons-logging - - - - - org.openimaj - core-image - ${core-image.version} - - - commons-logging - commons-logging - - - - - org.openpnp - opencv - 3.4.2-0 - - - com.twelvemonkeys.imageio - imageio-core - ${imageio.version} - - - com.twelvemonkeys.imageio - imageio-bmp - ${imageio.version} - - - net.sourceforge.tess4j - tess4j - ${tess4j.version} - - - org.bytedeco - tesseract-platform - ${tesseract-platform.version} - - - - - 1.3.5 - 1.51h - 3.3.2 - 4.5.1 - 4.1.0-1.5.2 - + + + net.imagej + ij + ${ij.version} + + + commons-logging + commons-logging + + + + + org.openimaj + core-image + ${core-image.version} + + + commons-logging + commons-logging + + + + + org.openpnp + opencv + 3.4.2-0 + + + com.twelvemonkeys.imageio + imageio-core + ${imageio.version} + + + com.twelvemonkeys.imageio + imageio-bmp + ${imageio.version} + + + net.sourceforge.tess4j + tess4j + ${tess4j.version} + + + org.bytedeco + tesseract-platform + ${tesseract-platform.version} + + + org.imgscalr + imgscalr-lib + ${imgscalr-version} + + + net.coobird + thumbnailator + ${thumbnailator-version} + + + com.github.downgoon + marvin + ${marvin-version} + pom + + + com.github.downgoon + MarvinPlugins + ${marvin-version} + + + + + 1.3.5 + 1.51h + 3.3.2 + 4.5.1 + 4.1.0-1.5.2 + 4.2 + 0.4.11 + 1.5.5 + \ No newline at end of file diff --git a/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java b/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java new file mode 100644 index 0000000000..1ae8af8e7a --- /dev/null +++ b/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java @@ -0,0 +1,25 @@ +package com.baeldung.image.resize.core; + +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public class Graphics2DExample { + + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException { + BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); + Graphics2D graphics2D = resizedImage.createGraphics(); + graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null); + graphics2D.dispose(); + return resizedImage; + } + + public static void main(String[] args) throws IOException { + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = resizeImage(originalImage, 200, 200); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + } +} diff --git a/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java b/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java new file mode 100644 index 0000000000..5bc834cc08 --- /dev/null +++ b/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java @@ -0,0 +1,24 @@ +package com.baeldung.image.resize.core; + +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public class ImageScaledInstanceExample { + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException { + Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_DEFAULT); + BufferedImage bufferedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); + bufferedImage.getGraphics() + .drawImage(resultingImage, 0, 0, null); + return bufferedImage; + } + + public static void main(String[] args) throws IOException { + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = resizeImage(originalImage, 200, 200); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + } +} diff --git a/image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java b/image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java new file mode 100644 index 0000000000..f42d109f77 --- /dev/null +++ b/image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java @@ -0,0 +1,24 @@ +package com.baeldung.image.resize.imagescalr; + +import java.awt.image.BufferedImage; +import java.io.File; + +import javax.imageio.ImageIO; + +import org.imgscalr.Scalr; + +public class ImagescalrExample { + static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) throws Exception { + return Scalr.resize(originalImage, targetWidth); + } + + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { + return Scalr.resize(originalImage, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight, Scalr.OP_ANTIALIAS); + } + + public static void main(String[] args) throws Exception { + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = resizeImage(originalImage, 200, 200); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + } +} diff --git a/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java b/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java new file mode 100644 index 0000000000..706949ecc6 --- /dev/null +++ b/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java @@ -0,0 +1,22 @@ +package com.baeldung.image.resize.marvin; + +import org.marvinproject.image.transform.scale.Scale; + +import marvin.image.MarvinImage; +import marvin.io.MarvinImageIO; + +public class MarvinExample { + static void resizeImage(String originalImagePath, int targetWidth, int targetHeight, String outputImagePath) { + MarvinImage image = MarvinImageIO.loadImage(originalImagePath); + Scale scale = new Scale(); + scale.load(); + scale.setAttribute("newWidth", targetWidth); + scale.setAttribute("newHeight", targetHeight); + scale.process(image.clone(), image, null, null, false); + MarvinImageIO.saveImage(image, outputImagePath); + } + + public static void main(String args[]) { + resizeImage("src/main/resources/images/sampleImage.jpg", 200, 200, "src/main/resources/images/sampleImage1.jpg"); + } +} diff --git a/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java b/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java new file mode 100644 index 0000000000..a7defb8259 --- /dev/null +++ b/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java @@ -0,0 +1,30 @@ +package com.baeldung.image.resize.thumbnailator; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; + +import javax.imageio.ImageIO; + +import net.coobird.thumbnailator.Thumbnails; + +public class ThumbnailatorExample { + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Thumbnails.of(originalImage) + .size(targetWidth, targetHeight) + .outputFormat("JPEG") + .outputQuality(0.90) + .toOutputStream(outputStream); + byte[] data = outputStream.toByteArray(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(data); + return ImageIO.read(inputStream); + } + + public static void main(String[] args) throws Exception { + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = resizeImage(originalImage, 200, 200); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + } +} From 4020798958db85d59c3e0144f72467252ee17f2f Mon Sep 17 00:00:00 2001 From: "joksovic.maja@gmail.com" Date: Sun, 14 Jun 2020 14:48:15 +0200 Subject: [PATCH 2/6] fixed xml formatting --- image-processing/pom.xml | 183 +++++++++++++++++++-------------------- 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/image-processing/pom.xml b/image-processing/pom.xml index e2a06e2eed..1df540f229 100644 --- a/image-processing/pom.xml +++ b/image-processing/pom.xml @@ -1,98 +1,97 @@ - 4.0.0 - image-processing - 1.0-SNAPSHOT - image-processing + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + image-processing + 1.0-SNAPSHOT + image-processing - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - - net.imagej - ij - ${ij.version} - - - commons-logging - commons-logging - - - - - org.openimaj - core-image - ${core-image.version} - - - commons-logging - commons-logging - - - - - org.openpnp - opencv - 3.4.2-0 - - - com.twelvemonkeys.imageio - imageio-core - ${imageio.version} - - - com.twelvemonkeys.imageio - imageio-bmp - ${imageio.version} - - - net.sourceforge.tess4j - tess4j - ${tess4j.version} - - - org.bytedeco - tesseract-platform - ${tesseract-platform.version} - - - org.imgscalr - imgscalr-lib - ${imgscalr-version} - - - net.coobird - thumbnailator - ${thumbnailator-version} - - - com.github.downgoon - marvin - ${marvin-version} - pom - - - com.github.downgoon - MarvinPlugins - ${marvin-version} - - - - - 1.3.5 - 1.51h - 3.3.2 - 4.5.1 - 4.1.0-1.5.2 - 4.2 - 0.4.11 - 1.5.5 - + + + net.imagej + ij + ${ij.version} + + + commons-logging + commons-logging + + + + + org.openimaj + core-image + ${core-image.version} + + + commons-logging + commons-logging + + + + + org.openpnp + opencv + 3.4.2-0 + + + com.twelvemonkeys.imageio + imageio-core + ${imageio.version} + + + com.twelvemonkeys.imageio + imageio-bmp + ${imageio.version} + + + net.sourceforge.tess4j + tess4j + ${tess4j.version} + + + org.bytedeco + tesseract-platform + ${tesseract-platform.version} + + + org.imgscalr + imgscalr-lib + ${imgscalr-version} + + + net.coobird + thumbnailator + ${thumbnailator-version} + + + com.github.downgoon + marvin + ${marvin-version} + pom + + + com.github.downgoon + MarvinPlugins + ${marvin-version} + + + + 1.3.5 + 1.51h + 3.3.2 + 4.5.1 + 4.1.0-1.5.2 + 4.2 + 0.4.11 + 1.5.5 + \ No newline at end of file From bc71da5e022ad22fd516cf337f02383f3191c5a3 Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Wed, 17 Jun 2020 22:57:20 +0200 Subject: [PATCH 3/6] Added unit tests and fixed some naming issues. --- .../image/resize/core/Graphics2DExample.java | 2 +- .../core/ImageScaledInstanceExample.java | 2 +- .../ImgscalrExample.java} | 10 +- .../image/resize/marvin/MarvinExample.java | 19 +++- .../thumbnailator/ThumbnailatorExample.java | 2 +- .../resize/core/Graphics2DExampleTest.java | 105 ++++++++++++++++++ .../core/ImageScaledInstanceExampleTest.java | 105 ++++++++++++++++++ .../resize/imgscalr/ImgscalrExampleTest.java | 105 ++++++++++++++++++ .../resize/marvin/MarvinExampleTest.java | 105 ++++++++++++++++++ .../ThumbnailatorExampleTest.java | 105 ++++++++++++++++++ 10 files changed, 546 insertions(+), 14 deletions(-) rename image-processing/src/main/java/com/baeldung/image/resize/{imagescalr/ImagescalrExample.java => imgscalr/ImgscalrExample.java} (63%) create mode 100644 image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java create mode 100644 image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java create mode 100644 image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java create mode 100644 image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java create mode 100644 image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java diff --git a/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java b/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java index 1ae8af8e7a..4be3158089 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java @@ -20,6 +20,6 @@ public class Graphics2DExample { public static void main(String[] args) throws IOException { BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); BufferedImage outputImage = resizeImage(originalImage, 200, 200); - ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage-resized-graphics2d.jpg")); } } diff --git a/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java b/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java index 5bc834cc08..44b71bb1d0 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java @@ -19,6 +19,6 @@ public class ImageScaledInstanceExample { public static void main(String[] args) throws IOException { BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); BufferedImage outputImage = resizeImage(originalImage, 200, 200); - ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage-resized-scaledinstance.jpg")); } } diff --git a/image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java b/image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java similarity index 63% rename from image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java rename to image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java index f42d109f77..dbabbd280c 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/imagescalr/ImagescalrExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java @@ -1,4 +1,4 @@ -package com.baeldung.image.resize.imagescalr; +package com.baeldung.image.resize.imgscalr; import java.awt.image.BufferedImage; import java.io.File; @@ -7,18 +7,18 @@ import javax.imageio.ImageIO; import org.imgscalr.Scalr; -public class ImagescalrExample { - static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) throws Exception { +public class ImgscalrExample { + public static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) throws Exception { return Scalr.resize(originalImage, targetWidth); } - static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { + public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { return Scalr.resize(originalImage, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight, Scalr.OP_ANTIALIAS); } public static void main(String[] args) throws Exception { BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); BufferedImage outputImage = resizeImage(originalImage, 200, 200); - ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage-resized-imgscalr.jpg")); } } diff --git a/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java b/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java index 706949ecc6..6b17012cce 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java @@ -1,22 +1,29 @@ package com.baeldung.image.resize.marvin; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + import org.marvinproject.image.transform.scale.Scale; import marvin.image.MarvinImage; -import marvin.io.MarvinImageIO; public class MarvinExample { - static void resizeImage(String originalImagePath, int targetWidth, int targetHeight, String outputImagePath) { - MarvinImage image = MarvinImageIO.loadImage(originalImagePath); + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) { + MarvinImage image = new MarvinImage(originalImage); Scale scale = new Scale(); scale.load(); scale.setAttribute("newWidth", targetWidth); scale.setAttribute("newHeight", targetHeight); scale.process(image.clone(), image, null, null, false); - MarvinImageIO.saveImage(image, outputImagePath); + return image.getBufferedImage(); } - public static void main(String args[]) { - resizeImage("src/main/resources/images/sampleImage.jpg", 200, 200, "src/main/resources/images/sampleImage1.jpg"); + public static void main(String args[]) throws IOException { + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = resizeImage(originalImage, 200, 200); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage-resized-marvin.jpg")); } } diff --git a/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java b/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java index a7defb8259..f925eace96 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java @@ -25,6 +25,6 @@ public class ThumbnailatorExample { public static void main(String[] args) throws Exception { BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); BufferedImage outputImage = resizeImage(originalImage, 200, 200); - ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg")); + ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage-resized-thumbnailator.jpg")); } } diff --git a/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java new file mode 100644 index 0000000000..2b5c05bdde --- /dev/null +++ b/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java @@ -0,0 +1,105 @@ +package com.baeldung.image.resize.core; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.junit.Test; + +public class Graphics2DExampleTest { + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + BufferedImage outputImage = null; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + try { + outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertNotNull(outputImage); + } + + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + assertNotEquals(originalImage.getWidth(), targetWidth); + assertNotEquals(originalImage.getHeight(), targetHeight); + try { + outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertEquals(outputImage.getWidth(), targetWidth); + assertEquals(outputImage.getHeight(), targetHeight); + } + + @Test + public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 0; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 0; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + try { + outputImage = Graphics2DExample.resizeImage(null, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } +} diff --git a/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java new file mode 100644 index 0000000000..f3ca1e05c0 --- /dev/null +++ b/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java @@ -0,0 +1,105 @@ +package com.baeldung.image.resize.core; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.junit.Test; + +public class ImageScaledInstanceExampleTest { + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + BufferedImage outputImage = null; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + try { + outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertNotNull(outputImage); + } + + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + assertNotEquals(originalImage.getWidth(), targetWidth); + assertNotEquals(originalImage.getHeight(), targetHeight); + try { + outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertEquals(outputImage.getWidth(), targetWidth); + assertEquals(outputImage.getHeight(), targetHeight); + } + + @Test + public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 0; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 0; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + try { + outputImage = ImageScaledInstanceExample.resizeImage(null, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } +} diff --git a/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java new file mode 100644 index 0000000000..0f36bf5429 --- /dev/null +++ b/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java @@ -0,0 +1,105 @@ +package com.baeldung.image.resize.imgscalr; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.junit.Test; + +public class ImgscalrExampleTest { + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + BufferedImage outputImage = null; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + try { + outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertNotNull(outputImage); + } + + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + assertNotEquals(originalImage.getWidth(), targetWidth); + assertNotEquals(originalImage.getHeight(), targetHeight); + try { + outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertEquals(outputImage.getWidth(), targetWidth); + assertEquals(outputImage.getHeight(), targetHeight); + } + + @Test + public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 0; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 0; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + try { + outputImage = ImgscalrExample.resizeImage(null, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } +} diff --git a/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java new file mode 100644 index 0000000000..20d0431f8f --- /dev/null +++ b/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java @@ -0,0 +1,105 @@ +package com.baeldung.image.resize.marvin; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.junit.Test; + +public class MarvinExampleTest { + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + BufferedImage outputImage = null; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + try { + outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertNotNull(outputImage); + } + + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + assertNotEquals(originalImage.getWidth(), targetWidth); + assertNotEquals(originalImage.getHeight(), targetHeight); + try { + outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertEquals(outputImage.getWidth(), targetWidth); + assertEquals(outputImage.getHeight(), targetHeight); + } + + @Test + public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 0; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 0; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + try { + outputImage = MarvinExample.resizeImage(null, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } +} diff --git a/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java new file mode 100644 index 0000000000..bef7ec744d --- /dev/null +++ b/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java @@ -0,0 +1,105 @@ +package com.baeldung.image.resize.thumbnailator; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.junit.Test; + +public class ThumbnailatorExampleTest { + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + BufferedImage outputImage = null; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + try { + outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertNotNull(outputImage); + } + + @Test + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + assertNotEquals(originalImage.getWidth(), targetWidth); + assertNotEquals(originalImage.getHeight(), targetHeight); + try { + outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertFalse(errorThrown); + assertEquals(outputImage.getWidth(), targetWidth); + assertEquals(outputImage.getHeight(), targetHeight); + } + + @Test + public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 0; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 0; + boolean errorThrown = false; + BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); + BufferedImage outputImage = null; + try { + outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } + + @Test + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + int targetWidth = 200; + int targetHeight = 200; + boolean errorThrown = false; + BufferedImage outputImage = null; + try { + outputImage = ThumbnailatorExample.resizeImage(null, targetWidth, targetHeight); + } catch (Exception e) { + errorThrown = true; + } + + assertTrue(errorThrown); + assertNull(outputImage); + } +} From ae071e7d71350646df1154eb267a8f320810abfd Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Thu, 18 Jun 2020 22:52:35 +0200 Subject: [PATCH 4/6] Unit test fixes and improvements --- .../image/resize/core/Graphics2DExample.java | 2 +- .../core/ImageScaledInstanceExample.java | 2 +- .../resize/imgscalr/ImgscalrExample.java | 4 +- .../thumbnailator/ThumbnailatorExample.java | 3 +- .../resize/core/Graphics2DExampleTest.java | 66 +++++------------ .../core/ImageScaledInstanceExampleTest.java | 60 ++++------------ .../resize/imgscalr/ImgscalrExampleTest.java | 70 +++++-------------- .../resize/marvin/MarvinExampleTest.java | 61 ++++------------ .../ThumbnailatorExampleTest.java | 59 +++------------- 9 files changed, 74 insertions(+), 253 deletions(-) diff --git a/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java b/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java index 4be3158089..d52a2dac1b 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/core/Graphics2DExample.java @@ -9,7 +9,7 @@ import javax.imageio.ImageIO; public class Graphics2DExample { - static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException { + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) { BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = resizedImage.createGraphics(); graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null); diff --git a/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java b/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java index 44b71bb1d0..a6e252f3eb 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/core/ImageScaledInstanceExample.java @@ -8,7 +8,7 @@ import java.io.IOException; import javax.imageio.ImageIO; public class ImageScaledInstanceExample { - static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException { + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) { Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_DEFAULT); BufferedImage bufferedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); bufferedImage.getGraphics() diff --git a/image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java b/image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java index dbabbd280c..10d4217de6 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/imgscalr/ImgscalrExample.java @@ -8,11 +8,11 @@ import javax.imageio.ImageIO; import org.imgscalr.Scalr; public class ImgscalrExample { - public static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) throws Exception { + public static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) { return Scalr.resize(originalImage, targetWidth); } - public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { + public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) { return Scalr.resize(originalImage, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight, Scalr.OP_ANTIALIAS); } diff --git a/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java b/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java index f925eace96..2296c1649d 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExample.java @@ -4,13 +4,14 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import javax.imageio.ImageIO; import net.coobird.thumbnailator.Thumbnails; public class ThumbnailatorExample { - static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { + static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Thumbnails.of(originalImage) .size(targetWidth, targetHeight) diff --git a/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java index 2b5c05bdde..7d60f5dde3 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java @@ -1,9 +1,7 @@ package com.baeldung.image.resize.core; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -16,90 +14,58 @@ import javax.imageio.ImageIO; import org.junit.Test; public class Graphics2DExampleTest { - @Test + + @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; int targetHeight = 200; - BufferedImage outputImage = null; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - try { - outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertNotNull(outputImage); } - @Test - public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + @Test(expected = Test.None.class) + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); assertNotEquals(originalImage.getWidth(), targetWidth); assertNotEquals(originalImage.getHeight(), targetHeight); - try { - outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertEquals(outputImage.getWidth(), targetWidth); assertEquals(outputImage.getHeight(), targetHeight); } - @Test + @Test(expected = Exception.class) public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 0; int targetHeight = 200; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test + @Test(expected = Exception.class) public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 200; int targetHeight = 0; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = Graphics2DExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test - public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + @Test(expected = Test.None.class) + public void whenOriginalImageDoesNotExist_thenErrorIsNotThrownAndImageIsGenerated() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; - try { - outputImage = Graphics2DExample.resizeImage(null, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = Graphics2DExample.resizeImage(null, targetWidth, targetHeight); - assertTrue(errorThrown); - assertNull(outputImage); + assertNotNull(outputImage); + assertEquals(outputImage.getWidth(), targetWidth); + assertEquals(outputImage.getHeight(), targetHeight); } } diff --git a/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java index f3ca1e05c0..bab9852bc0 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java @@ -1,9 +1,7 @@ package com.baeldung.image.resize.core; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -16,90 +14,56 @@ import javax.imageio.ImageIO; import org.junit.Test; public class ImageScaledInstanceExampleTest { - @Test + + @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; int targetHeight = 200; - BufferedImage outputImage = null; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - try { - outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertNotNull(outputImage); } - @Test - public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + @Test(expected = Test.None.class) + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); assertNotEquals(originalImage.getWidth(), targetWidth); assertNotEquals(originalImage.getHeight(), targetHeight); - try { - outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertEquals(outputImage.getWidth(), targetWidth); assertEquals(outputImage.getHeight(), targetHeight); } - @Test + @Test(expected = Exception.class) public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 0; int targetHeight = 200; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test + @Test(expected = Exception.class) public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 200; int targetHeight = 0; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImageScaledInstanceExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test + @Test(expected = Exception.class) public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; - try { - outputImage = ImageScaledInstanceExample.resizeImage(null, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImageScaledInstanceExample.resizeImage(null, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } } diff --git a/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java index 0f36bf5429..8c6b152a2e 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java @@ -1,9 +1,7 @@ package com.baeldung.image.resize.imgscalr; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -16,90 +14,56 @@ import javax.imageio.ImageIO; import org.junit.Test; public class ImgscalrExampleTest { - @Test + + @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; int targetHeight = 200; - BufferedImage outputImage = null; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - try { - outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertNotNull(outputImage); } - @Test - public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + @Test(expected = Test.None.class) + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); assertNotEquals(originalImage.getWidth(), targetWidth); assertNotEquals(originalImage.getHeight(), targetHeight); - try { - outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertEquals(outputImage.getWidth(), targetWidth); assertEquals(outputImage.getHeight(), targetHeight); } - @Test - public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { + @Test(expected = Test.None.class) + public void whenTargetWidthIsZero_thenImageIsCreated() throws IOException { int targetWidth = 0; int targetHeight = 200; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); - assertNull(outputImage); + assertNotNull(outputImage); } - @Test - public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { + @Test(expected = Test.None.class) + public void whenTargetHeightIsZero_thenImageIsCreated() throws IOException { int targetWidth = 200; int targetHeight = 0; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImgscalrExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); - assertNull(outputImage); + assertNotNull(outputImage); } - @Test - public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + @Test(expected = Exception.class) + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; - try { - outputImage = ImgscalrExample.resizeImage(null, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ImgscalrExample.resizeImage(null, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } } diff --git a/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java index 20d0431f8f..cbe7e21e8a 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java @@ -1,9 +1,7 @@ package com.baeldung.image.resize.marvin; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -16,90 +14,55 @@ import javax.imageio.ImageIO; import org.junit.Test; public class MarvinExampleTest { - @Test + @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; int targetHeight = 200; - BufferedImage outputImage = null; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - try { - outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertNotNull(outputImage); } - @Test - public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + @Test(expected = Test.None.class) + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); assertNotEquals(originalImage.getWidth(), targetWidth); assertNotEquals(originalImage.getHeight(), targetHeight); - try { - outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertEquals(outputImage.getWidth(), targetWidth); assertEquals(outputImage.getHeight(), targetHeight); } - @Test + @Test(expected = Exception.class) public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 0; int targetHeight = 200; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test + @Test(expected = Exception.class) public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 200; int targetHeight = 0; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = MarvinExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test - public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { + @Test(expected = Exception.class) + public void whenOriginalImageDoesNotExist_thenErrorIsThrown() { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; - try { - outputImage = MarvinExample.resizeImage(null, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = MarvinExample.resizeImage(null, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } } diff --git a/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java index bef7ec744d..e807af317d 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java @@ -1,9 +1,7 @@ package com.baeldung.image.resize.thumbnailator; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -16,90 +14,55 @@ import javax.imageio.ImageIO; import org.junit.Test; public class ThumbnailatorExampleTest { - @Test + @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; int targetHeight = 200; - BufferedImage outputImage = null; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - try { - outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertNotNull(outputImage); } - @Test - public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws Exception { + @Test(expected = Test.None.class) + public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenOutputImageSizeIsValid() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); assertNotEquals(originalImage.getWidth(), targetWidth); assertNotEquals(originalImage.getHeight(), targetHeight); - try { - outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - assertFalse(errorThrown); assertEquals(outputImage.getWidth(), targetWidth); assertEquals(outputImage.getHeight(), targetHeight); } - @Test + @Test(expected = Exception.class) public void whenTargetWidthIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 0; int targetHeight = 200; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test + @Test(expected = Exception.class) public void whenTargetHeightIsZero_thenErrorIsThrown() throws IOException { int targetWidth = 200; int targetHeight = 0; - boolean errorThrown = false; BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg")); - BufferedImage outputImage = null; - try { - outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ThumbnailatorExample.resizeImage(originalImage, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } - @Test + @Test(expected = Exception.class) public void whenOriginalImageDoesNotExist_thenErrorIsThrown() throws IOException { int targetWidth = 200; int targetHeight = 200; - boolean errorThrown = false; - BufferedImage outputImage = null; - try { - outputImage = ThumbnailatorExample.resizeImage(null, targetWidth, targetHeight); - } catch (Exception e) { - errorThrown = true; - } + BufferedImage outputImage = ThumbnailatorExample.resizeImage(null, targetWidth, targetHeight); - assertTrue(errorThrown); assertNull(outputImage); } } From 17199a1a8756a5694ff549eef6bac24ed7f4820f Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Fri, 19 Jun 2020 11:23:46 +0200 Subject: [PATCH 5/6] fixed test names --- ...raphics2DExampleTest.java => Graphics2DExampleUnitTest.java} | 2 +- ...ExampleTest.java => ImageScaledInstanceExampleUnitTest.java} | 2 +- .../{ImgscalrExampleTest.java => ImgscalrExampleUnitTest.java} | 2 +- .../{MarvinExampleTest.java => MarvinExampleUnitTest.java} | 2 +- ...ilatorExampleTest.java => ThumbnailatorExampleUnitTest.java} | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename image-processing/src/test/java/com/baeldung/image/resize/core/{Graphics2DExampleTest.java => Graphics2DExampleUnitTest.java} (98%) rename image-processing/src/test/java/com/baeldung/image/resize/core/{ImageScaledInstanceExampleTest.java => ImageScaledInstanceExampleUnitTest.java} (98%) rename image-processing/src/test/java/com/baeldung/image/resize/imgscalr/{ImgscalrExampleTest.java => ImgscalrExampleUnitTest.java} (98%) rename image-processing/src/test/java/com/baeldung/image/resize/marvin/{MarvinExampleTest.java => MarvinExampleUnitTest.java} (98%) rename image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/{ThumbnailatorExampleTest.java => ThumbnailatorExampleUnitTest.java} (98%) diff --git a/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleUnitTest.java similarity index 98% rename from image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java rename to image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleUnitTest.java index 7d60f5dde3..675a17366d 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/core/Graphics2DExampleUnitTest.java @@ -13,7 +13,7 @@ import javax.imageio.ImageIO; import org.junit.Test; -public class Graphics2DExampleTest { +public class Graphics2DExampleUnitTest { @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { diff --git a/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleUnitTest.java similarity index 98% rename from image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java rename to image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleUnitTest.java index bab9852bc0..b0ac5a7787 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/core/ImageScaledInstanceExampleUnitTest.java @@ -13,7 +13,7 @@ import javax.imageio.ImageIO; import org.junit.Test; -public class ImageScaledInstanceExampleTest { +public class ImageScaledInstanceExampleUnitTest { @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { diff --git a/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleUnitTest.java similarity index 98% rename from image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java rename to image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleUnitTest.java index 8c6b152a2e..e38850da21 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/imgscalr/ImgscalrExampleUnitTest.java @@ -13,7 +13,7 @@ import javax.imageio.ImageIO; import org.junit.Test; -public class ImgscalrExampleTest { +public class ImgscalrExampleUnitTest { @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { diff --git a/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleUnitTest.java similarity index 98% rename from image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java rename to image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleUnitTest.java index cbe7e21e8a..3133a71035 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/marvin/MarvinExampleUnitTest.java @@ -13,7 +13,7 @@ import javax.imageio.ImageIO; import org.junit.Test; -public class MarvinExampleTest { +public class MarvinExampleUnitTest { @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; diff --git a/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java b/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleUnitTest.java similarity index 98% rename from image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java rename to image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleUnitTest.java index e807af317d..383ac1c7af 100644 --- a/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleTest.java +++ b/image-processing/src/test/java/com/baeldung/image/resize/thumbnailator/ThumbnailatorExampleUnitTest.java @@ -13,7 +13,7 @@ import javax.imageio.ImageIO; import org.junit.Test; -public class ThumbnailatorExampleTest { +public class ThumbnailatorExampleUnitTest { @Test(expected = Test.None.class) public void whenOriginalImageExistsAndTargetSizesAreNotZero_thenImageGeneratedWithoutError() throws IOException { int targetWidth = 200; From a53a819bd06184d8ec9111d8ef5f85b62e218efb Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Wed, 1 Jul 2020 12:47:38 +0200 Subject: [PATCH 6/6] using no-alpha buffered image --- .../java/com/baeldung/image/resize/marvin/MarvinExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java b/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java index 6b17012cce..9a7233c4f4 100644 --- a/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java +++ b/image-processing/src/main/java/com/baeldung/image/resize/marvin/MarvinExample.java @@ -18,7 +18,7 @@ public class MarvinExample { scale.setAttribute("newWidth", targetWidth); scale.setAttribute("newHeight", targetHeight); scale.process(image.clone(), image, null, null, false); - return image.getBufferedImage(); + return image.getBufferedImageNoAlpha(); } public static void main(String args[]) throws IOException {