1 /* 2 * Copyright (c) 2011, 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; 27 28 import com.sun.javafx.pgstub.StubImageLoaderFactory; 29 import com.sun.javafx.pgstub.StubPlatformImageInfo; 30 import com.sun.javafx.pgstub.StubToolkit; 31 import com.sun.javafx.tk.Toolkit; 32 import javafx.scene.image.Image; 33 34 import static org.junit.Assert.assertEquals; 35 import static org.junit.Assert.assertTrue; 36 37 import org.junit.Test; 38 39 40 public class CursorTest { 41 42 @Test public void test_cursorFromUppercaseName() { 43 assertEquals(Cursor.DEFAULT, Cursor.cursor("DEFAULT")); 44 assertEquals(Cursor.CLOSED_HAND, Cursor.cursor("CLOSED_HAND")); 45 assertEquals(Cursor.CROSSHAIR, Cursor.cursor("CROSSHAIR")); 46 assertEquals(Cursor.DISAPPEAR, Cursor.cursor("DISAPPEAR")); 47 assertEquals(Cursor.E_RESIZE, Cursor.cursor("E_RESIZE")); 48 assertEquals(Cursor.MOVE, Cursor.cursor("MOVE")); 49 assertEquals(Cursor.NE_RESIZE, Cursor.cursor("NE_RESIZE")); 50 assertEquals(Cursor.NONE, Cursor.cursor("NONE")); 51 assertEquals(Cursor.NW_RESIZE, Cursor.cursor("NW_RESIZE")); 52 assertEquals(Cursor.N_RESIZE, Cursor.cursor("N_RESIZE")); 53 assertEquals(Cursor.OPEN_HAND, Cursor.cursor("OPEN_HAND")); 54 assertEquals(Cursor.SE_RESIZE, Cursor.cursor("SE_RESIZE")); 55 assertEquals(Cursor.SW_RESIZE, Cursor.cursor("SW_RESIZE")); 56 assertEquals(Cursor.S_RESIZE, Cursor.cursor("S_RESIZE")); 57 assertEquals(Cursor.TEXT, Cursor.cursor("TEXT")); 58 assertEquals(Cursor.V_RESIZE, Cursor.cursor("V_RESIZE")); 59 assertEquals(Cursor.WAIT, Cursor.cursor("WAIT")); 60 assertEquals(Cursor.W_RESIZE, Cursor.cursor("W_RESIZE")); 61 } 62 63 @Test public void test_cursorFromLowercaseName() { 64 assertEquals(Cursor.DEFAULT, Cursor.cursor("default")); 65 assertEquals(Cursor.CLOSED_HAND, Cursor.cursor("closed_hand")); 66 assertEquals(Cursor.CROSSHAIR, Cursor.cursor("crosshair")); 67 assertEquals(Cursor.DISAPPEAR, Cursor.cursor("disappear")); 68 assertEquals(Cursor.E_RESIZE, Cursor.cursor("e_resize")); 69 assertEquals(Cursor.MOVE, Cursor.cursor("move")); 70 assertEquals(Cursor.NE_RESIZE, Cursor.cursor("ne_resize")); 71 assertEquals(Cursor.NONE, Cursor.cursor("none")); 72 assertEquals(Cursor.NW_RESIZE, Cursor.cursor("nw_resize")); 73 assertEquals(Cursor.N_RESIZE, Cursor.cursor("n_resize")); 74 assertEquals(Cursor.OPEN_HAND, Cursor.cursor("open_hand")); 75 assertEquals(Cursor.SE_RESIZE, Cursor.cursor("se_resize")); 76 assertEquals(Cursor.SW_RESIZE, Cursor.cursor("sw_resize")); 77 assertEquals(Cursor.S_RESIZE, Cursor.cursor("s_resize")); 78 assertEquals(Cursor.TEXT, Cursor.cursor("text")); 79 assertEquals(Cursor.V_RESIZE, Cursor.cursor("v_resize")); 80 assertEquals(Cursor.WAIT, Cursor.cursor("wait")); 81 assertEquals(Cursor.W_RESIZE, Cursor.cursor("w_resize")); 82 } 83 84 @Test public void test_cursorFromUrl() { 85 final StubImageLoaderFactory imageLoaderFactory = 86 ((StubToolkit) Toolkit.getToolkit()).getImageLoaderFactory(); 87 88 final String imageUrl = "file:cursor.png"; 89 imageLoaderFactory.registerImage( 90 imageUrl, new StubPlatformImageInfo(100, 100)); 91 92 final Cursor cursor = Cursor.cursor(imageUrl); 93 assertTrue(cursor instanceof ImageCursor); 94 95 final Image cursorImage = ((ImageCursor) cursor).getImage(); 96 assertEquals(imageUrl, cursorImage.impl_getUrl()); 97 } 98 99 @Test(expected=NullPointerException.class) 100 public void test_cursorFromNull() { 101 Cursor.cursor(null); 102 } 103 104 @Test(expected=IllegalArgumentException.class) 105 public void test_cursorFromInvalidUrl() { 106 Cursor.cursor("file//:cursor.png"); 107 } 108 109 @Test(expected=IllegalArgumentException.class) 110 public void test_cursorFromInvalidName() { 111 Cursor.cursor("crosslair"); 112 } 113 }