From 23c821937f09dcb2a8dd9f55d1c40abd4824e0a7 Mon Sep 17 00:00:00 2001 From: Marcel Raddatz Date: Fri, 10 Apr 2026 09:38:01 +0200 Subject: [PATCH] test(recipes): add JPEG input test for ImageCompressor Confirms the compressor accepts JPEG data URIs as input (not just PNG). Co-Authored-By: Claude Sonnet 4.6 --- .../recipeapp/recipe/ImageCompressorTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java b/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java index 8d2c7c5..c9f1522 100644 --- a/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java +++ b/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java @@ -80,6 +80,17 @@ class ImageCompressorTest { assertThat(compressor.compressToPreview("data:image/jpeg;base64,!!!not-valid!!!")).isNull(); } + @Test + void compressToPreview_acceptsJpegInput() throws Exception { + String dataUri = makeJpegDataUri(800, 600); + String result = compressor.compressToPreview(dataUri); + assertThat(result).startsWith("data:image/jpeg;base64,"); + String base64 = result.substring("data:image/jpeg;base64,".length()); + BufferedImage img = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(base64))); + assertThat(img).isNotNull(); + assertThat(img.getWidth()).isLessThanOrEqualTo(400); + } + // ── helpers ── private String makePngDataUri(int width, int height) throws Exception { @@ -95,4 +106,15 @@ class ImageCompressorTest { ImageIO.write(img, "png", bos); return "data:image/png;base64," + Base64.getEncoder().encodeToString(bos.toByteArray()); } + + private String makeJpegDataUri(int width, int height) throws Exception { + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + java.awt.Graphics2D g = img.createGraphics(); + g.setColor(java.awt.Color.ORANGE); + g.fillRect(0, 0, width, height); + g.dispose(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ImageIO.write(img, "jpeg", bos); + return "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(bos.toByteArray()); + } }