1 /*
   2  * Copyright (c) 2010, 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.shape;
  27 
  28 import com.sun.javafx.FXUnit;
  29 import com.sun.javafx.sg.prism.NGLine;
  30 import com.sun.javafx.sg.prism.NGNode;
  31 import javafx.scene.NodeTest;
  32 import org.junit.Rule;
  33 import org.junit.Test;
  34 
  35 import static org.junit.Assert.assertFalse;
  36 import static org.junit.Assert.assertNotNull;
  37 
  38 public class LineTest {
  39 
  40     @Rule
  41     public FXUnit fx = new FXUnit();
  42 
  43     @Test
  44     public void testPropertyPropagation_visible() throws Exception {
  45         final Line node = new StubLine();
  46         NodeTest.testBooleanPropertyPropagation(node, "visible", false, true);
  47     }
  48 
  49     @Test
  50     public void testPropertyPropagation_startX() throws Exception {
  51         final Line node = new StubLine();
  52         NodeTest.testDoublePropertyPropagation(node, "startX", "x1", 100, 200);
  53     }
  54 
  55     @Test
  56     public void testPropertyPropagation_startY() throws Exception {
  57         final Line node = new StubLine();
  58         NodeTest.testDoublePropertyPropagation(node, "startY", "y1", 100, 200);
  59     }
  60 
  61     @Test
  62     public void testPropertyPropagation_endX() throws Exception {
  63         final Line node = new StubLine();
  64         NodeTest.testDoublePropertyPropagation(node, "endX", "x2", 100, 200);
  65     }
  66 
  67     @Test
  68     public void testPropertyPropagation_endY() throws Exception {
  69         final Line node = new StubLine();
  70         NodeTest.testDoublePropertyPropagation(node, "endY", "y2", 100, 200);
  71     }
  72 
  73     @Test public void testBoundPropertySync_startX() throws Exception {
  74         NodeTest.assertDoublePropertySynced(
  75                 new StubLine(0.0 ,0.0, 100.0, 100.0),
  76                 "startX", "x1", 10.0);
  77     }
  78 
  79     @Test public void testBoundPropertySync_startY() throws Exception {
  80         NodeTest.assertDoublePropertySynced(
  81                 new StubLine(0.0 ,0.0, 100.0, 100.0),
  82                 "startY", "y1", 50.0);
  83     }
  84 
  85     @Test public void testBoundPropertySync_endX() throws Exception {
  86         NodeTest.assertDoublePropertySynced(
  87                 new StubLine(0.0 ,0.0, 100.0, 100.0),
  88                 "endX", "x2", 200.0);
  89     }
  90 
  91     @Test public void testBoundPropertySync_endY() throws Exception {
  92         NodeTest.assertDoublePropertySynced(
  93                 new StubLine(0.0 ,0.0, 100.0, 100.0),
  94                 "endY", "y2", 300.0);
  95     }
  96 
  97     @Test public void toStringShouldReturnNonEmptyString() {
  98         String s = new StubLine().toString();
  99         assertNotNull(s);
 100         assertFalse(s.isEmpty());
 101     }
 102 
 103     public class StubLine extends Line {
 104         public StubLine() {
 105             super();
 106         }
 107 
 108         public StubLine(double startX, double startY, double endX, double endY) {
 109             super(startX, startY, endX, endY);
 110         }
 111 
 112         @Override
 113         protected NGNode impl_createPeer() {
 114             return new StubNGLine();
 115         }
 116     }
 117 
 118     public class StubNGLine extends NGLine {
 119         private float x1;
 120         private float y1;
 121         private float x2;
 122         private float y2;
 123 
 124         public float getX1() {return x1;}
 125         public float getX2() {return x2;}
 126         public float getY1() {return y1;}
 127         public float getY2() {return y2;}
 128 
 129         @Override
 130         public void updateLine(float x1, float y1, float x2, float y2) {
 131             this.x1 = x1;
 132             this.y1 = y1;
 133             this.x2 = x2;
 134             this.y2 = y2;
 135         }
 136     }
 137 
 138 }