KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > traits > TraitColorTestCase


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.fop.traits;
21
22 import java.awt.Color JavaDoc;
23
24 import junit.framework.TestCase;
25
26 import org.apache.fop.util.ColorUtil;
27
28 /**
29  * Tests the Trait.Color class.
30  * TODO: This actually tests the ColorUtil class now.
31  */

32 public class TraitColorTestCase extends TestCase {
33
34     /**
35      * Test serialization to String.
36      * @throws Exception if an error occurs
37      */

38     public void testSerialization() throws Exception JavaDoc {
39         Color JavaDoc col = new Color JavaDoc(1.0f, 1.0f, 0.5f, 1.0f);
40         String JavaDoc s = ColorUtil.colorToString(col);
41         
42         //This is what the old color spit out. Now it is 80 due to rounding
43
//assertEquals("#ffff7f", s);
44
assertEquals("#ffff80", s);
45         
46         col = new Color JavaDoc(1.0f, 0.0f, 0.0f, 0.8f);
47         s = ColorUtil.colorToString(col);
48         assertEquals("#ff0000cc", s);
49     }
50     
51     /**
52      * Test deserialization from String.
53      * @throws Exception if an error occurs
54      */

55     public void testDeserialization() throws Exception JavaDoc {
56         Color JavaDoc col = ColorUtil.parseColorString(null, "#ffff7f");
57         assertEquals(255, col.getRed());
58         assertEquals(255, col.getGreen());
59         assertEquals(127, col.getBlue());
60         assertEquals(255, col.getAlpha());
61
62         col = ColorUtil.parseColorString(null, "#ff0000cc");
63         assertEquals(255, col.getRed());
64         assertEquals(0, col.getGreen());
65         assertEquals(0, col.getBlue());
66         assertEquals(204, col.getAlpha());
67     }
68     
69     /**
70      * Test equals().
71      * @throws Exception if an error occurs
72      */

73     public void testEquals() throws Exception JavaDoc {
74         Color JavaDoc col1 = ColorUtil.parseColorString(null, "#ff0000cc");
75         Color JavaDoc col2 = ColorUtil.parseColorString(null, "#ff0000cc");
76         assertEquals(col1, col2);
77     }
78     
79 }
80
Popular Tags