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 javafx.geometry.Side; 29 import org.junit.Test; 30 31 import static org.junit.Assert.*; 32 33 /** 34 */ 35 public class BackgroundPositionTest { 36 @Test public void valuesAreCorrectAfterConstruction() { 37 BackgroundPosition pos = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 38 39 assertEquals(Side.LEFT, pos.getHorizontalSide()); 40 assertEquals(10, pos.getHorizontalPosition(), 0); 41 assertEquals(false, pos.isHorizontalAsPercentage()); 42 assertEquals(Side.TOP, pos.getVerticalSide()); 43 assertEquals(20, pos.getVerticalPosition(), 0); 44 assertEquals(false, pos.isVerticalAsPercentage()); 45 } 46 47 @Test public void valuesAreCorrectAfterConstruction2() { 48 BackgroundPosition pos = new BackgroundPosition(Side.RIGHT, 10, true, Side.BOTTOM, 20, true); 49 50 assertEquals(Side.RIGHT, pos.getHorizontalSide()); 51 assertEquals(10, pos.getHorizontalPosition(), 0); 52 assertEquals(true, pos.isHorizontalAsPercentage()); 53 assertEquals(Side.BOTTOM, pos.getVerticalSide()); 54 assertEquals(20, pos.getVerticalPosition(), 0); 55 assertEquals(true, pos.isVerticalAsPercentage()); 56 } 57 58 @Test public void nullHorizontalSideEqualsLEFT() { 59 BackgroundPosition pos = new BackgroundPosition(null, 10, true, Side.BOTTOM, 20, true); 60 assertEquals(Side.LEFT, pos.getHorizontalSide()); 61 } 62 63 @Test(expected = IllegalArgumentException.class) 64 public void TOPHorizontalSideFails() { 65 new BackgroundPosition(Side.TOP, 10, true, Side.BOTTOM, 20, true); 66 } 67 68 @Test(expected = IllegalArgumentException.class) 69 public void BOTTOMHorizontalSideFails() { 70 new BackgroundPosition(Side.BOTTOM, 10, true, Side.BOTTOM, 20, true); 71 } 72 73 @Test public void negativeHorizontalPositionOK() { 74 BackgroundPosition pos = new BackgroundPosition(null, -10, true, Side.BOTTOM, 20, true); 75 assertEquals(-10, pos.getHorizontalPosition(), 0); 76 } 77 78 @Test public void nullVerticalSideEqualsTOP() { 79 BackgroundPosition pos = new BackgroundPosition(Side.LEFT, 10, true, null, 20, true); 80 assertEquals(Side.TOP, pos.getVerticalSide()); 81 } 82 83 @Test(expected = IllegalArgumentException.class) 84 public void LEFTVerticalSideFails() { 85 new BackgroundPosition(Side.LEFT, 10, true, Side.LEFT, 20, true); 86 } 87 88 @Test(expected = IllegalArgumentException.class) 89 public void RIGHTVerticalSideFails() { 90 new BackgroundPosition(Side.LEFT, 10, true, Side.RIGHT, 20, true); 91 } 92 93 @Test public void negativeVerticalPositionOK() { 94 BackgroundPosition pos = new BackgroundPosition(Side.LEFT, 10, true, Side.BOTTOM, -20, true); 95 assertEquals(-20, pos.getVerticalPosition(), 0); 96 } 97 98 @Test public void equivalence() { 99 BackgroundPosition pos = new BackgroundPosition(Side.LEFT, 0, true, Side.TOP, 0, true); 100 assertEquals(BackgroundPosition.DEFAULT, pos); 101 } 102 103 @Test public void equivalence2() { 104 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 105 BackgroundPosition b = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 106 assertEquals(a, b); 107 } 108 109 @Test public void unequal() { 110 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 111 BackgroundPosition b = new BackgroundPosition(Side.RIGHT, 10, false, Side.TOP, 20, false); 112 assertFalse(a.equals(b)); 113 } 114 115 @Test public void unequal2() { 116 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 117 BackgroundPosition b = new BackgroundPosition(Side.LEFT, 0, false, Side.TOP, 20, false); 118 assertFalse(a.equals(b)); 119 } 120 121 @Test public void unequal3() { 122 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 123 BackgroundPosition b = new BackgroundPosition(Side.LEFT, 10, true, Side.TOP, 20, false); 124 assertFalse(a.equals(b)); 125 } 126 127 @Test public void unequal4() { 128 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 129 BackgroundPosition b = new BackgroundPosition(Side.LEFT, 10, false, Side.BOTTOM, 20, false); 130 assertFalse(a.equals(b)); 131 } 132 133 @Test public void unequal5() { 134 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 135 BackgroundPosition b = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 0, false); 136 assertFalse(a.equals(b)); 137 } 138 139 @Test public void unequal6() { 140 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 141 BackgroundPosition b = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, true); 142 assertFalse(a.equals(b)); 143 } 144 145 @Test public void notEqualWithNull() { 146 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 147 assertFalse(a.equals(null)); 148 } 149 150 @Test public void notEqualWithRandom() { 151 BackgroundPosition a = new BackgroundPosition(Side.LEFT, 10, false, Side.TOP, 20, false); 152 assertFalse(a.equals("Random Object")); 153 } 154 155 @Test public void equalPositionsHaveSameHashCode() { 156 BackgroundPosition pos = new BackgroundPosition(Side.LEFT, 0, true, Side.TOP, 0, true); 157 assertEquals(BackgroundPosition.DEFAULT.hashCode(), pos.hashCode()); 158 } 159 160 @Test public void CENTER() { 161 assertEquals(Side.LEFT, BackgroundPosition.CENTER.getHorizontalSide()); 162 assertEquals(.5, BackgroundPosition.CENTER.getHorizontalPosition(), 0); 163 assertTrue(BackgroundPosition.CENTER.isHorizontalAsPercentage()); 164 assertEquals(Side.TOP, BackgroundPosition.CENTER.getVerticalSide()); 165 assertEquals(.5, BackgroundPosition.CENTER.getVerticalPosition(), 0); 166 assertTrue(BackgroundPosition.CENTER.isVerticalAsPercentage()); 167 } 168 }