1 /*
   2  * Copyright (c) 2017, 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 myapp4;
  27 
  28 import javafx.beans.binding.Bindings;
  29 import javafx.beans.binding.DoubleBinding;
  30 import javafx.beans.binding.ObjectBinding;
  31 import myapp4.pkg5.MyProps;
  32 
  33 import static myapp4.Constants.*;
  34 
  35 // This logic is copied from AppBindingsExported.
  36 
  37 /**
  38  * Modular test application for testing JavaFX beans.
  39  * This is launched by ModuleLauncherTest.
  40  */
  41 public class AppBindingsQualOpened {
  42 
  43     /**
  44      * @param args the command line arguments
  45      */
  46     public static void main(String[] args) {
  47         try {
  48             new AppBindingsQualOpened().doTest();
  49             System.exit(ERROR_NONE);
  50         } catch (Throwable t) {
  51             t.printStackTrace(System.err);
  52             System.exit(ERROR_ASSERTION_FAILURE);
  53         }
  54     }
  55 
  56     private final double EPSILON = 1.0e-4;
  57 
  58     private void assertEquals(double expected, double observed) {
  59         if (Math.abs(expected - observed) > EPSILON) {
  60             throw new AssertionError("expected:<" + expected + "> but was:<" + observed + ">");
  61         }
  62     }
  63 
  64     private void assertEquals(String expected, String observed) {
  65         if (!expected.equals(observed)) {
  66             throw new AssertionError("expected:<" + expected + "> but was:<" + observed + ">");
  67         }
  68     }
  69 
  70     private void assertSame(Object expected, Object observed) {
  71         if (expected != observed) {
  72             throw new AssertionError("expected:<" + expected + "> but was:<" + observed + ">");
  73         }
  74     }
  75 
  76     public void doTest() throws Exception {
  77         MyProps root = new MyProps();
  78         MyProps a = new MyProps();
  79         MyProps b = new MyProps();
  80 
  81         root.setNext(a);
  82         a.setNext(b);
  83         a.setFoo(1.2);
  84         b.setFoo(2.3);
  85 
  86         DoubleBinding binding1 = Bindings.selectDouble(root, "next", "foo");
  87         assertEquals(1.2, binding1.get());
  88         a.setFoo(3.4);
  89         assertEquals(3.4, binding1.get());
  90 
  91         ObjectBinding<MyProps> binding2 = Bindings.select(root, "next", "next");
  92         assertEquals(2.3, binding2.get().getFoo());
  93         b.setFoo(4.5);
  94         assertEquals(4.5, binding2.get().getFoo());
  95 
  96         RootProps root2 = new RootProps();
  97         MyProps c = new MyProps();
  98         MyProps d = new MyProps();
  99 
 100         root2.setNext(c);
 101         c.setNext(d);
 102         c.setFoo(1.2);
 103         d.setFoo(2.3);
 104 
 105         DoubleBinding binding3 = Bindings.selectDouble(root2, "next", "foo");
 106         assertEquals(1.2, binding3.get());
 107         c.setFoo(3.4);
 108         assertEquals(3.4, binding3.get());
 109 
 110         ObjectBinding<MyProps> binding4 = Bindings.select(root2, "next", "next");
 111         assertEquals(2.3, binding4.get().getFoo());
 112         d.setFoo(4.5);
 113         assertEquals(4.5, binding4.get().getFoo());
 114     }
 115 }