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.property.adapter.JavaBeanDoubleProperty; 29 import javafx.beans.property.adapter.JavaBeanDoublePropertyBuilder; 30 import javafx.beans.property.adapter.JavaBeanObjectProperty; 31 import javafx.beans.property.adapter.JavaBeanObjectPropertyBuilder; 32 import javafx.beans.property.adapter.ReadOnlyJavaBeanStringProperty; 33 import javafx.beans.property.adapter.ReadOnlyJavaBeanStringPropertyBuilder; 34 import myapp4.pkg4.POJO; 35 import myapp4.pkg4.RefClass; 36 37 import static myapp4.Constants.*; 38 39 // This logic is copied from AppBeansExported. 40 41 /** 42 * Modular test application for testing JavaFX beans. 43 * This is launched by ModuleLauncherTest. 44 */ 45 public class AppBeansOpened { 46 47 /** 48 * @param args the command line arguments 49 */ 50 public static void main(String[] args) { 51 try { 52 new AppBeansOpened().doTest(); 53 System.exit(ERROR_NONE); 54 } catch (Throwable t) { 55 t.printStackTrace(System.err); 56 System.exit(ERROR_ASSERTION_FAILURE); 57 } 58 } 59 60 private final double EPSILON = 1.0e-4; 61 62 private void assertEquals(double expected, double observed) { 63 if (Math.abs(expected - observed) > EPSILON) { 64 throw new AssertionError("expected:<" + expected + "> but was:<" + observed + ">"); 65 } 66 } 67 68 private void assertEquals(String expected, String observed) { 69 if (!expected.equals(observed)) { 70 throw new AssertionError("expected:<" + expected + "> but was:<" + observed + ">"); 71 } 72 } 73 74 private void assertSame(Object expected, Object observed) { 75 if (expected != observed) { 76 throw new AssertionError("expected:<" + expected + "> but was:<" + observed + ">"); 77 } 78 } 79 80 public void doTest() throws Exception { 81 String name = "test object"; 82 double val = 1.2; 83 RefClass obj = new RefClass(); 84 85 POJO bean = new POJO(name, val, obj); 86 87 JavaBeanDoubleProperty valProp = JavaBeanDoublePropertyBuilder.create() 88 .bean(bean) 89 .name("val") 90 .build(); 91 92 double retVal = valProp.get(); 93 assertEquals(val, retVal); 94 95 val = 2.5; 96 valProp.set(val); 97 retVal = valProp.get(); 98 assertEquals(val, retVal); 99 100 JavaBeanObjectProperty<RefClass> objProp = JavaBeanObjectPropertyBuilder.create() 101 .bean(bean) 102 .name("obj") 103 .build(); 104 105 RefClass retObj = objProp.get(); 106 assertSame(obj, retObj); 107 108 obj = new RefClass(); 109 objProp.set(obj); 110 retObj = objProp.get(); 111 assertSame(obj, retObj); 112 113 ReadOnlyJavaBeanStringProperty namePropRO = ReadOnlyJavaBeanStringPropertyBuilder.create() 114 .bean(bean) 115 .name("name") 116 .build(); 117 118 String retName = namePropRO.get(); 119 assertEquals(name, retName); 120 } 121 122 }