2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
20
package org.apache.xmlgraphics.java2d.color;
22
import java.awt.Color;
24
import org.junit.Test;
26
import static org.junit.Assert.assertEquals;
27
import static org.junit.Assert.assertFalse;
28
import static org.junit.Assert.assertTrue;
31
* Tests the {@link ColorWithAlternatives} class.
33
public class ColorWithAlternativesTestCase {
36
public void testEquals() throws Exception {
37
Color col1 = new ColorWithAlternatives(255, 204, 0, null);
38
Color col2 = new Color(255, 204, 0);
40
assertEquals(col1, col2);
41
assertEquals(col2, col1);
43
CIELabColorSpace lab = ColorSpaces.getCIELabColorSpaceD50();
44
Color postgelbLab = lab.toColor(83.25f, 16.45f, 96.89f, 1.0f);
45
col1 = new ColorWithAlternatives(255, 204, 0, new Color[] {postgelbLab});
47
//java.awt.Color tests on the sRGB value only
48
assertEquals(col1, col2);
49
assertEquals(col2, col1);
53
public void testSameColor() throws Exception {
54
Color col1 = new ColorWithAlternatives(255, 204, 0, null);
55
Color col2 = new Color(255, 204, 0);
57
//No alternatives. Only sRGB counts.
58
assertTrue(ColorUtil.isSameColor(col1, col2));
60
CIELabColorSpace lab = ColorSpaces.getCIELabColorSpaceD50();
61
Color postgelbLab = lab.toColor(83.25f, 16.45f, 96.89f, 1.0f);
62
col1 = new ColorWithAlternatives(255, 204, 0, new Color[] {postgelbLab});
64
//Same sRGB value but one color with alternatives:
65
assertFalse(ColorUtil.isSameColor(col1, col2));
67
//Once the spotcolor naked and once as part of a color with alternatives
68
assertFalse(ColorUtil.isSameColor(postgelbLab, col1));
70
//sRGB values is calculated from Lab color and doesn't exactly match the selected fallback
71
assertFalse(postgelbLab.equals(col1));