~hjd/ubuntu/wily/xmlgraphics-commons/debian-merged

« back to all changes in this revision

Viewing changes to test/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternativesTestCase.java

  • Committer: Hans Joachim Desserud
  • Date: 2015-11-11 18:22:53 UTC
  • mfrom: (9.1.5 sid)
  • Revision ID: hans_joachim_desserud-20151111182253-zwi0frfm97j0wddn
  * Merge from Debian unstable.  Remaining changes:
    - d/control: Drop dependencies required for unit testing as they
      include libmockito-java which would pull maven into main, disable unit
      test execution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
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.
 
16
 */
 
17
 
 
18
/* $Id$ */
 
19
 
 
20
package org.apache.xmlgraphics.java2d.color;
 
21
 
 
22
import java.awt.Color;
 
23
 
 
24
import org.junit.Test;
 
25
 
 
26
import static org.junit.Assert.assertEquals;
 
27
import static org.junit.Assert.assertFalse;
 
28
import static org.junit.Assert.assertTrue;
 
29
 
 
30
/**
 
31
 * Tests the {@link ColorWithAlternatives} class.
 
32
 */
 
33
public class ColorWithAlternativesTestCase {
 
34
 
 
35
    @Test
 
36
    public void testEquals() throws Exception {
 
37
        Color col1 = new ColorWithAlternatives(255, 204, 0, null);
 
38
        Color col2 = new Color(255, 204, 0);
 
39
 
 
40
        assertEquals(col1, col2);
 
41
        assertEquals(col2, col1);
 
42
 
 
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});
 
46
 
 
47
        //java.awt.Color tests on the sRGB value only
 
48
        assertEquals(col1, col2);
 
49
        assertEquals(col2, col1);
 
50
    }
 
51
 
 
52
    @Test
 
53
    public void testSameColor() throws Exception {
 
54
        Color col1 = new ColorWithAlternatives(255, 204, 0, null);
 
55
        Color col2 = new Color(255, 204, 0);
 
56
 
 
57
        //No alternatives. Only sRGB counts.
 
58
        assertTrue(ColorUtil.isSameColor(col1, col2));
 
59
 
 
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});
 
63
 
 
64
        //Same sRGB value but one color with alternatives:
 
65
        assertFalse(ColorUtil.isSameColor(col1, col2));
 
66
 
 
67
        //Once the spotcolor naked and once as part of a color with alternatives
 
68
        assertFalse(ColorUtil.isSameColor(postgelbLab, col1));
 
69
 
 
70
        //sRGB values is calculated from Lab color and doesn't exactly match the selected fallback
 
71
        assertFalse(postgelbLab.equals(col1));
 
72
    }
 
73
}