< prev index next >

modules/base/src/test/java/javafx/beans/property/ReadOnlyIntegerWrapperTest.java

Print this page
rev 9213 : 8089557: bindBidirection works for ReadOnly*Wrapper incorrectly


 138         assertEquals(VALUE_1, p1.get());
 139         assertEquals((Integer)VALUE_1, p1.getValue());
 140         assertFalse(property.isBound());
 141         assertEquals(bean, p1.getBean());
 142         assertEquals(name, p1.getName());
 143         final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty();
 144         assertEquals(VALUE_1, r1.get());
 145         assertEquals((Integer)VALUE_1, r1.getValue());
 146         assertEquals(bean, r1.getBean());
 147         assertEquals(name, r1.getName());
 148     }
 149 
 150     @Test
 151     public void testLazySet() {
 152         attachInvalidationListeners();
 153         
 154         // set value once
 155         property.set(VALUE_1);
 156         assertEquals(VALUE_1, property.get());
 157         property.check(1);
 158         internalInvalidationListener.check(readOnlyProperty, 1);
 159         assertEquals(VALUE_1, readOnlyProperty.get());
 160         publicInvalidationListener.check(readOnlyProperty, 1);
 161         
 162         // set same value again
 163         property.set(VALUE_1);
 164         assertEquals(VALUE_1, property.get());
 165         property.check(0);
 166         internalInvalidationListener.check(null, 0);
 167         assertEquals(VALUE_1, readOnlyProperty.get());
 168         publicInvalidationListener.check(null, 0);
 169         
 170         // set value twice without reading
 171         property.set(VALUE_2);
 172         property.set(VALUE_1);
 173         assertEquals(VALUE_1, property.get());
 174         property.check(1);
 175         internalInvalidationListener.check(readOnlyProperty, 1);
 176         assertEquals(VALUE_1, readOnlyProperty.get());
 177         publicInvalidationListener.check(readOnlyProperty, 1);
 178     }
 179     
 180     @Test
 181     public void testInternalEagerSet() {
 182         attachInternalChangeListener();
 183         
 184         // set value once
 185         property.set(VALUE_1);
 186         assertEquals(VALUE_1, property.get());
 187         property.check(1);
 188         internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 189         assertEquals(VALUE_1, readOnlyProperty.get());
 190         
 191         // set same value again
 192         property.set(VALUE_1);
 193         assertEquals(VALUE_1, property.get());
 194         property.check(0);
 195         internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
 196         assertEquals(VALUE_1, readOnlyProperty.get());
 197         
 198         // set value twice without reading
 199         property.set(VALUE_2);
 200         property.set(VALUE_1);
 201         assertEquals(VALUE_1, property.get());
 202         property.check(2);
 203         internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
 204         assertEquals(VALUE_1, readOnlyProperty.get());
 205     }
 206     
 207     @Test
 208     public void testPublicEagerSet() {
 209         attachPublicChangeListener();
 210         
 211         // set value once
 212         property.set(VALUE_1);
 213         assertEquals(VALUE_1, property.get());
 214         property.check(1);
 215         assertEquals(VALUE_1, readOnlyProperty.get());
 216         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 217         
 218         // set same value again
 219         property.set(VALUE_1);
 220         assertEquals(VALUE_1, property.get());
 221         property.check(0);
 222         assertEquals(VALUE_1, readOnlyProperty.get());
 223         publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
 224         
 225         // set value twice without reading
 226         property.set(VALUE_2);
 227         property.set(VALUE_1);
 228         assertEquals(VALUE_1, property.get());
 229         property.check(2);
 230         assertEquals(VALUE_1, readOnlyProperty.get());
 231         publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
 232     }
 233 
 234     @Test
 235     public void testLazySetValue() {
 236         attachInvalidationListeners();
 237         
 238         // set value once
 239         property.setValue(VALUE_1);
 240         assertEquals(VALUE_1, property.get());
 241         property.check(1);
 242         internalInvalidationListener.check(readOnlyProperty, 1);
 243         assertEquals(VALUE_1, readOnlyProperty.get());
 244         publicInvalidationListener.check(readOnlyProperty, 1);
 245         
 246         // set same value again
 247         property.setValue(VALUE_1);
 248         assertEquals(VALUE_1, property.get());
 249         property.check(0);
 250         internalInvalidationListener.check(null, 0);
 251         assertEquals(VALUE_1, readOnlyProperty.get());
 252         publicInvalidationListener.check(null, 0);
 253         
 254         // set value twice without reading
 255         property.setValue(VALUE_2);
 256         property.setValue(VALUE_1);
 257         assertEquals(VALUE_1, property.get());
 258         property.check(1);
 259         internalInvalidationListener.check(readOnlyProperty, 1);
 260         assertEquals(VALUE_1, readOnlyProperty.get());
 261         publicInvalidationListener.check(readOnlyProperty, 1);
 262     }
 263     
 264     @Test
 265     public void testInternalEagerSetValue() {
 266         attachInternalChangeListener();
 267         
 268         // set value once
 269         property.setValue(VALUE_1);
 270         assertEquals(VALUE_1, property.get());
 271         property.check(1);
 272         internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 273         assertEquals(VALUE_1, readOnlyProperty.get());
 274         
 275         // set same value again
 276         property.setValue(VALUE_1);
 277         assertEquals(VALUE_1, property.get());
 278         property.check(0);
 279         internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
 280         assertEquals(VALUE_1, readOnlyProperty.get());
 281         
 282         // set value twice without reading
 283         property.setValue(VALUE_2);
 284         property.setValue(VALUE_1);
 285         assertEquals(VALUE_1, property.get());
 286         property.check(2);
 287         internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
 288         assertEquals(VALUE_1, readOnlyProperty.get());
 289     }
 290     
 291     @Test
 292     public void testPublicEagerSetValue() {
 293         attachPublicChangeListener();
 294         
 295         // set value once
 296         property.setValue(VALUE_1);
 297         assertEquals(VALUE_1, property.get());
 298         property.check(1);
 299         assertEquals(VALUE_1, readOnlyProperty.get());
 300         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 301         
 302         // set same value again
 303         property.setValue(VALUE_1);
 304         assertEquals(VALUE_1, property.get());
 305         property.check(0);
 306         assertEquals(VALUE_1, readOnlyProperty.get());
 307         publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);


 314         assertEquals(VALUE_1, readOnlyProperty.get());
 315         publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
 316     }
 317     
 318     @Test(expected=RuntimeException.class)
 319     public void testSetBoundValue() {
 320         final IntegerProperty v = new SimpleIntegerProperty(VALUE_1);
 321         property.bind(v);
 322         property.set(VALUE_1);
 323     }
 324 
 325     @Test
 326     public void testLazyBind_primitive() {
 327         attachInvalidationListeners();
 328         final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1);
 329 
 330         property.bind(v);
 331         assertEquals(VALUE_1, property.get());
 332         assertTrue(property.isBound());
 333         property.check(1);
 334         internalInvalidationListener.check(readOnlyProperty, 1);
 335         assertEquals(VALUE_1, readOnlyProperty.get());
 336         publicInvalidationListener.check(readOnlyProperty, 1);
 337 
 338         // change binding once
 339         v.set(VALUE_2);
 340         assertEquals(VALUE_2, property.get());
 341         property.check(1);
 342         internalInvalidationListener.check(readOnlyProperty, 1);
 343         assertEquals(VALUE_2, readOnlyProperty.get());
 344         publicInvalidationListener.check(readOnlyProperty, 1);
 345 
 346         // change binding twice without reading
 347         v.set(VALUE_1);
 348         v.set(VALUE_2);
 349         assertEquals(VALUE_2, property.get());
 350         property.check(1);
 351         internalInvalidationListener.check(readOnlyProperty, 1);
 352         assertEquals(VALUE_2, readOnlyProperty.get());
 353         publicInvalidationListener.check(readOnlyProperty, 1);
 354 
 355         // change binding twice to same value
 356         v.set(VALUE_1);
 357         v.set(VALUE_1);
 358         assertEquals(VALUE_1, property.get());
 359         property.check(1);
 360         internalInvalidationListener.check(readOnlyProperty, 1);
 361         assertEquals(VALUE_1, readOnlyProperty.get());
 362         publicInvalidationListener.check(readOnlyProperty, 1);
 363     }
 364 
 365     @Test
 366     public void testInternalEagerBind_primitive() {
 367         attachInternalChangeListener();
 368         final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1);
 369 
 370         property.bind(v);
 371         assertEquals(VALUE_1, property.get());
 372         assertTrue(property.isBound());
 373         property.check(1);
 374         internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 375         assertEquals(VALUE_1, readOnlyProperty.get());
 376 
 377         // change binding once
 378         v.set(VALUE_2);
 379         assertEquals(VALUE_2, property.get());
 380         property.check(1);
 381         internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1);
 382         assertEquals(VALUE_2, readOnlyProperty.get());
 383 
 384         // change binding twice without reading
 385         v.set(VALUE_1);
 386         v.set(VALUE_2);
 387         assertEquals(VALUE_2, property.get());
 388         property.check(2);
 389         internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
 390         assertEquals(VALUE_2, readOnlyProperty.get());
 391 
 392         // change binding twice to same value
 393         v.set(VALUE_1);
 394         v.set(VALUE_1);
 395         assertEquals(VALUE_1, property.get());
 396         property.check(2);
 397         internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
 398         assertEquals(VALUE_1, readOnlyProperty.get());
 399     }
 400     
 401     @Test
 402     public void testPublicEagerBind_primitive() {
 403         attachPublicChangeListener();
 404         final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1);
 405 
 406         property.bind(v);
 407         assertEquals(VALUE_1, property.get());
 408         assertTrue(property.isBound());
 409         property.check(1);
 410         assertEquals(VALUE_1, readOnlyProperty.get());
 411         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 412 
 413         // change binding once
 414         v.set(VALUE_2);
 415         assertEquals(VALUE_2, property.get());
 416         property.check(1);
 417         assertEquals(VALUE_2, readOnlyProperty.get());


 426         publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
 427 
 428         // change binding twice to same value
 429         v.set(VALUE_1);
 430         v.set(VALUE_1);
 431         assertEquals(VALUE_1, property.get());
 432         property.check(2);
 433         assertEquals(VALUE_1, readOnlyProperty.get());
 434         publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
 435     }
 436     
 437     @Test
 438     public void testLazyBind_generic() {
 439         attachInvalidationListeners();
 440         final ObservableObjectValueStub<Integer> v = new ObservableObjectValueStub<Integer>(VALUE_1);
 441 
 442         property.bind(v);
 443         assertEquals(VALUE_1, property.get());
 444         assertTrue(property.isBound());
 445         property.check(1);
 446         internalInvalidationListener.check(readOnlyProperty, 1);
 447         assertEquals(VALUE_1, readOnlyProperty.get());
 448         publicInvalidationListener.check(readOnlyProperty, 1);
 449 
 450         // change binding once
 451         v.set(VALUE_2);
 452         assertEquals(VALUE_2, property.get());
 453         property.check(1);
 454         internalInvalidationListener.check(readOnlyProperty, 1);
 455         assertEquals(VALUE_2, readOnlyProperty.get());
 456         publicInvalidationListener.check(readOnlyProperty, 1);
 457 
 458         // change binding twice without reading
 459         v.set(VALUE_1);
 460         v.set(VALUE_2);
 461         assertEquals(VALUE_2, property.get());
 462         property.check(1);
 463         internalInvalidationListener.check(readOnlyProperty, 1);
 464         assertEquals(VALUE_2, readOnlyProperty.get());
 465         publicInvalidationListener.check(readOnlyProperty, 1);
 466 
 467         // change binding twice to same value
 468         v.set(VALUE_1);
 469         v.set(VALUE_1);
 470         assertEquals(VALUE_1, property.get());
 471         property.check(1);
 472         internalInvalidationListener.check(readOnlyProperty, 1);
 473         assertEquals(VALUE_1, readOnlyProperty.get());
 474         publicInvalidationListener.check(readOnlyProperty, 1);
 475     }
 476 
 477     @Test
 478     public void testInternalEagerBind_generic() {
 479         attachInternalChangeListener();
 480         final ObservableObjectValueStub<Integer> v = new ObservableObjectValueStub<Integer>(VALUE_1);
 481 
 482         property.bind(v);
 483         assertEquals(VALUE_1, property.get());
 484         assertTrue(property.isBound());
 485         property.check(1);
 486         internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 487         assertEquals(VALUE_1, readOnlyProperty.get());
 488 
 489         // change binding once
 490         v.set(VALUE_2);
 491         assertEquals(VALUE_2, property.get());
 492         property.check(1);
 493         internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1);
 494         assertEquals(VALUE_2, readOnlyProperty.get());
 495 
 496         // change binding twice without reading
 497         v.set(VALUE_1);
 498         v.set(VALUE_2);
 499         assertEquals(VALUE_2, property.get());
 500         property.check(2);
 501         internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
 502         assertEquals(VALUE_2, readOnlyProperty.get());
 503 
 504         // change binding twice to same value
 505         v.set(VALUE_1);
 506         v.set(VALUE_1);
 507         assertEquals(VALUE_1, property.get());
 508         property.check(2);
 509         internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
 510         assertEquals(VALUE_1, readOnlyProperty.get());
 511     }
 512 
 513     @Test
 514     public void testPublicEagerBind_generic() {
 515         attachPublicChangeListener();
 516         final ObservableObjectValueStub<Integer> v = new ObservableObjectValueStub<Integer>(VALUE_1);
 517 
 518         property.bind(v);
 519         assertEquals(VALUE_1, property.get());
 520         assertTrue(property.isBound());
 521         property.check(1);
 522         assertEquals(VALUE_1, readOnlyProperty.get());
 523         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 524 
 525         // change binding once
 526         v.set(VALUE_2);
 527         assertEquals(VALUE_2, property.get());
 528         property.check(1);
 529         assertEquals(VALUE_2, readOnlyProperty.get());


 551         property.bind(null);
 552     }
 553 
 554     @Test
 555     public void testRebind() {
 556         attachInvalidationListeners();
 557         final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1);
 558         final IntegerProperty v2 = new SimpleIntegerProperty(VALUE_2);
 559         property.bind(v1);
 560         property.get();
 561         readOnlyProperty.get();
 562         property.reset();
 563         internalInvalidationListener.reset();
 564         publicInvalidationListener.reset();
 565         
 566         // rebind causes invalidation event
 567         property.bind(v2);
 568         assertEquals(VALUE_2, property.get());
 569         assertTrue(property.isBound());
 570         property.check(1);
 571         internalInvalidationListener.check(readOnlyProperty, 1);
 572         assertEquals(VALUE_2, readOnlyProperty.get());
 573         publicInvalidationListener.check(readOnlyProperty, 1);
 574         
 575         // change new binding
 576         v2.set(VALUE_1);
 577         assertEquals(VALUE_1, property.get());
 578         property.check(1);
 579         internalInvalidationListener.check(readOnlyProperty, 1);
 580         assertEquals(VALUE_1, readOnlyProperty.get());
 581         publicInvalidationListener.check(readOnlyProperty, 1);
 582         
 583         // change old binding
 584         v1.set(VALUE_2);
 585         assertEquals(VALUE_1, property.get());
 586         property.check(0);
 587         internalInvalidationListener.check(null, 0);
 588         assertEquals(VALUE_1, readOnlyProperty.get());
 589         publicInvalidationListener.check(null, 0);
 590         
 591         // rebind to same observable should have no effect
 592         property.bind(v2);
 593         assertEquals(VALUE_1, property.get());
 594         assertTrue(property.isBound());
 595         property.check(0);
 596         internalInvalidationListener.check(null, 0);
 597         assertEquals(VALUE_1, readOnlyProperty.get());
 598         publicInvalidationListener.check(null, 0);
 599     }


 606         property.unbind();
 607         assertEquals(VALUE_1, property.get());
 608         assertFalse(property.isBound());
 609         assertEquals(VALUE_1, readOnlyProperty.get());
 610         property.reset();
 611         internalInvalidationListener.reset();
 612         publicInvalidationListener.reset();
 613         
 614         // change binding
 615         v.set(VALUE_2);
 616         assertEquals(VALUE_1, property.get());
 617         property.check(0);
 618         internalInvalidationListener.check(null, 0);
 619         assertEquals(VALUE_1, readOnlyProperty.get());
 620         publicInvalidationListener.check(null, 0);
 621         
 622         // set value
 623         property.set(VALUE_2);
 624         assertEquals(VALUE_2, property.get());
 625         property.check(1);
 626         internalInvalidationListener.check(readOnlyProperty, 1);
 627         assertEquals(VALUE_2, readOnlyProperty.get());
 628         publicInvalidationListener.check(readOnlyProperty, 1);
 629     }
 630     
 631     @Test
 632     public void testAddingListenerWillAlwaysReceiveInvalidationEvent() {
 633         final IntegerProperty v = new SimpleIntegerProperty(VALUE_1);
 634         final InvalidationListenerMock internalListener2 = new InvalidationListenerMock();
 635         final InvalidationListenerMock internalListener3 = new InvalidationListenerMock();
 636         final InvalidationListenerMock publicListener2 = new InvalidationListenerMock();
 637         final InvalidationListenerMock publicListener3 = new InvalidationListenerMock();
 638 
 639         // setting the property,checking internal
 640         property.set(VALUE_1);
 641         property.addListener(internalListener2);
 642         internalListener2.reset();
 643         property.set(VALUE_2);
 644         internalListener2.check(readOnlyProperty, 1);
 645         
 646         // setting the property, checking public
 647         property.set(VALUE_1);
 648         readOnlyProperty.addListener(publicListener2);
 649         publicListener2.reset();
 650         property.set(VALUE_2);
 651         publicListener2.check(readOnlyProperty, 1);
 652         
 653         // binding the property, checking internal
 654         property.bind(v);
 655         v.set(VALUE_2);
 656         property.addListener(internalListener3);
 657         v.get();
 658         internalListener3.reset();
 659         v.set(VALUE_1);
 660         internalListener3.check(readOnlyProperty, 1);
 661         
 662         // binding the property, checking public
 663         property.bind(v);
 664         v.set(VALUE_2);
 665         readOnlyProperty.addListener(publicListener3);
 666         v.get();
 667         publicListener3.reset();
 668         v.set(VALUE_1);
 669         publicListener3.check(readOnlyProperty, 1);
 670     }
 671     
 672     @Test
 673     public void testRemoveListeners() {
 674         attachInvalidationListeners();
 675         attachInternalChangeListener();
 676         property.removeListener(internalInvalidationListener);
 677         property.removeListener(internalChangeListener);
 678         property.get();
 679         internalInvalidationListener.reset();
 680         internalChangeListener.reset();




 138         assertEquals(VALUE_1, p1.get());
 139         assertEquals((Integer)VALUE_1, p1.getValue());
 140         assertFalse(property.isBound());
 141         assertEquals(bean, p1.getBean());
 142         assertEquals(name, p1.getName());
 143         final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty();
 144         assertEquals(VALUE_1, r1.get());
 145         assertEquals((Integer)VALUE_1, r1.getValue());
 146         assertEquals(bean, r1.getBean());
 147         assertEquals(name, r1.getName());
 148     }
 149 
 150     @Test
 151     public void testLazySet() {
 152         attachInvalidationListeners();
 153         
 154         // set value once
 155         property.set(VALUE_1);
 156         assertEquals(VALUE_1, property.get());
 157         property.check(1);
 158         internalInvalidationListener.check(property, 1);
 159         assertEquals(VALUE_1, readOnlyProperty.get());
 160         publicInvalidationListener.check(readOnlyProperty, 1);
 161         
 162         // set same value again
 163         property.set(VALUE_1);
 164         assertEquals(VALUE_1, property.get());
 165         property.check(0);
 166         internalInvalidationListener.check(null, 0);
 167         assertEquals(VALUE_1, readOnlyProperty.get());
 168         publicInvalidationListener.check(null, 0);
 169         
 170         // set value twice without reading
 171         property.set(VALUE_2);
 172         property.set(VALUE_1);
 173         assertEquals(VALUE_1, property.get());
 174         property.check(1);
 175         internalInvalidationListener.check(property, 1);
 176         assertEquals(VALUE_1, readOnlyProperty.get());
 177         publicInvalidationListener.check(readOnlyProperty, 1);
 178     }
 179     
 180     @Test
 181     public void testInternalEagerSet() {
 182         attachInternalChangeListener();
 183         
 184         // set value once
 185         property.set(VALUE_1);
 186         assertEquals(VALUE_1, property.get());
 187         property.check(1);
 188         internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
 189         assertEquals(VALUE_1, readOnlyProperty.get());
 190         
 191         // set same value again
 192         property.set(VALUE_1);
 193         assertEquals(VALUE_1, property.get());
 194         property.check(0);
 195         internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
 196         assertEquals(VALUE_1, readOnlyProperty.get());
 197         
 198         // set value twice without reading
 199         property.set(VALUE_2);
 200         property.set(VALUE_1);
 201         assertEquals(VALUE_1, property.get());
 202         property.check(2);
 203         internalChangeListener.check(property, VALUE_2, VALUE_1, 2);
 204         assertEquals(VALUE_1, readOnlyProperty.get());
 205     }
 206     
 207     @Test
 208     public void testPublicEagerSet() {
 209         attachPublicChangeListener();
 210         
 211         // set value once
 212         property.set(VALUE_1);
 213         assertEquals(VALUE_1, property.get());
 214         property.check(1);
 215         assertEquals(VALUE_1, readOnlyProperty.get());
 216         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 217         
 218         // set same value again
 219         property.set(VALUE_1);
 220         assertEquals(VALUE_1, property.get());
 221         property.check(0);
 222         assertEquals(VALUE_1, readOnlyProperty.get());
 223         publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
 224         
 225         // set value twice without reading
 226         property.set(VALUE_2);
 227         property.set(VALUE_1);
 228         assertEquals(VALUE_1, property.get());
 229         property.check(2);
 230         assertEquals(VALUE_1, readOnlyProperty.get());
 231         publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
 232     }
 233 
 234     @Test
 235     public void testLazySetValue() {
 236         attachInvalidationListeners();
 237         
 238         // set value once
 239         property.setValue(VALUE_1);
 240         assertEquals(VALUE_1, property.get());
 241         property.check(1);
 242         internalInvalidationListener.check(property, 1);
 243         assertEquals(VALUE_1, readOnlyProperty.get());
 244         publicInvalidationListener.check(readOnlyProperty, 1);
 245         
 246         // set same value again
 247         property.setValue(VALUE_1);
 248         assertEquals(VALUE_1, property.get());
 249         property.check(0);
 250         internalInvalidationListener.check(null, 0);
 251         assertEquals(VALUE_1, readOnlyProperty.get());
 252         publicInvalidationListener.check(null, 0);
 253         
 254         // set value twice without reading
 255         property.setValue(VALUE_2);
 256         property.setValue(VALUE_1);
 257         assertEquals(VALUE_1, property.get());
 258         property.check(1);
 259         internalInvalidationListener.check(property, 1);
 260         assertEquals(VALUE_1, readOnlyProperty.get());
 261         publicInvalidationListener.check(readOnlyProperty, 1);
 262     }
 263     
 264     @Test
 265     public void testInternalEagerSetValue() {
 266         attachInternalChangeListener();
 267         
 268         // set value once
 269         property.setValue(VALUE_1);
 270         assertEquals(VALUE_1, property.get());
 271         property.check(1);
 272         internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
 273         assertEquals(VALUE_1, readOnlyProperty.get());
 274         
 275         // set same value again
 276         property.setValue(VALUE_1);
 277         assertEquals(VALUE_1, property.get());
 278         property.check(0);
 279         internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
 280         assertEquals(VALUE_1, readOnlyProperty.get());
 281         
 282         // set value twice without reading
 283         property.setValue(VALUE_2);
 284         property.setValue(VALUE_1);
 285         assertEquals(VALUE_1, property.get());
 286         property.check(2);
 287         internalChangeListener.check(property, VALUE_2, VALUE_1, 2);
 288         assertEquals(VALUE_1, readOnlyProperty.get());
 289     }
 290     
 291     @Test
 292     public void testPublicEagerSetValue() {
 293         attachPublicChangeListener();
 294         
 295         // set value once
 296         property.setValue(VALUE_1);
 297         assertEquals(VALUE_1, property.get());
 298         property.check(1);
 299         assertEquals(VALUE_1, readOnlyProperty.get());
 300         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 301         
 302         // set same value again
 303         property.setValue(VALUE_1);
 304         assertEquals(VALUE_1, property.get());
 305         property.check(0);
 306         assertEquals(VALUE_1, readOnlyProperty.get());
 307         publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);


 314         assertEquals(VALUE_1, readOnlyProperty.get());
 315         publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
 316     }
 317     
 318     @Test(expected=RuntimeException.class)
 319     public void testSetBoundValue() {
 320         final IntegerProperty v = new SimpleIntegerProperty(VALUE_1);
 321         property.bind(v);
 322         property.set(VALUE_1);
 323     }
 324 
 325     @Test
 326     public void testLazyBind_primitive() {
 327         attachInvalidationListeners();
 328         final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1);
 329 
 330         property.bind(v);
 331         assertEquals(VALUE_1, property.get());
 332         assertTrue(property.isBound());
 333         property.check(1);
 334         internalInvalidationListener.check(property, 1);
 335         assertEquals(VALUE_1, readOnlyProperty.get());
 336         publicInvalidationListener.check(readOnlyProperty, 1);
 337 
 338         // change binding once
 339         v.set(VALUE_2);
 340         assertEquals(VALUE_2, property.get());
 341         property.check(1);
 342         internalInvalidationListener.check(property, 1);
 343         assertEquals(VALUE_2, readOnlyProperty.get());
 344         publicInvalidationListener.check(readOnlyProperty, 1);
 345 
 346         // change binding twice without reading
 347         v.set(VALUE_1);
 348         v.set(VALUE_2);
 349         assertEquals(VALUE_2, property.get());
 350         property.check(1);
 351         internalInvalidationListener.check(property, 1);
 352         assertEquals(VALUE_2, readOnlyProperty.get());
 353         publicInvalidationListener.check(readOnlyProperty, 1);
 354 
 355         // change binding twice to same value
 356         v.set(VALUE_1);
 357         v.set(VALUE_1);
 358         assertEquals(VALUE_1, property.get());
 359         property.check(1);
 360         internalInvalidationListener.check(property, 1);
 361         assertEquals(VALUE_1, readOnlyProperty.get());
 362         publicInvalidationListener.check(readOnlyProperty, 1);
 363     }
 364 
 365     @Test
 366     public void testInternalEagerBind_primitive() {
 367         attachInternalChangeListener();
 368         final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1);
 369 
 370         property.bind(v);
 371         assertEquals(VALUE_1, property.get());
 372         assertTrue(property.isBound());
 373         property.check(1);
 374         internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
 375         assertEquals(VALUE_1, readOnlyProperty.get());
 376 
 377         // change binding once
 378         v.set(VALUE_2);
 379         assertEquals(VALUE_2, property.get());
 380         property.check(1);
 381         internalChangeListener.check(property, VALUE_1, VALUE_2, 1);
 382         assertEquals(VALUE_2, readOnlyProperty.get());
 383 
 384         // change binding twice without reading
 385         v.set(VALUE_1);
 386         v.set(VALUE_2);
 387         assertEquals(VALUE_2, property.get());
 388         property.check(2);
 389         internalChangeListener.check(property, VALUE_1, VALUE_2, 2);
 390         assertEquals(VALUE_2, readOnlyProperty.get());
 391 
 392         // change binding twice to same value
 393         v.set(VALUE_1);
 394         v.set(VALUE_1);
 395         assertEquals(VALUE_1, property.get());
 396         property.check(2);
 397         internalChangeListener.check(property, VALUE_2, VALUE_1, 1);
 398         assertEquals(VALUE_1, readOnlyProperty.get());
 399     }
 400     
 401     @Test
 402     public void testPublicEagerBind_primitive() {
 403         attachPublicChangeListener();
 404         final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1);
 405 
 406         property.bind(v);
 407         assertEquals(VALUE_1, property.get());
 408         assertTrue(property.isBound());
 409         property.check(1);
 410         assertEquals(VALUE_1, readOnlyProperty.get());
 411         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 412 
 413         // change binding once
 414         v.set(VALUE_2);
 415         assertEquals(VALUE_2, property.get());
 416         property.check(1);
 417         assertEquals(VALUE_2, readOnlyProperty.get());


 426         publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
 427 
 428         // change binding twice to same value
 429         v.set(VALUE_1);
 430         v.set(VALUE_1);
 431         assertEquals(VALUE_1, property.get());
 432         property.check(2);
 433         assertEquals(VALUE_1, readOnlyProperty.get());
 434         publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
 435     }
 436     
 437     @Test
 438     public void testLazyBind_generic() {
 439         attachInvalidationListeners();
 440         final ObservableObjectValueStub<Integer> v = new ObservableObjectValueStub<Integer>(VALUE_1);
 441 
 442         property.bind(v);
 443         assertEquals(VALUE_1, property.get());
 444         assertTrue(property.isBound());
 445         property.check(1);
 446         internalInvalidationListener.check(property, 1);
 447         assertEquals(VALUE_1, readOnlyProperty.get());
 448         publicInvalidationListener.check(readOnlyProperty, 1);
 449 
 450         // change binding once
 451         v.set(VALUE_2);
 452         assertEquals(VALUE_2, property.get());
 453         property.check(1);
 454         internalInvalidationListener.check(property, 1);
 455         assertEquals(VALUE_2, readOnlyProperty.get());
 456         publicInvalidationListener.check(readOnlyProperty, 1);
 457 
 458         // change binding twice without reading
 459         v.set(VALUE_1);
 460         v.set(VALUE_2);
 461         assertEquals(VALUE_2, property.get());
 462         property.check(1);
 463         internalInvalidationListener.check(property, 1);
 464         assertEquals(VALUE_2, readOnlyProperty.get());
 465         publicInvalidationListener.check(readOnlyProperty, 1);
 466 
 467         // change binding twice to same value
 468         v.set(VALUE_1);
 469         v.set(VALUE_1);
 470         assertEquals(VALUE_1, property.get());
 471         property.check(1);
 472         internalInvalidationListener.check(property, 1);
 473         assertEquals(VALUE_1, readOnlyProperty.get());
 474         publicInvalidationListener.check(readOnlyProperty, 1);
 475     }
 476 
 477     @Test
 478     public void testInternalEagerBind_generic() {
 479         attachInternalChangeListener();
 480         final ObservableObjectValueStub<Integer> v = new ObservableObjectValueStub<Integer>(VALUE_1);
 481 
 482         property.bind(v);
 483         assertEquals(VALUE_1, property.get());
 484         assertTrue(property.isBound());
 485         property.check(1);
 486         internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
 487         assertEquals(VALUE_1, readOnlyProperty.get());
 488 
 489         // change binding once
 490         v.set(VALUE_2);
 491         assertEquals(VALUE_2, property.get());
 492         property.check(1);
 493         internalChangeListener.check(property, VALUE_1, VALUE_2, 1);
 494         assertEquals(VALUE_2, readOnlyProperty.get());
 495 
 496         // change binding twice without reading
 497         v.set(VALUE_1);
 498         v.set(VALUE_2);
 499         assertEquals(VALUE_2, property.get());
 500         property.check(2);
 501         internalChangeListener.check(property, VALUE_1, VALUE_2, 2);
 502         assertEquals(VALUE_2, readOnlyProperty.get());
 503 
 504         // change binding twice to same value
 505         v.set(VALUE_1);
 506         v.set(VALUE_1);
 507         assertEquals(VALUE_1, property.get());
 508         property.check(2);
 509         internalChangeListener.check(property, VALUE_2, VALUE_1, 1);
 510         assertEquals(VALUE_1, readOnlyProperty.get());
 511     }
 512 
 513     @Test
 514     public void testPublicEagerBind_generic() {
 515         attachPublicChangeListener();
 516         final ObservableObjectValueStub<Integer> v = new ObservableObjectValueStub<Integer>(VALUE_1);
 517 
 518         property.bind(v);
 519         assertEquals(VALUE_1, property.get());
 520         assertTrue(property.isBound());
 521         property.check(1);
 522         assertEquals(VALUE_1, readOnlyProperty.get());
 523         publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
 524 
 525         // change binding once
 526         v.set(VALUE_2);
 527         assertEquals(VALUE_2, property.get());
 528         property.check(1);
 529         assertEquals(VALUE_2, readOnlyProperty.get());


 551         property.bind(null);
 552     }
 553 
 554     @Test
 555     public void testRebind() {
 556         attachInvalidationListeners();
 557         final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1);
 558         final IntegerProperty v2 = new SimpleIntegerProperty(VALUE_2);
 559         property.bind(v1);
 560         property.get();
 561         readOnlyProperty.get();
 562         property.reset();
 563         internalInvalidationListener.reset();
 564         publicInvalidationListener.reset();
 565         
 566         // rebind causes invalidation event
 567         property.bind(v2);
 568         assertEquals(VALUE_2, property.get());
 569         assertTrue(property.isBound());
 570         property.check(1);
 571         internalInvalidationListener.check(property, 1);
 572         assertEquals(VALUE_2, readOnlyProperty.get());
 573         publicInvalidationListener.check(readOnlyProperty, 1);
 574         
 575         // change new binding
 576         v2.set(VALUE_1);
 577         assertEquals(VALUE_1, property.get());
 578         property.check(1);
 579         internalInvalidationListener.check(property, 1);
 580         assertEquals(VALUE_1, readOnlyProperty.get());
 581         publicInvalidationListener.check(readOnlyProperty, 1);
 582         
 583         // change old binding
 584         v1.set(VALUE_2);
 585         assertEquals(VALUE_1, property.get());
 586         property.check(0);
 587         internalInvalidationListener.check(null, 0);
 588         assertEquals(VALUE_1, readOnlyProperty.get());
 589         publicInvalidationListener.check(null, 0);
 590         
 591         // rebind to same observable should have no effect
 592         property.bind(v2);
 593         assertEquals(VALUE_1, property.get());
 594         assertTrue(property.isBound());
 595         property.check(0);
 596         internalInvalidationListener.check(null, 0);
 597         assertEquals(VALUE_1, readOnlyProperty.get());
 598         publicInvalidationListener.check(null, 0);
 599     }


 606         property.unbind();
 607         assertEquals(VALUE_1, property.get());
 608         assertFalse(property.isBound());
 609         assertEquals(VALUE_1, readOnlyProperty.get());
 610         property.reset();
 611         internalInvalidationListener.reset();
 612         publicInvalidationListener.reset();
 613         
 614         // change binding
 615         v.set(VALUE_2);
 616         assertEquals(VALUE_1, property.get());
 617         property.check(0);
 618         internalInvalidationListener.check(null, 0);
 619         assertEquals(VALUE_1, readOnlyProperty.get());
 620         publicInvalidationListener.check(null, 0);
 621         
 622         // set value
 623         property.set(VALUE_2);
 624         assertEquals(VALUE_2, property.get());
 625         property.check(1);
 626         internalInvalidationListener.check(property, 1);
 627         assertEquals(VALUE_2, readOnlyProperty.get());
 628         publicInvalidationListener.check(readOnlyProperty, 1);
 629     }
 630     
 631     @Test
 632     public void testAddingListenerWillAlwaysReceiveInvalidationEvent() {
 633         final IntegerProperty v = new SimpleIntegerProperty(VALUE_1);
 634         final InvalidationListenerMock internalListener2 = new InvalidationListenerMock();
 635         final InvalidationListenerMock internalListener3 = new InvalidationListenerMock();
 636         final InvalidationListenerMock publicListener2 = new InvalidationListenerMock();
 637         final InvalidationListenerMock publicListener3 = new InvalidationListenerMock();
 638 
 639         // setting the property,checking internal
 640         property.set(VALUE_1);
 641         property.addListener(internalListener2);
 642         internalListener2.reset();
 643         property.set(VALUE_2);
 644         internalListener2.check(property, 1);
 645         
 646         // setting the property, checking public
 647         property.set(VALUE_1);
 648         readOnlyProperty.addListener(publicListener2);
 649         publicListener2.reset();
 650         property.set(VALUE_2);
 651         publicListener2.check(readOnlyProperty, 1);
 652         
 653         // binding the property, checking internal
 654         property.bind(v);
 655         v.set(VALUE_2);
 656         property.addListener(internalListener3);
 657         v.get();
 658         internalListener3.reset();
 659         v.set(VALUE_1);
 660         internalListener3.check(property, 1);
 661         
 662         // binding the property, checking public
 663         property.bind(v);
 664         v.set(VALUE_2);
 665         readOnlyProperty.addListener(publicListener3);
 666         v.get();
 667         publicListener3.reset();
 668         v.set(VALUE_1);
 669         publicListener3.check(readOnlyProperty, 1);
 670     }
 671     
 672     @Test
 673     public void testRemoveListeners() {
 674         attachInvalidationListeners();
 675         attachInternalChangeListener();
 676         property.removeListener(internalInvalidationListener);
 677         property.removeListener(internalChangeListener);
 678         property.get();
 679         internalInvalidationListener.reset();
 680         internalChangeListener.reset();


< prev index next >