Update test to pass on JDK 19.

This commit is contained in:
Harald Kuhr 2022-10-14 18:44:54 +02:00
parent 627bb1bf1f
commit 081f2efea2

View File

@ -32,46 +32,40 @@ package com.twelvemonkeys.imageio.color;
import org.junit.Test; import org.junit.Test;
import java.awt.color.ColorSpace; import java.awt.color.*;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Mockito.*;
public class KCMSSanitizerStrategyTest { public class KCMSSanitizerStrategyTest {
private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '}; private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '};
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testFixProfileNullProfile() throws Exception { public void testFixProfileNullProfile() {
new KCMSSanitizerStrategy().fixProfile(null); new KCMSSanitizerStrategy().fixProfile(null);
} }
@Test @Test
public void testFixProfile() throws Exception { public void testFixProfile() {
new KCMSSanitizerStrategy().fixProfile(((ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB)).getProfile()); new KCMSSanitizerStrategy().fixProfile(((ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB)).getProfile());
} }
@Test @Test
public void testFixProfileUpdateHeader() throws Exception { public void testFixProfileUpdateHeader() throws IOException {
byte[] header = new byte[128]; ICC_Profile profile = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc"));
header[ICC_Profile.icHdrRenderingIntent + 3] = 1;
ICC_Profile profile = mock(ICC_Profile.class); // Mangle the profile slightly...
when(profile.getData(ICC_Profile.icSigHead)).thenReturn(header); 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); new KCMSSanitizerStrategy().fixProfile(profile);
// Verify that the method was invoked assertArrayEquals(new byte[] {0, 0, 0, ICC_Profile.icPerceptual}, Arrays.copyOfRange(profile.getData(ICC_Profile.icSigHead), ICC_Profile.icHdrRenderingIntent, ICC_Profile.icHdrRenderingIntent + 4));
verify(profile).setData(eq(ICC_Profile.icSigHead), any(byte[].class));
} }
@Test @Test
public void testFixProfileCorbisRGB() throws IOException { 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")); ICC_Profile corbisRGB = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/Corbis RGB.icc"));
new KCMSSanitizerStrategy().fixProfile(corbisRGB); new KCMSSanitizerStrategy().fixProfile(corbisRGB);