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 javafx.scene.layout;
  27 
  28 import org.junit.Ignore;
  29 import org.junit.Test;
  30 
  31 import static org.junit.Assert.*;
  32 
  33 /**
  34  */
  35 public class BackgroundSizeTest {
  36     @Test public void instanceCreation() {
  37         BackgroundSize size = new BackgroundSize(1, 2, true, false, true, false);
  38         assertEquals(1, size.getWidth(), 0);
  39         assertEquals(2, size.getHeight(), 0);
  40         assertTrue(size.isWidthAsPercentage());
  41         assertFalse(size.isHeightAsPercentage());
  42         assertTrue(size.isContain());
  43         assertFalse(size.isCover());
  44     }
  45 
  46     @Test public void instanceCreation2() {
  47         BackgroundSize size = new BackgroundSize(0, Double.MAX_VALUE, false, true, false, true);
  48         assertEquals(0, size.getWidth(), 0);
  49         assertEquals(Double.MAX_VALUE, size.getHeight(), 0);
  50         assertFalse(size.isWidthAsPercentage());
  51         assertTrue(size.isHeightAsPercentage());
  52         assertFalse(size.isContain());
  53         assertTrue(size.isCover());
  54     }
  55 
  56     @Test public void instanceCreation3() {
  57         BackgroundSize size = new BackgroundSize(.5, .5, true, true, false, false);
  58         assertEquals(.5, size.getWidth(), 0);
  59         assertEquals(.5, size.getHeight(), 0);
  60         assertTrue(size.isWidthAsPercentage());
  61         assertTrue(size.isHeightAsPercentage());
  62         assertFalse(size.isContain());
  63         assertFalse(size.isCover());
  64     }
  65 
  66     @Test(expected = IllegalArgumentException.class)
  67     public void negativeWidthThrowsException() {
  68         new BackgroundSize(-.2, 1, true, true, false, false);
  69     }
  70 
  71     @Test(expected = IllegalArgumentException.class)
  72     public void negativeWidthThrowsException2() {
  73         new BackgroundSize(-2, 1, true, true, false, false);
  74     }
  75 
  76     @Ignore("Surprised that MIN_VALUE is not < 0")
  77     @Test(expected = IllegalArgumentException.class)
  78     public void negativeWidthThrowsException3() {
  79         new BackgroundSize(Double.MIN_VALUE, 1, true, true, false, false);
  80     }
  81 
  82     @Ignore("Not handling positive infinity")
  83     @Test(expected = IllegalArgumentException.class)
  84     public void positiveInfinityWidthThrowsException() {
  85         new BackgroundSize(Double.POSITIVE_INFINITY, 1, true, true, false, false);
  86     }
  87 
  88     @Ignore("Not handling negative infinity")
  89     @Test(expected = IllegalArgumentException.class)
  90     public void negativeInfinityWidthThrowsException() {
  91         new BackgroundSize(Double.NEGATIVE_INFINITY, 1, true, true, false, false);
  92     }
  93 
  94     @Ignore("Not handling NaN")
  95     @Test(expected = IllegalArgumentException.class)
  96     public void nanWidthThrowsException() {
  97         new BackgroundSize(Double.NaN, 1, true, true, false, false);
  98     }
  99 
 100     @Test public void negativeZeroWidthIsOK() {
 101         BackgroundSize size = new BackgroundSize(-0, 1, true, true, false, false);
 102         assertEquals(0, size.getWidth(), 0);
 103     }
 104 
 105     @Test public void autoWidthIsOK() {
 106         BackgroundSize size = new BackgroundSize(-1, 1, true, true, false, false);
 107         assertEquals(BackgroundSize.AUTO, size.getWidth(), 0);
 108     }
 109 
 110     @Test(expected = IllegalArgumentException.class)
 111     public void negativeHeightThrowsException() {
 112         new BackgroundSize(1, -.1, true, true, false, false);
 113     }
 114 
 115     @Test(expected = IllegalArgumentException.class)
 116     public void negativeHeightThrowsException2() {
 117         new BackgroundSize(1, -2, true, true, false, false);
 118     }
 119 
 120     @Ignore("Surprised that MIN_VALUE is not < 0")
 121     @Test(expected = IllegalArgumentException.class)
 122     public void negativeHeightThrowsException3() {
 123         new BackgroundSize(1, Double.MIN_VALUE, true, true, false, false);
 124     }
 125 
 126     @Ignore("Not handling positive infinity")
 127     @Test(expected = IllegalArgumentException.class)
 128     public void positiveInfinityHeightThrowsException() {
 129         new BackgroundSize(1, Double.POSITIVE_INFINITY, true, true, false, false);
 130     }
 131 
 132     @Ignore("Not handling negative infinity")
 133     @Test(expected = IllegalArgumentException.class)
 134     public void negativeInfinityHeightThrowsException() {
 135         new BackgroundSize(1, Double.NEGATIVE_INFINITY, true, true, false, false);
 136     }
 137 
 138     @Ignore("Not handling NaN")
 139     @Test(expected = IllegalArgumentException.class)
 140     public void nanHeightThrowsException() {
 141         new BackgroundSize(1, Double.NaN, true, true, false, false);
 142     }
 143 
 144     @Test public void negativeZeroHeightIsOK() {
 145         BackgroundSize size = new BackgroundSize(1, -0, true, true, false, false);
 146         assertEquals(0, size.getHeight(), 0);
 147     }
 148 
 149     @Test public void autoHeightIsOK() {
 150         BackgroundSize size = new BackgroundSize(1, -1, true, true, false, false);
 151         assertEquals(BackgroundSize.AUTO, size.getHeight(), 0);
 152     }
 153 
 154     @Test public void equivalent() {
 155         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, true);
 156         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 157         assertEquals(a, b);
 158     }
 159 
 160     @Test public void equivalent2() {
 161         BackgroundSize a = new BackgroundSize(1, .5, false, true, true, true);
 162         BackgroundSize b = new BackgroundSize(1, .5, false, true, true, true);
 163         assertEquals(a, b);
 164     }
 165 
 166     @Test public void equivalent3() {
 167         BackgroundSize a = new BackgroundSize(1, .5, true, false, true, true);
 168         BackgroundSize b = new BackgroundSize(1, .5, true, false, true, true);
 169         assertEquals(a, b);
 170     }
 171 
 172     @Test public void equivalent4() {
 173         BackgroundSize a = new BackgroundSize(1, .5, true, true, false, true);
 174         BackgroundSize b = new BackgroundSize(1, .5, true, true, false, true);
 175         assertEquals(a, b);
 176     }
 177 
 178     @Test public void equivalent5() {
 179         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, false);
 180         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, false);
 181         assertEquals(a, b);
 182     }
 183 
 184     @Test public void equivalentHaveSameHashCode() {
 185         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, true);
 186         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 187         assertEquals(a.hashCode(), b.hashCode());
 188     }
 189 
 190     @Test public void equivalentHaveSameHashCode2() {
 191         BackgroundSize a = new BackgroundSize(1, .5, false, true, true, true);
 192         BackgroundSize b = new BackgroundSize(1, .5, false, true, true, true);
 193         assertEquals(a.hashCode(), b.hashCode());
 194     }
 195 
 196     @Test public void equivalentHaveSameHashCode3() {
 197         BackgroundSize a = new BackgroundSize(1, .5, true, false, true, true);
 198         BackgroundSize b = new BackgroundSize(1, .5, true, false, true, true);
 199         assertEquals(a.hashCode(), b.hashCode());
 200     }
 201 
 202     @Test public void equivalentHaveSameHashCode4() {
 203         BackgroundSize a = new BackgroundSize(1, .5, true, true, false, true);
 204         BackgroundSize b = new BackgroundSize(1, .5, true, true, false, true);
 205         assertEquals(a.hashCode(), b.hashCode());
 206     }
 207 
 208     @Test public void equivalentHaveSameHashCode5() {
 209         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, false);
 210         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, false);
 211         assertEquals(a.hashCode(), b.hashCode());
 212     }
 213 
 214     @Test public void notEquivalent() {
 215         BackgroundSize a = new BackgroundSize(0, .5, true, true, true, true);
 216         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 217         assertFalse(a.equals(b));
 218     }
 219 
 220     @Test public void notEquivalent2() {
 221         BackgroundSize a = new BackgroundSize(1, 1, true, true, true, true);
 222         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 223         assertFalse(a.equals(b));
 224     }
 225 
 226     @Test public void notEquivalent3() {
 227         BackgroundSize a = new BackgroundSize(1, .5, false, true, true, true);
 228         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 229         assertFalse(a.equals(b));
 230     }
 231 
 232     @Test public void notEquivalent4() {
 233         BackgroundSize a = new BackgroundSize(1, .5, true, false, true, true);
 234         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 235         assertFalse(a.equals(b));
 236     }
 237 
 238     @Test public void notEquivalent5() {
 239         BackgroundSize a = new BackgroundSize(1, .5, true, true, false, true);
 240         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 241         assertFalse(a.equals(b));
 242     }
 243 
 244     @Test public void notEquivalent6() {
 245         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, false);
 246         BackgroundSize b = new BackgroundSize(1, .5, true, true, true, true);
 247         assertFalse(a.equals(b));
 248     }
 249 
 250     @Test public void notEqualToNull() {
 251         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, false);
 252         assertFalse(a.equals(null));
 253     }
 254 
 255     @Test public void notEqualToRandom() {
 256         BackgroundSize a = new BackgroundSize(1, .5, true, true, true, false);
 257         assertFalse(a.equals("Some random object"));
 258     }
 259 }