1 /*
   2  * Copyright (c) 2012, 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.layout;
  27 
  28 import javafx.geometry.Insets;
  29 import javafx.scene.layout.BackgroundFill;
  30 import javafx.scene.layout.CornerRadii;
  31 import javafx.scene.paint.Color;
  32 import org.junit.Test;
  33 
  34 import static org.junit.Assert.*;
  35 
  36 /**
  37  * Simple tests for BackgroundFill
  38  */
  39 public class BackgroundFillTest {
  40     @Test public void nullPaintDefaultsToTransparent() {
  41         BackgroundFill fill = new BackgroundFill(null, new CornerRadii(3), new Insets(4));
  42         assertEquals(Color.TRANSPARENT, fill.getFill());
  43     }
  44 
  45     @Test public void nullRadiusDefaultsToEmpty() {
  46         BackgroundFill fill = new BackgroundFill(Color.ORANGE, null, new Insets(2));
  47         assertEquals(CornerRadii.EMPTY, fill.getRadii());
  48     }
  49 
  50     @Test public void nullInsetsDefaultsToEmpty() {
  51         BackgroundFill fill = new BackgroundFill(Color.ORANGE, new CornerRadii(2), null);
  52         assertEquals(Insets.EMPTY, fill.getInsets());
  53     }
  54 
  55     @Test public void equivalentFills() {
  56         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  57         BackgroundFill b = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  58         assertEquals(a, b);
  59     }
  60 
  61     @Test public void differentFills() {
  62         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  63         BackgroundFill b = new BackgroundFill(Color.RED, new CornerRadii(2), new Insets(3));
  64         assertFalse(a.equals(b));
  65     }
  66 
  67     @Test public void differentFills2() {
  68         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  69         BackgroundFill b = new BackgroundFill(Color.ORANGE, new CornerRadii(1), new Insets(3));
  70         assertFalse(a.equals(b));
  71     }
  72 
  73     @Test public void differentFills3() {
  74         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  75         BackgroundFill b = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(1));
  76         assertFalse(a.equals(b));
  77     }
  78 
  79     @Test public void equalsAgainstNull() {
  80         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  81         assertFalse(a.equals(null));
  82     }
  83 
  84     @Test public void equalsAgainstRandomObject() {
  85         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  86         assertFalse(a.equals("Some random object"));
  87     }
  88 
  89     @Test public void equivalentHaveSameHash() {
  90         BackgroundFill a = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  91         BackgroundFill b = new BackgroundFill(Color.ORANGE, new CornerRadii(2), new Insets(3));
  92         assertEquals(a.hashCode(), b.hashCode());
  93     }
  94 
  95     @Test public void toStringCausesNoError() {
  96         BackgroundFill f = new BackgroundFill(null, null, null);
  97         f.toString();
  98     }
  99 }