From 081f2efea22d2f73fa991e198803b07279f29df6 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Fri, 14 Oct 2022 18:44:54 +0200 Subject: [PATCH] Update test to pass on JDK 19. --- .../color/KCMSSanitizerStrategyTest.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/KCMSSanitizerStrategyTest.java b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/KCMSSanitizerStrategyTest.java index 3cf80a29..0d6b956d 100644 --- a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/KCMSSanitizerStrategyTest.java +++ b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/KCMSSanitizerStrategyTest.java @@ -32,46 +32,40 @@ package com.twelvemonkeys.imageio.color; import org.junit.Test; -import java.awt.color.ColorSpace; -import java.awt.color.ICC_ColorSpace; -import java.awt.color.ICC_Profile; +import java.awt.color.*; import java.io.IOException; import java.util.Arrays; import static org.junit.Assert.assertArrayEquals; -import static org.mockito.Mockito.*; public class KCMSSanitizerStrategyTest { private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '}; @Test(expected = IllegalArgumentException.class) - public void testFixProfileNullProfile() throws Exception { + public void testFixProfileNullProfile() { new KCMSSanitizerStrategy().fixProfile(null); } @Test - public void testFixProfile() throws Exception { + public void testFixProfile() { new KCMSSanitizerStrategy().fixProfile(((ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB)).getProfile()); } @Test - public void testFixProfileUpdateHeader() throws Exception { - byte[] header = new byte[128]; - header[ICC_Profile.icHdrRenderingIntent + 3] = 1; - ICC_Profile profile = mock(ICC_Profile.class); - when(profile.getData(ICC_Profile.icSigHead)).thenReturn(header); + public void testFixProfileUpdateHeader() throws IOException { + ICC_Profile profile = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")); + + // Mangle the profile slightly... + byte[] header = profile.getData(ICC_Profile.icSigHead); + header[ICC_Profile.icHdrRenderingIntent + 3] = 42; - // Can't test that the values are actually changed, as the LCMS-backed implementation - // of ICC_Profile does not change based on this invocation. new KCMSSanitizerStrategy().fixProfile(profile); - // Verify that the method was invoked - verify(profile).setData(eq(ICC_Profile.icSigHead), any(byte[].class)); + assertArrayEquals(new byte[] {0, 0, 0, ICC_Profile.icPerceptual}, Arrays.copyOfRange(profile.getData(ICC_Profile.icSigHead), ICC_Profile.icHdrRenderingIntent, ICC_Profile.icHdrRenderingIntent + 4)); } @Test public void testFixProfileCorbisRGB() throws IOException { - // TODO: Consider re-writing this using mocks, to avoid dependencies on the CMS implementation ICC_Profile corbisRGB = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/Corbis RGB.icc")); new KCMSSanitizerStrategy().fixProfile(corbisRGB);