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