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.BorderWidths; 29 import org.junit.Test; 30 31 import static org.junit.Assert.*; 32 33 /** 34 * TODO The spec doesn't seem to indicate, but what do we do (if anything) with percentages 35 * above 100%? 36 */ 37 public class BorderWidthsTest { 38 @Test public void instanceCreation() { 39 BorderWidths widths = new BorderWidths(1, 2, 3, 4, false, true, false, true); 40 assertEquals(1, widths.getTop(), 0); 41 assertEquals(2, widths.getRight(), 0); 42 assertEquals(3, widths.getBottom(), 0); 43 assertEquals(4, widths.getLeft(), 0); 44 assertFalse(widths.isTopAsPercentage()); 45 assertTrue(widths.isRightAsPercentage()); 46 assertFalse(widths.isBottomAsPercentage()); 47 assertTrue(widths.isLeftAsPercentage()); 48 } 49 50 @Test public void instanceCreation2() { 51 BorderWidths widths = new BorderWidths(1, 2, 3, 4, true, false, true, false); 52 assertEquals(1, widths.getTop(), 0); 53 assertEquals(2, widths.getRight(), 0); 54 assertEquals(3, widths.getBottom(), 0); 55 assertEquals(4, widths.getLeft(), 0); 56 assertTrue(widths.isTopAsPercentage()); 57 assertFalse(widths.isRightAsPercentage()); 58 assertTrue(widths.isBottomAsPercentage()); 59 assertFalse(widths.isLeftAsPercentage()); 60 } 61 62 @Test public void instanceCreation3() { 63 BorderWidths widths = new BorderWidths(1, 2, 3, 4, true, false, false, true); 64 assertEquals(1, widths.getTop(), 0); 65 assertEquals(2, widths.getRight(), 0); 66 assertEquals(3, widths.getBottom(), 0); 67 assertEquals(4, widths.getLeft(), 0); 68 assertTrue(widths.isTopAsPercentage()); 69 assertFalse(widths.isRightAsPercentage()); 70 assertFalse(widths.isBottomAsPercentage()); 71 assertTrue(widths.isLeftAsPercentage()); 72 } 73 74 @Test public void instanceCreation4() { 75 BorderWidths widths = new BorderWidths(100); 76 assertEquals(100, widths.getTop(), 0); 77 assertEquals(100, widths.getRight(), 0); 78 assertEquals(100, widths.getBottom(), 0); 79 assertEquals(100, widths.getLeft(), 0); 80 assertFalse(widths.isTopAsPercentage()); 81 assertFalse(widths.isRightAsPercentage()); 82 assertFalse(widths.isBottomAsPercentage()); 83 assertFalse(widths.isLeftAsPercentage()); 84 } 85 86 @Test public void instanceCreation5() { 87 BorderWidths widths = new BorderWidths(1, 2, 3, 4); 88 assertEquals(1, widths.getTop(), 0); 89 assertEquals(2, widths.getRight(), 0); 90 assertEquals(3, widths.getBottom(), 0); 91 assertEquals(4, widths.getLeft(), 0); 92 assertFalse(widths.isTopAsPercentage()); 93 assertFalse(widths.isRightAsPercentage()); 94 assertFalse(widths.isBottomAsPercentage()); 95 assertFalse(widths.isLeftAsPercentage()); 96 } 97 98 @Test(expected = IllegalArgumentException.class) 99 public void cannotSpecifyNegativeWidth() { 100 new BorderWidths(-2); 101 } 102 103 @Test(expected = IllegalArgumentException.class) 104 public void cannotSpecifyNegativeTop() { 105 new BorderWidths(-2, 0, 0, 0, false, false, false, false); 106 } 107 108 @Test(expected = IllegalArgumentException.class) 109 public void cannotSpecifyNegativeTop2() { 110 new BorderWidths(-2, 0, 0, 0); 111 } 112 113 @Test(expected = IllegalArgumentException.class) 114 public void cannotSpecifyNegativeRight() { 115 new BorderWidths(0, -2, 0, 0, false, false, false, false); 116 } 117 118 @Test(expected = IllegalArgumentException.class) 119 public void cannotSpecifyNegativeRight2() { 120 new BorderWidths(0, -2, 0, 0); 121 } 122 123 @Test(expected = IllegalArgumentException.class) 124 public void cannotSpecifyNegativeBottom() { 125 new BorderWidths(0, 0, -2, 0, false, false, false, false); 126 } 127 128 @Test(expected = IllegalArgumentException.class) 129 public void cannotSpecifyNegativeBottom2() { 130 new BorderWidths(0, 0, -2, 0); 131 } 132 133 @Test(expected = IllegalArgumentException.class) 134 public void cannotSpecifyNegativeLeft() { 135 new BorderWidths(0, 0, 0, -2, false, false, false, false); 136 } 137 138 @Test(expected = IllegalArgumentException.class) 139 public void cannotSpecifyNegativeLeft2() { 140 new BorderWidths(0, 0, 0, -2); 141 } 142 143 @Test public void equality() { 144 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 145 BorderWidths b = new BorderWidths(1, 2, 3, 4, true, false, false, true); 146 assertEquals(a, b); 147 } 148 149 @Test public void same() { 150 assertEquals(BorderWidths.DEFAULT, BorderWidths.DEFAULT); 151 } 152 153 @Test public void different() { 154 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 155 BorderWidths b = new BorderWidths(2, 2, 3, 4, true, false, false, true); 156 assertFalse(a.equals(b)); 157 } 158 159 @Test public void different2() { 160 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 161 BorderWidths b = new BorderWidths(1, 3, 3, 4, true, false, false, true); 162 assertFalse(a.equals(b)); 163 } 164 165 @Test public void different3() { 166 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 167 BorderWidths b = new BorderWidths(1, 2, 4, 4, true, false, false, true); 168 assertFalse(a.equals(b)); 169 } 170 171 @Test public void different4() { 172 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 173 BorderWidths b = new BorderWidths(1, 2, 3, 5, true, false, false, true); 174 assertFalse(a.equals(b)); 175 } 176 177 @Test public void different5() { 178 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 179 BorderWidths b = new BorderWidths(1, 2, 3, 4, false, false, false, true); 180 assertFalse(a.equals(b)); 181 } 182 183 @Test public void different6() { 184 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 185 BorderWidths b = new BorderWidths(1, 2, 3, 4, true, true, false, true); 186 assertFalse(a.equals(b)); 187 } 188 189 @Test public void different7() { 190 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 191 BorderWidths b = new BorderWidths(1, 2, 3, 4, true, false, true, true); 192 assertFalse(a.equals(b)); 193 } 194 195 @Test public void different8() { 196 BorderWidths a = new BorderWidths(1, 2, 3, 4, true, false, false, true); 197 BorderWidths b = new BorderWidths(1, 2, 3, 4, true, false, false, false); 198 assertFalse(a.equals(b)); 199 } 200 201 @Test public void noEqualToNull() { 202 assertFalse(BorderWidths.DEFAULT.equals(null)); 203 } 204 205 @Test public void noEqualToRandom() { 206 assertFalse(BorderWidths.DEFAULT.equals("Some random value")); 207 } 208 }