You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "kinow (via GitHub)" <gi...@apache.org> on 2023/02/18 08:37:35 UTC

[GitHub] [commons-imaging] kinow commented on a diff in pull request #271: [IMAGING-345] Unit test : make tests in memory instead of writing hundred of tmp files

kinow commented on code in PR #271:
URL: https://github.com/apache/commons-imaging/pull/271#discussion_r1110880287


##########
src/test/java/org/apache/commons/imaging/formats/png/PngWriteForceTrueColorText.java:
##########
@@ -21,21 +21,25 @@
 import org.junit.jupiter.api.Test;
 
 import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.List;
+import java.util.logging.Logger;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class PngWriteForceTrueColorText extends PngBaseTest {
+    private static final Logger LOGGER = Logger.getLogger(PngWriteForceTrueColorText.class.getName());
 
     @Test
     public void test() throws Exception {
         final PngImageParser pngImageParser = new PngImageParser();
         final List<File> images = getPngImages();
         for (final File imageFile : images) {
 
+            byte[] outFile = null;

Review Comment:
   This could be inside the `try` block. I thought it was declared outside for some reason, but apparently it's only used within that block?



##########
src/test/java/org/apache/commons/imaging/formats/png/PngTextTest.java:
##########
@@ -74,8 +76,10 @@ public void test() throws Exception {
             bytes = baos.toByteArray();
         }
 
-        final File tempFile = Files.createTempFile("temp", ".png").toFile();
-        FileUtils.writeByteArrayToFile(tempFile, bytes);
+        if (false) { // activate saving tmp file for troubleshooting
+            final File tempFile = Files.createTempFile("temp", ".png").toFile();
+            FileUtils.writeByteArrayToFile(tempFile, bytes);

Review Comment:
   `LOGGER` no used here.



##########
src/test/java/org/apache/commons/imaging/roundtrip/RoundtripBase.java:
##########
@@ -62,10 +78,18 @@ protected void roundtrip(final FormatInfo formatInfo, final BufferedImage testIm
         }
 
         if (formatInfo.identicalSecondWrite) {
-            final File temp2 = Files.createTempFile(tempPrefix + ".", "." + formatInfo.format.getDefaultExtension()).toFile();
-            try (FileOutputStream fos = new FileOutputStream(temp2)) {
-                imageParser.writeImage(image2, fos, params);
+            if (false) { // activate saving tmp file for troubleshooting
+                final File temp2 = Files.createTempFile(tempPrefix + ".", "." + formatInfo.format.getDefaultExtension()).toFile();
+                try (FileOutputStream fos = new FileOutputStream(temp2)) {
+                    imageParser.writeImage(image2, fos, params);
+                }

Review Comment:
   `LOGGER` not used here.



##########
src/test/java/org/apache/commons/imaging/formats/png/PngWriteForceTrueColorText.java:
##########
@@ -50,13 +54,19 @@ public void test() throws Exception {
                 final BufferedImage image = pngImageParser.getBufferedImage(imageFile, new PngImagingParameters());
                 assertNotNull(image);
 
-                final File outFile = Files.createTempFile(imageFile.getName() + ".", ".png").toFile();
                 // Debug.debug("outFile", outFile);
 
                 final PngImagingParameters params = new PngImagingParameters();
-                params.setForceTrueColor(Boolean.TRUE);
-                try (FileOutputStream fos = new FileOutputStream(outFile)) {
-                    pngImageParser.writeImage(image, fos, params);
+
+                try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+                    params.setForceTrueColor(Boolean.TRUE);
+                    pngImageParser.writeImage(image, os, params);
+                    outFile = os.toByteArray();
+                }
+
+                if (false) { // activate saving tmp file for troubleshooting
+                    final Path tempFile = Files.createTempFile(imageFile.getName() + ".", ".jpg");
+                    Files.write(tempFile, outFile);

Review Comment:
   `LOGGER` not used here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org