136 assertEquals(VALUE_1, p1.get());
137 assertEquals((Object)VALUE_1, p1.getValue());
138 assertFalse(property.isBound());
139 assertEquals(bean, p1.getBean());
140 assertEquals(name, p1.getName());
141 final ReadOnlySetProperty<Object> r1 = p1.getReadOnlyProperty();
142 assertEquals(VALUE_1, r1.get());
143 assertEquals((Object)VALUE_1, r1.getValue());
144 assertEquals(bean, r1.getBean());
145 assertEquals(name, r1.getName());
146 }
147
148 @Test
149 public void testLazySet() {
150 attachInvalidationListeners();
151
152 // set value once
153 property.set(VALUE_1);
154 assertEquals(VALUE_1, property.get());
155 property.check(1);
156 internalInvalidationListener.check(readOnlyProperty, 1);
157 assertEquals(VALUE_1, readOnlyProperty.get());
158 publicInvalidationListener.check(readOnlyProperty, 1);
159
160 // set same value again
161 property.set(VALUE_1);
162 assertEquals(VALUE_1, property.get());
163 property.check(0);
164 internalInvalidationListener.check(null, 0);
165 assertEquals(VALUE_1, readOnlyProperty.get());
166 publicInvalidationListener.check(null, 0);
167
168 // set value twice without reading
169 property.set(VALUE_2);
170 property.set(VALUE_1);
171 assertEquals(VALUE_1, property.get());
172 property.check(1);
173 internalInvalidationListener.check(readOnlyProperty, 1);
174 assertEquals(VALUE_1, readOnlyProperty.get());
175 publicInvalidationListener.check(readOnlyProperty, 1);
176 }
177
178 @Test
179 public void testInternalEagerSet() {
180 attachInternalChangeListener();
181
182 // set value once
183 property.set(VALUE_1);
184 assertEquals(VALUE_1, property.get());
185 property.check(1);
186 internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
187 assertEquals(VALUE_1, readOnlyProperty.get());
188
189 // set same value again
190 property.set(VALUE_1);
191 assertEquals(VALUE_1, property.get());
192 property.check(0);
193 internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
194 assertEquals(VALUE_1, readOnlyProperty.get());
195
196 // set value twice without reading
197 property.set(VALUE_2);
198 property.set(VALUE_1);
199 assertEquals(VALUE_1, property.get());
200 property.check(2);
201 internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
202 assertEquals(VALUE_1, readOnlyProperty.get());
203 }
204
205 @Test
206 public void testPublicEagerSet() {
207 attachPublicChangeListener();
208
209 // set value once
210 property.set(VALUE_1);
211 assertEquals(VALUE_1, property.get());
212 property.check(1);
213 assertEquals(VALUE_1, readOnlyProperty.get());
214 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
215
216 // set same value again
217 property.set(VALUE_1);
218 assertEquals(VALUE_1, property.get());
219 property.check(0);
220 assertEquals(VALUE_1, readOnlyProperty.get());
221 publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
222
223 // set value twice without reading
224 property.set(VALUE_2);
225 property.set(VALUE_1);
226 assertEquals(VALUE_1, property.get());
227 property.check(2);
228 assertEquals(VALUE_1, readOnlyProperty.get());
229 publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
230 }
231
232 @Test
233 public void testLazySetValue() {
234 attachInvalidationListeners();
235
236 // set value once
237 property.setValue(VALUE_1);
238 assertEquals(VALUE_1, property.get());
239 property.check(1);
240 internalInvalidationListener.check(readOnlyProperty, 1);
241 assertEquals(VALUE_1, readOnlyProperty.get());
242 publicInvalidationListener.check(readOnlyProperty, 1);
243
244 // set same value again
245 property.setValue(VALUE_1);
246 assertEquals(VALUE_1, property.get());
247 property.check(0);
248 internalInvalidationListener.check(null, 0);
249 assertEquals(VALUE_1, readOnlyProperty.get());
250 publicInvalidationListener.check(null, 0);
251
252 // set value twice without reading
253 property.setValue(VALUE_2);
254 property.setValue(VALUE_1);
255 assertEquals(VALUE_1, property.get());
256 property.check(1);
257 internalInvalidationListener.check(readOnlyProperty, 1);
258 assertEquals(VALUE_1, readOnlyProperty.get());
259 publicInvalidationListener.check(readOnlyProperty, 1);
260 }
261
262 @Test
263 public void testInternalEagerSetValue() {
264 attachInternalChangeListener();
265
266 // set value once
267 property.setValue(VALUE_1);
268 assertEquals(VALUE_1, property.get());
269 property.check(1);
270 internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
271 assertEquals(VALUE_1, readOnlyProperty.get());
272
273 // set same value again
274 property.setValue(VALUE_1);
275 assertEquals(VALUE_1, property.get());
276 property.check(0);
277 internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
278 assertEquals(VALUE_1, readOnlyProperty.get());
279
280 // set value twice without reading
281 property.setValue(VALUE_2);
282 property.setValue(VALUE_1);
283 assertEquals(VALUE_1, property.get());
284 property.check(2);
285 internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
286 assertEquals(VALUE_1, readOnlyProperty.get());
287 }
288
289 @Test
290 public void testPublicEagerSetValue() {
291 attachPublicChangeListener();
292
293 // set value once
294 property.setValue(VALUE_1);
295 assertEquals(VALUE_1, property.get());
296 property.check(1);
297 assertEquals(VALUE_1, readOnlyProperty.get());
298 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
299
300 // set same value again
301 property.setValue(VALUE_1);
302 assertEquals(VALUE_1, property.get());
303 property.check(0);
304 assertEquals(VALUE_1, readOnlyProperty.get());
305 publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
312 assertEquals(VALUE_1, readOnlyProperty.get());
313 publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
314 }
315
316 @Test(expected=RuntimeException.class)
317 public void testSetBoundValue() {
318 final SetProperty<Object> v = new SimpleSetProperty<Object>(VALUE_1);
319 property.bind(v);
320 property.set(VALUE_1);
321 }
322
323 @Test
324 public void testLazyBind_primitive() {
325 attachInvalidationListeners();
326 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
327
328 property.bind(v);
329 assertEquals(VALUE_1, property.get());
330 assertTrue(property.isBound());
331 property.check(1);
332 internalInvalidationListener.check(readOnlyProperty, 1);
333 assertEquals(VALUE_1, readOnlyProperty.get());
334 publicInvalidationListener.check(readOnlyProperty, 1);
335
336 // change binding once
337 v.set(VALUE_2);
338 assertEquals(VALUE_2, property.get());
339 property.check(1);
340 internalInvalidationListener.check(readOnlyProperty, 1);
341 assertEquals(VALUE_2, readOnlyProperty.get());
342 publicInvalidationListener.check(readOnlyProperty, 1);
343
344 // change binding twice without reading
345 v.set(VALUE_1);
346 v.set(VALUE_2);
347 assertEquals(VALUE_2, property.get());
348 property.check(1);
349 internalInvalidationListener.check(readOnlyProperty, 1);
350 assertEquals(VALUE_2, readOnlyProperty.get());
351 publicInvalidationListener.check(readOnlyProperty, 1);
352
353 // change binding twice to same value
354 v.set(VALUE_1);
355 v.set(VALUE_1);
356 assertEquals(VALUE_1, property.get());
357 property.check(1);
358 internalInvalidationListener.check(readOnlyProperty, 1);
359 assertEquals(VALUE_1, readOnlyProperty.get());
360 publicInvalidationListener.check(readOnlyProperty, 1);
361 }
362
363 @Test
364 public void testInternalEagerBind_primitive() {
365 attachInternalChangeListener();
366 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
367
368 property.bind(v);
369 assertEquals(VALUE_1, property.get());
370 assertTrue(property.isBound());
371 property.check(1);
372 internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
373 assertEquals(VALUE_1, readOnlyProperty.get());
374
375 // change binding once
376 v.set(VALUE_2);
377 assertEquals(VALUE_2, property.get());
378 property.check(1);
379 internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1);
380 assertEquals(VALUE_2, readOnlyProperty.get());
381
382 // change binding twice without reading
383 v.set(VALUE_1);
384 v.set(VALUE_2);
385 assertEquals(VALUE_2, property.get());
386 property.check(2);
387 internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
388 assertEquals(VALUE_2, readOnlyProperty.get());
389
390 // change binding twice to same value
391 v.set(VALUE_1);
392 v.set(VALUE_1);
393 assertEquals(VALUE_1, property.get());
394 property.check(2);
395 internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
396 assertEquals(VALUE_1, readOnlyProperty.get());
397 }
398
399 @Test
400 public void testPublicEagerBind_primitive() {
401 attachPublicChangeListener();
402 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
403
404 property.bind(v);
405 assertEquals(VALUE_1, property.get());
406 assertTrue(property.isBound());
407 property.check(1);
408 assertEquals(VALUE_1, readOnlyProperty.get());
409 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
410
411 // change binding once
412 v.set(VALUE_2);
413 assertEquals(VALUE_2, property.get());
414 property.check(1);
415 assertEquals(VALUE_2, readOnlyProperty.get());
424 publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
425
426 // change binding twice to same value
427 v.set(VALUE_1);
428 v.set(VALUE_1);
429 assertEquals(VALUE_1, property.get());
430 property.check(2);
431 assertEquals(VALUE_1, readOnlyProperty.get());
432 publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
433 }
434
435 @Test
436 public void testLazyBind_generic() {
437 attachInvalidationListeners();
438 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
439
440 property.bind(v);
441 assertEquals(VALUE_1, property.get());
442 assertTrue(property.isBound());
443 property.check(1);
444 internalInvalidationListener.check(readOnlyProperty, 1);
445 assertEquals(VALUE_1, readOnlyProperty.get());
446 publicInvalidationListener.check(readOnlyProperty, 1);
447
448 // change binding once
449 v.set(VALUE_2);
450 assertEquals(VALUE_2, property.get());
451 property.check(1);
452 internalInvalidationListener.check(readOnlyProperty, 1);
453 assertEquals(VALUE_2, readOnlyProperty.get());
454 publicInvalidationListener.check(readOnlyProperty, 1);
455
456 // change binding twice without reading
457 v.set(VALUE_1);
458 v.set(VALUE_2);
459 assertEquals(VALUE_2, property.get());
460 property.check(1);
461 internalInvalidationListener.check(readOnlyProperty, 1);
462 assertEquals(VALUE_2, readOnlyProperty.get());
463 publicInvalidationListener.check(readOnlyProperty, 1);
464
465 // change binding twice to same value
466 v.set(VALUE_1);
467 v.set(VALUE_1);
468 assertEquals(VALUE_1, property.get());
469 property.check(1);
470 internalInvalidationListener.check(readOnlyProperty, 1);
471 assertEquals(VALUE_1, readOnlyProperty.get());
472 publicInvalidationListener.check(readOnlyProperty, 1);
473 }
474
475 @Test
476 public void testInternalEagerBind_generic() {
477 attachInternalChangeListener();
478 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
479
480 property.bind(v);
481 assertEquals(VALUE_1, property.get());
482 assertTrue(property.isBound());
483 property.check(1);
484 internalChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
485 assertEquals(VALUE_1, readOnlyProperty.get());
486
487 // change binding once
488 v.set(VALUE_2);
489 assertEquals(VALUE_2, property.get());
490 property.check(1);
491 internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1);
492 assertEquals(VALUE_2, readOnlyProperty.get());
493
494 // change binding twice without reading
495 v.set(VALUE_1);
496 v.set(VALUE_2);
497 assertEquals(VALUE_2, property.get());
498 property.check(2);
499 internalChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
500 assertEquals(VALUE_2, readOnlyProperty.get());
501
502 // change binding twice to same value
503 v.set(VALUE_1);
504 v.set(VALUE_1);
505 assertEquals(VALUE_1, property.get());
506 property.check(2);
507 internalChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
508 assertEquals(VALUE_1, readOnlyProperty.get());
509 }
510
511 @Test
512 public void testPublicEagerBind_generic() {
513 attachPublicChangeListener();
514 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
515
516 property.bind(v);
517 assertEquals(VALUE_1, property.get());
518 assertTrue(property.isBound());
519 property.check(1);
520 assertEquals(VALUE_1, readOnlyProperty.get());
521 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
522
523 // change binding once
524 v.set(VALUE_2);
525 assertEquals(VALUE_2, property.get());
526 property.check(1);
527 assertEquals(VALUE_2, readOnlyProperty.get());
549 property.bind(null);
550 }
551
552 @Test
553 public void testRebind() {
554 attachInvalidationListeners();
555 final SetProperty<Object> v1 = new SimpleSetProperty<Object>(VALUE_1);
556 final SetProperty<Object> v2 = new SimpleSetProperty<Object>(VALUE_2);
557 property.bind(v1);
558 property.get();
559 readOnlyProperty.get();
560 property.reset();
561 internalInvalidationListener.reset();
562 publicInvalidationListener.reset();
563
564 // rebind causes invalidation event
565 property.bind(v2);
566 assertEquals(VALUE_2, property.get());
567 assertTrue(property.isBound());
568 property.check(1);
569 internalInvalidationListener.check(readOnlyProperty, 1);
570 assertEquals(VALUE_2, readOnlyProperty.get());
571 publicInvalidationListener.check(readOnlyProperty, 1);
572
573 // change new binding
574 v2.set(VALUE_1);
575 assertEquals(VALUE_1, property.get());
576 property.check(1);
577 internalInvalidationListener.check(readOnlyProperty, 1);
578 assertEquals(VALUE_1, readOnlyProperty.get());
579 publicInvalidationListener.check(readOnlyProperty, 1);
580
581 // change old binding
582 v1.set(VALUE_2);
583 assertEquals(VALUE_1, property.get());
584 property.check(0);
585 internalInvalidationListener.check(null, 0);
586 assertEquals(VALUE_1, readOnlyProperty.get());
587 publicInvalidationListener.check(null, 0);
588
589 // rebind to same observable should have no effect
590 property.bind(v2);
591 assertEquals(VALUE_1, property.get());
592 assertTrue(property.isBound());
593 property.check(0);
594 internalInvalidationListener.check(null, 0);
595 assertEquals(VALUE_1, readOnlyProperty.get());
596 publicInvalidationListener.check(null, 0);
597 }
604 property.unbind();
605 assertEquals(VALUE_1, property.get());
606 assertFalse(property.isBound());
607 assertEquals(VALUE_1, readOnlyProperty.get());
608 property.reset();
609 internalInvalidationListener.reset();
610 publicInvalidationListener.reset();
611
612 // change binding
613 v.set(VALUE_2);
614 assertEquals(VALUE_1, property.get());
615 property.check(0);
616 internalInvalidationListener.check(null, 0);
617 assertEquals(VALUE_1, readOnlyProperty.get());
618 publicInvalidationListener.check(null, 0);
619
620 // set value
621 property.set(VALUE_2);
622 assertEquals(VALUE_2, property.get());
623 property.check(1);
624 internalInvalidationListener.check(readOnlyProperty, 1);
625 assertEquals(VALUE_2, readOnlyProperty.get());
626 publicInvalidationListener.check(readOnlyProperty, 1);
627 }
628
629 @Test
630 public void testAddingListenerWillAlwaysReceiveInvalidationEvent() {
631 final SetProperty<Object> v = new SimpleSetProperty<Object>(VALUE_1);
632 final InvalidationListenerMock internalListener2 = new InvalidationListenerMock();
633 final InvalidationListenerMock internalListener3 = new InvalidationListenerMock();
634 final InvalidationListenerMock publicListener2 = new InvalidationListenerMock();
635 final InvalidationListenerMock publicListener3 = new InvalidationListenerMock();
636
637 // setting the property,checking internal
638 property.set(VALUE_1);
639 property.addListener(internalListener2);
640 internalListener2.reset();
641 property.set(VALUE_2);
642 internalListener2.check(readOnlyProperty, 1);
643
644 // setting the property, checking public
645 property.set(VALUE_1);
646 readOnlyProperty.addListener(publicListener2);
647 publicListener2.reset();
648 property.set(VALUE_2);
649 publicListener2.check(readOnlyProperty, 1);
650
651 // binding the property, checking internal
652 property.bind(v);
653 v.set(VALUE_2);
654 property.addListener(internalListener3);
655 v.get();
656 internalListener3.reset();
657 v.set(VALUE_1);
658 internalListener3.check(readOnlyProperty, 1);
659
660 // binding the property, checking public
661 property.bind(v);
662 v.set(VALUE_2);
663 readOnlyProperty.addListener(publicListener3);
664 v.get();
665 publicListener3.reset();
666 v.set(VALUE_1);
667 publicListener3.check(readOnlyProperty, 1);
668 }
669
670 @Test
671 public void testRemoveListeners() {
672 attachInvalidationListeners();
673 attachInternalChangeListener();
674 property.removeListener(internalInvalidationListener);
675 property.removeListener(internalChangeListener);
676 property.get();
677 internalInvalidationListener.reset();
678 internalChangeListener.reset();
|
136 assertEquals(VALUE_1, p1.get());
137 assertEquals((Object)VALUE_1, p1.getValue());
138 assertFalse(property.isBound());
139 assertEquals(bean, p1.getBean());
140 assertEquals(name, p1.getName());
141 final ReadOnlySetProperty<Object> r1 = p1.getReadOnlyProperty();
142 assertEquals(VALUE_1, r1.get());
143 assertEquals((Object)VALUE_1, r1.getValue());
144 assertEquals(bean, r1.getBean());
145 assertEquals(name, r1.getName());
146 }
147
148 @Test
149 public void testLazySet() {
150 attachInvalidationListeners();
151
152 // set value once
153 property.set(VALUE_1);
154 assertEquals(VALUE_1, property.get());
155 property.check(1);
156 internalInvalidationListener.check(property, 1);
157 assertEquals(VALUE_1, readOnlyProperty.get());
158 publicInvalidationListener.check(readOnlyProperty, 1);
159
160 // set same value again
161 property.set(VALUE_1);
162 assertEquals(VALUE_1, property.get());
163 property.check(0);
164 internalInvalidationListener.check(null, 0);
165 assertEquals(VALUE_1, readOnlyProperty.get());
166 publicInvalidationListener.check(null, 0);
167
168 // set value twice without reading
169 property.set(VALUE_2);
170 property.set(VALUE_1);
171 assertEquals(VALUE_1, property.get());
172 property.check(1);
173 internalInvalidationListener.check(property, 1);
174 assertEquals(VALUE_1, readOnlyProperty.get());
175 publicInvalidationListener.check(readOnlyProperty, 1);
176 }
177
178 @Test
179 public void testInternalEagerSet() {
180 attachInternalChangeListener();
181
182 // set value once
183 property.set(VALUE_1);
184 assertEquals(VALUE_1, property.get());
185 property.check(1);
186 internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
187 assertEquals(VALUE_1, readOnlyProperty.get());
188
189 // set same value again
190 property.set(VALUE_1);
191 assertEquals(VALUE_1, property.get());
192 property.check(0);
193 internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
194 assertEquals(VALUE_1, readOnlyProperty.get());
195
196 // set value twice without reading
197 property.set(VALUE_2);
198 property.set(VALUE_1);
199 assertEquals(VALUE_1, property.get());
200 property.check(2);
201 internalChangeListener.check(property, VALUE_2, VALUE_1, 2);
202 assertEquals(VALUE_1, readOnlyProperty.get());
203 }
204
205 @Test
206 public void testPublicEagerSet() {
207 attachPublicChangeListener();
208
209 // set value once
210 property.set(VALUE_1);
211 assertEquals(VALUE_1, property.get());
212 property.check(1);
213 assertEquals(VALUE_1, readOnlyProperty.get());
214 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
215
216 // set same value again
217 property.set(VALUE_1);
218 assertEquals(VALUE_1, property.get());
219 property.check(0);
220 assertEquals(VALUE_1, readOnlyProperty.get());
221 publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
222
223 // set value twice without reading
224 property.set(VALUE_2);
225 property.set(VALUE_1);
226 assertEquals(VALUE_1, property.get());
227 property.check(2);
228 assertEquals(VALUE_1, readOnlyProperty.get());
229 publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
230 }
231
232 @Test
233 public void testLazySetValue() {
234 attachInvalidationListeners();
235
236 // set value once
237 property.setValue(VALUE_1);
238 assertEquals(VALUE_1, property.get());
239 property.check(1);
240 internalInvalidationListener.check(property, 1);
241 assertEquals(VALUE_1, readOnlyProperty.get());
242 publicInvalidationListener.check(readOnlyProperty, 1);
243
244 // set same value again
245 property.setValue(VALUE_1);
246 assertEquals(VALUE_1, property.get());
247 property.check(0);
248 internalInvalidationListener.check(null, 0);
249 assertEquals(VALUE_1, readOnlyProperty.get());
250 publicInvalidationListener.check(null, 0);
251
252 // set value twice without reading
253 property.setValue(VALUE_2);
254 property.setValue(VALUE_1);
255 assertEquals(VALUE_1, property.get());
256 property.check(1);
257 internalInvalidationListener.check(property, 1);
258 assertEquals(VALUE_1, readOnlyProperty.get());
259 publicInvalidationListener.check(readOnlyProperty, 1);
260 }
261
262 @Test
263 public void testInternalEagerSetValue() {
264 attachInternalChangeListener();
265
266 // set value once
267 property.setValue(VALUE_1);
268 assertEquals(VALUE_1, property.get());
269 property.check(1);
270 internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
271 assertEquals(VALUE_1, readOnlyProperty.get());
272
273 // set same value again
274 property.setValue(VALUE_1);
275 assertEquals(VALUE_1, property.get());
276 property.check(0);
277 internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
278 assertEquals(VALUE_1, readOnlyProperty.get());
279
280 // set value twice without reading
281 property.setValue(VALUE_2);
282 property.setValue(VALUE_1);
283 assertEquals(VALUE_1, property.get());
284 property.check(2);
285 internalChangeListener.check(property, VALUE_2, VALUE_1, 2);
286 assertEquals(VALUE_1, readOnlyProperty.get());
287 }
288
289 @Test
290 public void testPublicEagerSetValue() {
291 attachPublicChangeListener();
292
293 // set value once
294 property.setValue(VALUE_1);
295 assertEquals(VALUE_1, property.get());
296 property.check(1);
297 assertEquals(VALUE_1, readOnlyProperty.get());
298 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
299
300 // set same value again
301 property.setValue(VALUE_1);
302 assertEquals(VALUE_1, property.get());
303 property.check(0);
304 assertEquals(VALUE_1, readOnlyProperty.get());
305 publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0);
312 assertEquals(VALUE_1, readOnlyProperty.get());
313 publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2);
314 }
315
316 @Test(expected=RuntimeException.class)
317 public void testSetBoundValue() {
318 final SetProperty<Object> v = new SimpleSetProperty<Object>(VALUE_1);
319 property.bind(v);
320 property.set(VALUE_1);
321 }
322
323 @Test
324 public void testLazyBind_primitive() {
325 attachInvalidationListeners();
326 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
327
328 property.bind(v);
329 assertEquals(VALUE_1, property.get());
330 assertTrue(property.isBound());
331 property.check(1);
332 internalInvalidationListener.check(property, 1);
333 assertEquals(VALUE_1, readOnlyProperty.get());
334 publicInvalidationListener.check(readOnlyProperty, 1);
335
336 // change binding once
337 v.set(VALUE_2);
338 assertEquals(VALUE_2, property.get());
339 property.check(1);
340 internalInvalidationListener.check(property, 1);
341 assertEquals(VALUE_2, readOnlyProperty.get());
342 publicInvalidationListener.check(readOnlyProperty, 1);
343
344 // change binding twice without reading
345 v.set(VALUE_1);
346 v.set(VALUE_2);
347 assertEquals(VALUE_2, property.get());
348 property.check(1);
349 internalInvalidationListener.check(property, 1);
350 assertEquals(VALUE_2, readOnlyProperty.get());
351 publicInvalidationListener.check(readOnlyProperty, 1);
352
353 // change binding twice to same value
354 v.set(VALUE_1);
355 v.set(VALUE_1);
356 assertEquals(VALUE_1, property.get());
357 property.check(1);
358 internalInvalidationListener.check(property, 1);
359 assertEquals(VALUE_1, readOnlyProperty.get());
360 publicInvalidationListener.check(readOnlyProperty, 1);
361 }
362
363 @Test
364 public void testInternalEagerBind_primitive() {
365 attachInternalChangeListener();
366 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
367
368 property.bind(v);
369 assertEquals(VALUE_1, property.get());
370 assertTrue(property.isBound());
371 property.check(1);
372 internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
373 assertEquals(VALUE_1, readOnlyProperty.get());
374
375 // change binding once
376 v.set(VALUE_2);
377 assertEquals(VALUE_2, property.get());
378 property.check(1);
379 internalChangeListener.check(property, VALUE_1, VALUE_2, 1);
380 assertEquals(VALUE_2, readOnlyProperty.get());
381
382 // change binding twice without reading
383 v.set(VALUE_1);
384 v.set(VALUE_2);
385 assertEquals(VALUE_2, property.get());
386 property.check(2);
387 internalChangeListener.check(property, VALUE_1, VALUE_2, 2);
388 assertEquals(VALUE_2, readOnlyProperty.get());
389
390 // change binding twice to same value
391 v.set(VALUE_1);
392 v.set(VALUE_1);
393 assertEquals(VALUE_1, property.get());
394 property.check(2);
395 internalChangeListener.check(property, VALUE_2, VALUE_1, 1);
396 assertEquals(VALUE_1, readOnlyProperty.get());
397 }
398
399 @Test
400 public void testPublicEagerBind_primitive() {
401 attachPublicChangeListener();
402 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
403
404 property.bind(v);
405 assertEquals(VALUE_1, property.get());
406 assertTrue(property.isBound());
407 property.check(1);
408 assertEquals(VALUE_1, readOnlyProperty.get());
409 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
410
411 // change binding once
412 v.set(VALUE_2);
413 assertEquals(VALUE_2, property.get());
414 property.check(1);
415 assertEquals(VALUE_2, readOnlyProperty.get());
424 publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2);
425
426 // change binding twice to same value
427 v.set(VALUE_1);
428 v.set(VALUE_1);
429 assertEquals(VALUE_1, property.get());
430 property.check(2);
431 assertEquals(VALUE_1, readOnlyProperty.get());
432 publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1);
433 }
434
435 @Test
436 public void testLazyBind_generic() {
437 attachInvalidationListeners();
438 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
439
440 property.bind(v);
441 assertEquals(VALUE_1, property.get());
442 assertTrue(property.isBound());
443 property.check(1);
444 internalInvalidationListener.check(property, 1);
445 assertEquals(VALUE_1, readOnlyProperty.get());
446 publicInvalidationListener.check(readOnlyProperty, 1);
447
448 // change binding once
449 v.set(VALUE_2);
450 assertEquals(VALUE_2, property.get());
451 property.check(1);
452 internalInvalidationListener.check(property, 1);
453 assertEquals(VALUE_2, readOnlyProperty.get());
454 publicInvalidationListener.check(readOnlyProperty, 1);
455
456 // change binding twice without reading
457 v.set(VALUE_1);
458 v.set(VALUE_2);
459 assertEquals(VALUE_2, property.get());
460 property.check(1);
461 internalInvalidationListener.check(property, 1);
462 assertEquals(VALUE_2, readOnlyProperty.get());
463 publicInvalidationListener.check(readOnlyProperty, 1);
464
465 // change binding twice to same value
466 v.set(VALUE_1);
467 v.set(VALUE_1);
468 assertEquals(VALUE_1, property.get());
469 property.check(1);
470 internalInvalidationListener.check(property, 1);
471 assertEquals(VALUE_1, readOnlyProperty.get());
472 publicInvalidationListener.check(readOnlyProperty, 1);
473 }
474
475 @Test
476 public void testInternalEagerBind_generic() {
477 attachInternalChangeListener();
478 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
479
480 property.bind(v);
481 assertEquals(VALUE_1, property.get());
482 assertTrue(property.isBound());
483 property.check(1);
484 internalChangeListener.check(property, DEFAULT, VALUE_1, 1);
485 assertEquals(VALUE_1, readOnlyProperty.get());
486
487 // change binding once
488 v.set(VALUE_2);
489 assertEquals(VALUE_2, property.get());
490 property.check(1);
491 internalChangeListener.check(property, VALUE_1, VALUE_2, 1);
492 assertEquals(VALUE_2, readOnlyProperty.get());
493
494 // change binding twice without reading
495 v.set(VALUE_1);
496 v.set(VALUE_2);
497 assertEquals(VALUE_2, property.get());
498 property.check(2);
499 internalChangeListener.check(property, VALUE_1, VALUE_2, 2);
500 assertEquals(VALUE_2, readOnlyProperty.get());
501
502 // change binding twice to same value
503 v.set(VALUE_1);
504 v.set(VALUE_1);
505 assertEquals(VALUE_1, property.get());
506 property.check(2);
507 internalChangeListener.check(property, VALUE_2, VALUE_1, 1);
508 assertEquals(VALUE_1, readOnlyProperty.get());
509 }
510
511 @Test
512 public void testPublicEagerBind_generic() {
513 attachPublicChangeListener();
514 final ObservableObjectValueStub<ObservableSet<Object>> v = new ObservableObjectValueStub<ObservableSet<Object>>(VALUE_1);
515
516 property.bind(v);
517 assertEquals(VALUE_1, property.get());
518 assertTrue(property.isBound());
519 property.check(1);
520 assertEquals(VALUE_1, readOnlyProperty.get());
521 publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1);
522
523 // change binding once
524 v.set(VALUE_2);
525 assertEquals(VALUE_2, property.get());
526 property.check(1);
527 assertEquals(VALUE_2, readOnlyProperty.get());
549 property.bind(null);
550 }
551
552 @Test
553 public void testRebind() {
554 attachInvalidationListeners();
555 final SetProperty<Object> v1 = new SimpleSetProperty<Object>(VALUE_1);
556 final SetProperty<Object> v2 = new SimpleSetProperty<Object>(VALUE_2);
557 property.bind(v1);
558 property.get();
559 readOnlyProperty.get();
560 property.reset();
561 internalInvalidationListener.reset();
562 publicInvalidationListener.reset();
563
564 // rebind causes invalidation event
565 property.bind(v2);
566 assertEquals(VALUE_2, property.get());
567 assertTrue(property.isBound());
568 property.check(1);
569 internalInvalidationListener.check(property, 1);
570 assertEquals(VALUE_2, readOnlyProperty.get());
571 publicInvalidationListener.check(readOnlyProperty, 1);
572
573 // change new binding
574 v2.set(VALUE_1);
575 assertEquals(VALUE_1, property.get());
576 property.check(1);
577 internalInvalidationListener.check(property, 1);
578 assertEquals(VALUE_1, readOnlyProperty.get());
579 publicInvalidationListener.check(readOnlyProperty, 1);
580
581 // change old binding
582 v1.set(VALUE_2);
583 assertEquals(VALUE_1, property.get());
584 property.check(0);
585 internalInvalidationListener.check(null, 0);
586 assertEquals(VALUE_1, readOnlyProperty.get());
587 publicInvalidationListener.check(null, 0);
588
589 // rebind to same observable should have no effect
590 property.bind(v2);
591 assertEquals(VALUE_1, property.get());
592 assertTrue(property.isBound());
593 property.check(0);
594 internalInvalidationListener.check(null, 0);
595 assertEquals(VALUE_1, readOnlyProperty.get());
596 publicInvalidationListener.check(null, 0);
597 }
604 property.unbind();
605 assertEquals(VALUE_1, property.get());
606 assertFalse(property.isBound());
607 assertEquals(VALUE_1, readOnlyProperty.get());
608 property.reset();
609 internalInvalidationListener.reset();
610 publicInvalidationListener.reset();
611
612 // change binding
613 v.set(VALUE_2);
614 assertEquals(VALUE_1, property.get());
615 property.check(0);
616 internalInvalidationListener.check(null, 0);
617 assertEquals(VALUE_1, readOnlyProperty.get());
618 publicInvalidationListener.check(null, 0);
619
620 // set value
621 property.set(VALUE_2);
622 assertEquals(VALUE_2, property.get());
623 property.check(1);
624 internalInvalidationListener.check(property, 1);
625 assertEquals(VALUE_2, readOnlyProperty.get());
626 publicInvalidationListener.check(readOnlyProperty, 1);
627 }
628
629 @Test
630 public void testAddingListenerWillAlwaysReceiveInvalidationEvent() {
631 final SetProperty<Object> v = new SimpleSetProperty<Object>(VALUE_1);
632 final InvalidationListenerMock internalListener2 = new InvalidationListenerMock();
633 final InvalidationListenerMock internalListener3 = new InvalidationListenerMock();
634 final InvalidationListenerMock publicListener2 = new InvalidationListenerMock();
635 final InvalidationListenerMock publicListener3 = new InvalidationListenerMock();
636
637 // setting the property,checking internal
638 property.set(VALUE_1);
639 property.addListener(internalListener2);
640 internalListener2.reset();
641 property.set(VALUE_2);
642 internalListener2.check(property, 1);
643
644 // setting the property, checking public
645 property.set(VALUE_1);
646 readOnlyProperty.addListener(publicListener2);
647 publicListener2.reset();
648 property.set(VALUE_2);
649 publicListener2.check(readOnlyProperty, 1);
650
651 // binding the property, checking internal
652 property.bind(v);
653 v.set(VALUE_2);
654 property.addListener(internalListener3);
655 v.get();
656 internalListener3.reset();
657 v.set(VALUE_1);
658 internalListener3.check(property, 1);
659
660 // binding the property, checking public
661 property.bind(v);
662 v.set(VALUE_2);
663 readOnlyProperty.addListener(publicListener3);
664 v.get();
665 publicListener3.reset();
666 v.set(VALUE_1);
667 publicListener3.check(readOnlyProperty, 1);
668 }
669
670 @Test
671 public void testRemoveListeners() {
672 attachInvalidationListeners();
673 attachInternalChangeListener();
674 property.removeListener(internalInvalidationListener);
675 property.removeListener(internalChangeListener);
676 property.get();
677 internalInvalidationListener.reset();
678 internalChangeListener.reset();
|