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 <noreply@anthropic.com>
This commit is contained in:
2026-04-10 09:38:01 +02:00
parent 9df6d6f0c6
commit 23c821937f

View File

@@ -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());
}
}