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