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 package test.com.sun.javafx.binding;
26
27 import com.sun.javafx.binding.Logging;
28 import java.beans.PropertyChangeListener;
29 import java.beans.PropertyChangeSupport;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
33 import java.util.Random;
34 import test.javafx.beans.Person;
35 import javafx.beans.binding.Bindings;
36 import javafx.beans.binding.BooleanBinding;
37 import javafx.beans.binding.DoubleBinding;
38 import javafx.beans.binding.FloatBinding;
39 import javafx.beans.binding.IntegerBinding;
40 import javafx.beans.binding.LongBinding;
41 import javafx.beans.binding.ObjectBinding;
42 import javafx.beans.binding.StringBinding;
43 import test.javafx.binding.Variable;
44 import javafx.collections.ObservableList;
45 import com.sun.javafx.logging.PlatformLogger.Level;
46 import org.junit.AfterClass;
47 import org.junit.Before;
387 assertEquals(0L, binding2.get());
388 log.checkFine(NullPointerException.class);
389 b.setNext(null);
390 assertEquals(0L, binding2.get());
391 log.checkFine(NullPointerException.class);
392 }
393
394 @Test(expected = NullPointerException.class)
395 public void createWithRootNull() {
396 select = Bindings.selectString(null, "next", "name");
397 }
398
399 @Test
400 public void createWithNoSteps() {
401 select = Bindings.selectString(a.nameProperty());
402 assertEquals("a", select.get());
403 a.setName("b");
404 assertEquals("b", select.get());
405 a.setName(null);
406 assertNull(select.get());
407 log.check(java.util.logging.Level.WARNING, NullPointerException.class);
408 }
409
410 @Test(expected = NullPointerException.class)
411 public void createWithOneStepIsNull() {
412 select = Bindings.selectString(a.nextProperty(), null, "name");
413 }
414
415 @Test
416 public void testNullIsReturnedFromAChainWithAPropertyThatIsNotOnTheAvailableObject() {
417 select = Bindings.selectString(a.nextProperty(), "dummy", "name");
418 assertNull(select.get());
419 log.check(java.util.logging.Level.WARNING, NoSuchMethodException.class);
420 }
421
422 @SuppressWarnings("unchecked")
423 @Test
424 public void testAllMembersHaveListeners() {
425 // As yet, there should still be no listeners registered
426 assertEquals(1, a.numChangedListenersForNext);
427 assertEquals(0, a.numChangedListenersForName);
428 assertEquals(0, b.numChangedListenersForNext);
429 assertEquals(0, b.numChangedListenersForName);
430 assertEquals(0, c.numChangedListenersForNext);
431 assertEquals(0, c.numChangedListenersForName);
432 assertEquals(Arrays.asList(a.nextProperty()), dependencies);
433 // Read the value of the select. It should be == "c"
434 assertEquals("c", select.get());
435 // Now there should be changed listeners for a.value and
436 // b.value and c.name
437 assertEquals(1, a.numChangedListenersForNext);
438 assertEquals(0, a.numChangedListenersForName);
439 assertEquals(1, b.numChangedListenersForNext);
|
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 package test.com.sun.javafx.binding;
26
27 import java.beans.PropertyChangeListener;
28 import java.beans.PropertyChangeSupport;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.List;
32 import java.util.Random;
33 import test.javafx.beans.Person;
34 import javafx.beans.binding.Bindings;
35 import javafx.beans.binding.BooleanBinding;
36 import javafx.beans.binding.DoubleBinding;
37 import javafx.beans.binding.FloatBinding;
38 import javafx.beans.binding.IntegerBinding;
39 import javafx.beans.binding.LongBinding;
40 import javafx.beans.binding.ObjectBinding;
41 import javafx.beans.binding.StringBinding;
42 import test.javafx.binding.Variable;
43 import javafx.collections.ObservableList;
44 import com.sun.javafx.logging.PlatformLogger.Level;
45 import org.junit.AfterClass;
46 import org.junit.Before;
386 assertEquals(0L, binding2.get());
387 log.checkFine(NullPointerException.class);
388 b.setNext(null);
389 assertEquals(0L, binding2.get());
390 log.checkFine(NullPointerException.class);
391 }
392
393 @Test(expected = NullPointerException.class)
394 public void createWithRootNull() {
395 select = Bindings.selectString(null, "next", "name");
396 }
397
398 @Test
399 public void createWithNoSteps() {
400 select = Bindings.selectString(a.nameProperty());
401 assertEquals("a", select.get());
402 a.setName("b");
403 assertEquals("b", select.get());
404 a.setName(null);
405 assertNull(select.get());
406 log.checkWarning(NullPointerException.class);
407 }
408
409 @Test(expected = NullPointerException.class)
410 public void createWithOneStepIsNull() {
411 select = Bindings.selectString(a.nextProperty(), null, "name");
412 }
413
414 @Test
415 public void testNullIsReturnedFromAChainWithAPropertyThatIsNotOnTheAvailableObject() {
416 select = Bindings.selectString(a.nextProperty(), "dummy", "name");
417 assertNull(select.get());
418 log.checkWarning(NoSuchMethodException.class);
419 }
420
421 @SuppressWarnings("unchecked")
422 @Test
423 public void testAllMembersHaveListeners() {
424 // As yet, there should still be no listeners registered
425 assertEquals(1, a.numChangedListenersForNext);
426 assertEquals(0, a.numChangedListenersForName);
427 assertEquals(0, b.numChangedListenersForNext);
428 assertEquals(0, b.numChangedListenersForName);
429 assertEquals(0, c.numChangedListenersForNext);
430 assertEquals(0, c.numChangedListenersForName);
431 assertEquals(Arrays.asList(a.nextProperty()), dependencies);
432 // Read the value of the select. It should be == "c"
433 assertEquals("c", select.get());
434 // Now there should be changed listeners for a.value and
435 // b.value and c.name
436 assertEquals(1, a.numChangedListenersForNext);
437 assertEquals(0, a.numChangedListenersForName);
438 assertEquals(1, b.numChangedListenersForNext);
|