1 /*
   2  * Copyright (c) 2011, 2014, 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 static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.assertNotSame;
  30 import javafx.beans.property.ObjectProperty;
  31 import javafx.beans.property.SimpleObjectProperty;
  32 import javafx.scene.effect.Blend;
  33 import javafx.scene.effect.Effect;
  34 import javafx.scene.effect.Shadow;
  35 import javafx.scene.shape.Rectangle;
  36 
  37 import org.junit.Rule;
  38 import org.junit.Test;
  39 import org.junit.rules.ExpectedException;
  40 
  41 public class Node_bind_Test {
  42     @Rule
  43     public ExpectedException thrown = ExpectedException.none();
  44 
  45      @Test public void testClip() {
  46          Rectangle rectA = new Rectangle(300, 300);
  47          Rectangle clip1 = new Rectangle(10, 10);
  48          Rectangle clip2 = new Rectangle(100, 100);
  49          ObjectProperty<Node> v = new SimpleObjectProperty<Node>(clip1);
  50          rectA.clipProperty().bind(v);
  51          assertEquals(rectA.getClip(), clip1);
  52          v.set(clip2);
  53          assertEquals(rectA.getClip(), clip2);
  54      }
  55 
  56      @Test public void testIllegalClip() {
  57          Rectangle rectA = new Rectangle(300, 300);
  58          Rectangle clip1 = new Rectangle(10, 10);
  59          Rectangle clip2 = new Rectangle(100, 100);
  60          clip2.setClip(rectA);
  61          ObjectProperty<Node> v = new SimpleObjectProperty<Node>(clip1);
  62          rectA.clipProperty().bind(v);
  63          assertEquals(rectA.getClip(), clip1);
  64          v.set(clip2);
  65          assertNotSame(rectA.getClip(), clip2);
  66      }
  67 
  68      @Test public void testBackToLegalClip() {
  69          Rectangle rectA = new Rectangle(300, 300);
  70          Rectangle clip1 = new Rectangle(10, 10);
  71          Rectangle clip2 = new Rectangle(100, 100);
  72          clip2.setClip(rectA);
  73          ObjectProperty<Node> v = new SimpleObjectProperty<Node>(clip1);
  74          rectA.clipProperty().bind(v);
  75          assertEquals(rectA.getClip(), clip1);
  76          v.set(clip2);
  77          assertEquals(rectA.getClip(), clip1);
  78      }
  79 
  80      @Test public void testEffect() {
  81          Shadow effect1 = new Shadow();
  82          Blend effect2 = new Blend();
  83          Rectangle rectA = new Rectangle(100, 100);
  84          ObjectProperty<Effect> v = new SimpleObjectProperty<Effect>(effect1);
  85          rectA.effectProperty().bind(v);
  86          assertEquals(rectA.getEffect(), effect1);
  87          v.set(effect2);
  88          assertEquals(rectA.getEffect(), effect2);
  89      }
  90 }