1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene.paint;
  27 
  28 import javafx.scene.paint.Color;
  29 import javafx.scene.paint.Stop;
  30 import static org.junit.Assert.assertEquals;
  31 import static org.junit.Assert.assertFalse;
  32 import static org.junit.Assert.assertNotNull;
  33 import static org.junit.Assert.assertTrue;
  34 
  35 import org.junit.Test;
  36 
  37 public class StopTest {
  38 
  39     @Test
  40     public void testStop() {
  41         Color color = Color.rgb(0xAA, 0xBB, 0xCC);
  42         Stop stop = new Stop(0.5f, color);
  43 
  44         assertEquals(color.getRed(), stop.getColor().getRed(), 0.0001);
  45         assertEquals(color.getGreen(), stop.getColor().getGreen(), 0.0001);
  46         assertEquals(color.getBlue(), stop.getColor().getBlue(), 0.0001);
  47         assertEquals(0.5f, stop.getOffset(), 0.0001);
  48     }
  49 
  50     @Test
  51     public void testEquals() {
  52         Color color1 = Color.rgb(0xAA, 0xBB, 0xCC);
  53         Color color2 = Color.rgb(0, 0, 0);
  54 
  55         Stop basic = new Stop(0.2f, color1);
  56         Stop equal = new Stop(0.2f, color1);
  57         Stop diffColor = new Stop(0.2f, color2);
  58         Stop diffOffset = new Stop(0.4f, color1);
  59         Stop nullColor = new Stop(0.2f, null);
  60         Stop nullColor2 = new Stop(0.2f, null);
  61 
  62         assertFalse(basic.equals(null));
  63         assertFalse(basic.equals(new Object()));
  64         assertTrue(basic.equals(basic));
  65         assertTrue(basic.equals(equal));
  66         assertFalse(basic.equals(diffColor));
  67         assertFalse(basic.equals(diffOffset));
  68         assertTrue(nullColor.equals(nullColor2));
  69         assertFalse(nullColor.equals(basic));
  70     }
  71 
  72     @Test
  73     public void testHashCode() {
  74         Color color1 = Color.rgb(0xAA, 0xBB, 0xCC);
  75         Color color2 = Color.rgb(0xAA, 0xBB, 0xCC);
  76         Color color3 = Color.rgb(0, 0, 0);
  77 
  78         Stop basic = new Stop(0.2f, color1);
  79         Stop equal = new Stop(0.2f, color2);
  80         Stop different1 = new Stop(0.4f, color1);
  81         Stop different2 = new Stop(0.2f, color3);
  82 
  83         int code = basic.hashCode();
  84         int second = basic.hashCode();
  85         assertTrue(code == second);
  86         assertTrue(code == equal.hashCode());
  87         assertFalse(code == different1.hashCode());
  88         assertFalse(code == different2.hashCode());
  89     }
  90 
  91     @Test
  92     public void testToString() {
  93         Stop empty = new Stop(0, Color.TRANSPARENT);
  94         Stop nonempty = new Stop(0.5f, Color.rgb(0xAA, 0xBB, 0xCC, 0.5f));
  95 
  96         String s = empty.toString();
  97         assertNotNull(s);
  98         assertFalse(s.isEmpty());
  99 
 100         s = nonempty.toString();
 101         assertNotNull(s);
 102         assertFalse(s.isEmpty());
 103     }
 104 }