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 java.util.ArrayList; 29 import java.util.List; 30 import javafx.scene.shape.StrokeLineCap; 31 import javafx.scene.shape.StrokeLineJoin; 32 import javafx.scene.shape.StrokeType; 33 import org.junit.Test; 34 35 import static org.junit.Assert.*; 36 37 /** 38 */ 39 public class BorderStrokeStyleTest { 40 @Test public void instanceCreation() { 41 BorderStrokeStyle style = new BorderStrokeStyle(null, null, null, 1, 2, null); 42 assertEquals(StrokeType.CENTERED, style.getType()); 43 assertEquals(StrokeLineJoin.MITER, style.getLineJoin()); 44 assertEquals(StrokeLineCap.BUTT, style.getLineCap()); 45 assertEquals(1, style.getMiterLimit(), 0); 46 assertEquals(2, style.getDashOffset(), 0); 47 assertEquals(0, style.getDashArray().size()); 48 } 49 50 @Test public void instanceCreation2() { 51 List<Double> dashArray = new ArrayList<Double>(); 52 dashArray.add(1.0); 53 dashArray.add(4.0); 54 BorderStrokeStyle style = new BorderStrokeStyle(StrokeType.OUTSIDE, StrokeLineJoin.BEVEL, StrokeLineCap.SQUARE, 55 10, 0, dashArray); 56 assertEquals(StrokeType.OUTSIDE, style.getType()); 57 assertEquals(StrokeLineJoin.BEVEL, style.getLineJoin()); 58 assertEquals(StrokeLineCap.SQUARE, style.getLineCap()); 59 assertEquals(10, style.getMiterLimit(), 0); 60 assertEquals(0, style.getDashOffset(), 0); 61 assertEquals(2, style.getDashArray().size()); 62 assertEquals(1.0, style.getDashArray().get(0), 0); 63 assertEquals(4.0, style.getDashArray().get(1), 0); 64 } 65 66 @Test(expected = UnsupportedOperationException.class) 67 public void dashArrayIsImmutable() { 68 BorderStrokeStyle style = new BorderStrokeStyle(null, null, null, 10, 2, null); 69 style.getDashArray().add(1.0); 70 } 71 72 @Test public void changesToDashArrayPassedToConstructorHaveNoEffect() { 73 List<Double> dashArray = new ArrayList<Double>(); 74 BorderStrokeStyle style = new BorderStrokeStyle(null, null, null, 1, 2, dashArray); 75 dashArray.add(4.0); 76 assertEquals(0, style.getDashArray().size()); 77 } 78 79 @Test public void identity() { 80 BorderStrokeStyle style = new BorderStrokeStyle(null, null, null, 10, 2, null); 81 assertEquals(style, style); 82 assertEquals(style.hashCode(), style.hashCode()); 83 } 84 85 @Test public void equality() { 86 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 2, null); 87 BorderStrokeStyle b = new BorderStrokeStyle(null, null, null, 10, 2, null); 88 assertEquals(a, b); 89 assertEquals(a.hashCode(), b.hashCode()); 90 } 91 92 @Test public void equality2() { 93 BorderStrokeStyle a = new BorderStrokeStyle(StrokeType.OUTSIDE, null, null, 10, 2, null); 94 BorderStrokeStyle b = new BorderStrokeStyle(StrokeType.OUTSIDE, null, null, 10, 2, null); 95 assertEquals(a, b); 96 assertEquals(a.hashCode(), b.hashCode()); 97 } 98 99 @Test public void equality3() { 100 BorderStrokeStyle a = new BorderStrokeStyle(null, StrokeLineJoin.ROUND, null, 10, 2, null); 101 BorderStrokeStyle b = new BorderStrokeStyle(null, StrokeLineJoin.ROUND, null, 10, 2, null); 102 assertEquals(a, b); 103 assertEquals(a.hashCode(), b.hashCode()); 104 } 105 106 @Test public void equality4() { 107 BorderStrokeStyle a = new BorderStrokeStyle(null, null, StrokeLineCap.ROUND, 10, 2, null); 108 BorderStrokeStyle b = new BorderStrokeStyle(null, null, StrokeLineCap.ROUND, 10, 2, null); 109 assertEquals(a, b); 110 assertEquals(a.hashCode(), b.hashCode()); 111 } 112 113 @Test public void equality5() { 114 List<Double> dashArray1 = new ArrayList<Double>(); 115 dashArray1.add(1.0); 116 dashArray1.add(4.0); 117 118 List<Double> dashArray2 = new ArrayList<Double>(); 119 dashArray2.add(1.0); 120 dashArray2.add(4.0); 121 122 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 2, dashArray1); 123 BorderStrokeStyle b = new BorderStrokeStyle(null, null, null, 10, 2, dashArray2); 124 assertEquals(a, b); 125 assertEquals(a.hashCode(), b.hashCode()); 126 } 127 128 @Test public void notEqual() { 129 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 130 BorderStrokeStyle b = new BorderStrokeStyle(StrokeType.OUTSIDE, null, null, 10, 0, null); 131 assertFalse(a.equals(b)); 132 } 133 134 @Test public void notEqual2() { 135 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 136 BorderStrokeStyle b = new BorderStrokeStyle(null, StrokeLineJoin.ROUND, null, 10, 0, null); 137 assertFalse(a.equals(b)); 138 } 139 140 @Test public void notEqual3() { 141 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 142 BorderStrokeStyle b = new BorderStrokeStyle(null, null, StrokeLineCap.ROUND, 10, 0, null); 143 assertFalse(a.equals(b)); 144 } 145 146 @Test public void notEqual4() { 147 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 148 BorderStrokeStyle b = new BorderStrokeStyle(null, null, null, 20, 0, null); 149 assertFalse(a.equals(b)); 150 } 151 152 @Test public void notEqual5() { 153 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 154 BorderStrokeStyle b = new BorderStrokeStyle(null, null, null, 10, 1, null); 155 assertFalse(a.equals(b)); 156 } 157 158 @Test public void notEqual6() { 159 List<Double> dashArray1 = new ArrayList<Double>(); 160 dashArray1.add(1.0); 161 dashArray1.add(4.0); 162 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 163 BorderStrokeStyle b = new BorderStrokeStyle(null, null, null, 10, 0, dashArray1); 164 assertFalse(a.equals(b)); 165 } 166 167 @Test public void notEqualWithNull() { 168 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 169 assertFalse(a.equals(null)); 170 } 171 172 @Test public void notEqualWithRandom() { 173 BorderStrokeStyle a = new BorderStrokeStyle(null, null, null, 10, 0, null); 174 assertFalse(a.equals("Some random string")); 175 } 176 }