1 /* 2 * Copyright (c) 2012, 2013, 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 test.com.sun.javafx.property.adapter;//package com.sun.javafx.property.adapter; 27 // 28 //import javafx.beans.property.ObjectProperty; 29 //import javafx.beans.property.adapter.JavaBeanObjectProperty; 30 //import org.junit.Before; 31 //import org.junit.Test; 32 // 33 //import java.beans.*; 34 //import java.lang.reflect.Method; 35 //import java.util.ArrayList; 36 //import java.util.List; 37 // 38 //import static org.junit.Assert.assertEquals; 39 //import static org.junit.Assert.fail; 40 // 41 ///** 42 //*/ 43 //public class PropertyDescriptorTest { 44 // 45 // @Before 46 // public void setUp() { 47 // } 48 // 49 // @Test 50 // public void testSetup() throws NoSuchMethodException { 51 // final Object initialValue = new Object(); 52 // final Object secondValue = new Object(); 53 // final POJOBean bean = new POJOBean(initialValue); 54 // helperPOJOBean.bean(bean); 55 // final ObjectProperty<Object> property = new JavaBeanObjectProperty<Object>(helperPOJOBean.getDescriptor(), bean); 56 // assertEquals(initialValue, property.get()); 57 // property.set(secondValue); 58 // assertEquals(secondValue, bean.getX()); 59 // assertEquals(secondValue, property.get()); 60 // } 61 // 62 // @Test(expected = NullPointerException.class) 63 // public void testSetup_WithNameIsNull() { 64 // try { 65 // helperPOJOBean.name(null); 66 // helperPOJOBean.getDescriptor(); 67 // } catch (NoSuchMethodException e) { 68 // fail(); 69 // } 70 // } 71 // 72 // @Test(expected = IllegalArgumentException.class) 73 // public void testSetup_WithNameIsEmpty() { 74 // try { 75 // helperPOJOBean.name(""); 76 // helperPOJOBean.getDescriptor(); 77 // } catch (NoSuchMethodException e) { 78 // fail(); 79 // } 80 // } 81 // 82 // @Test(expected = NullPointerException.class) 83 // public void testSetup_WithBeanClassIsNull() { 84 // try { 85 // helperPOJOBean.beanClass(null); 86 // helperPOJOBean.getDescriptor(); 87 // } catch (NoSuchMethodException e) { 88 // fail(); 89 // } 90 // } 91 // 92 // @Test 93 // public void testSetup_WithNonStandardNames() { 94 // final Object initialValue = new Object(); 95 // final Object secondValue = new Object(); 96 // final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); 97 // helperPOJOBeanWithNonStandardNames.bean(bean); 98 // final ObjectProperty<Object> property = builder.createObjectProperty(bean); 99 // assertEquals(initialValue, property.get()); 100 // property.set(secondValue); 101 // assertEquals(secondValue, bean.readX()); 102 // assertEquals(secondValue, property.get()); 103 // } 104 // 105 // @Test(expected = NullPointerException.class) 106 // public void testSetup_WithNonStandardNames_WithNameIsNull() { 107 // try { 108 // helperPOJOBeanWithNonStandardNames.name(null); 109 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 110 // } catch (NoSuchMethodException e) { 111 // fail(); 112 // } 113 // } 114 // 115 // @Test(expected = NullPointerException.class) 116 // public void testSetup_WithNonStandardNames_WithBeanClassIsNull() { 117 // try { 118 // helperPOJOBeanWithNonStandardNames.beanClass(null); 119 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 120 // } catch (NoSuchMethodException e) { 121 // fail(); 122 // } 123 // } 124 // 125 // @Test(expected = NoSuchMethodException.class) 126 // public void testSetup_WithNonStandardNames_WithGetterNameIsNull() throws NoSuchMethodException { 127 // helperPOJOBeanWithNonStandardNames.getterName(null); 128 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 129 // } 130 // 131 // @Test(expected = NoSuchMethodException.class) 132 // public void testSetup_WithNonStandardNames_WithSetterNameIsNull() throws NoSuchMethodException { 133 // helperPOJOBeanWithNonStandardNames.setterName(null); 134 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 135 // } 136 // 137 // @Test(expected = IllegalArgumentException.class) 138 // public void testSetup_WithNonStandardNames_WithNameIsEmpty() { 139 // try { 140 // helperPOJOBeanWithNonStandardNames.name(""); 141 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 142 // } catch (NoSuchMethodException e) { 143 // fail(); 144 // } 145 // } 146 // 147 // @Test(expected = NoSuchMethodException.class) 148 // public void testSetup_WithNonStandardNames_WithGetterNameIsEmpty() throws NoSuchMethodException { 149 // helperPOJOBeanWithNonStandardNames.getterName(""); 150 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 151 // } 152 // 153 // @Test(expected = NoSuchMethodException.class) 154 // public void testSetup_WithNonStandardNames_WithSetterNameIsEmpty() throws NoSuchMethodException { 155 // helperPOJOBeanWithNonStandardNames.setterName(""); 156 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 157 // } 158 // 159 //// @Test 160 //// public void testSetup_WithNonStandardAccessors() { 161 //// JavaBeanPropertyBuilder builder = null; 162 //// try { 163 //// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); 164 //// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); 165 //// builder = new JavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, getter, setter); 166 //// } catch (NoSuchMethodException e) { 167 //// fail("Error in test code. Should not happen."); 168 //// } 169 //// final Object initialValue = new Object(); 170 //// final Object secondValue = new Object(); 171 //// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); 172 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 173 //// assertEquals(initialValue, property.get()); 174 //// property.set(secondValue); 175 //// assertEquals(secondValue, bean.readX()); 176 //// assertEquals(secondValue, property.get()); 177 //// } 178 // 179 // @Test(expected = NullPointerException.class) 180 // public void testSetup_WithNonStandardAccessors_WithNameIsNull() throws NoSuchMethodException { 181 // helperPOJOBeanWithNonStandardNames.getterName(null); 182 // helperPOJOBeanWithNonStandardNames.setterName(null); 183 // try { 184 // final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); 185 // final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); 186 // helperPOJOBeanWithNonStandardNames.getter(getter); 187 // helperPOJOBeanWithNonStandardNames.setter(setter); 188 // 189 // helperPOJOBeanWithNonStandardNames.name(null); 190 // } catch (NoSuchMethodException e) { 191 // fail("Error in test code. Should not happen."); 192 // } 193 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 194 // } 195 // 196 // @Test(expected = NoSuchMethodException.class) 197 // public void testSetup_WithNonStandardAccessors_WithGetterIsNull() throws NoSuchMethodException { 198 // helperPOJOBeanWithNonStandardNames.getterName(null); 199 // helperPOJOBeanWithNonStandardNames.setterName(null); 200 // try { 201 // final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); 202 // helperPOJOBeanWithNonStandardNames.setter(setter); 203 // 204 // helperPOJOBeanWithNonStandardNames.getter(null); 205 // } catch (NoSuchMethodException e) { 206 // fail("Error in test code. Should not happen."); 207 // } 208 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 209 // } 210 // 211 // @Test(expected = NoSuchMethodException.class) 212 // public void testSetup_WithNonStandardAccessors_WithSetterIsNull() throws NoSuchMethodException { 213 // helperPOJOBeanWithNonStandardNames.getterName(null); 214 // helperPOJOBeanWithNonStandardNames.setterName(null); 215 // try { 216 // final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); 217 // helperPOJOBeanWithNonStandardNames.getter(getter); 218 // 219 // helperPOJOBeanWithNonStandardNames.setter(null); 220 // } catch (NoSuchMethodException e) { 221 // fail("Error in test code. Should not happen."); 222 // } 223 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 224 // } 225 // 226 // @Test(expected = IllegalArgumentException.class) 227 // public void testSetup_WithNonStandardAccessors_WithNameIsEmpty() throws NoSuchMethodException { 228 // helperPOJOBeanWithNonStandardNames.getterName(null); 229 // helperPOJOBeanWithNonStandardNames.setterName(null); 230 // try { 231 // final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); 232 // final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); 233 // helperPOJOBeanWithNonStandardNames.getter(getter); 234 // helperPOJOBeanWithNonStandardNames.setter(setter); 235 // 236 // helperPOJOBeanWithNonStandardNames.name(""); 237 // } catch (NoSuchMethodException e) { 238 // fail("Error in test code. Should not happen."); 239 // } 240 // helperPOJOBeanWithNonStandardNames.getDescriptor(); 241 // } 242 // 243 //// @Test(expected = IllegalArgumentException.class) 244 //// public void testCreatePropertyWithWrongType_Boolean() { 245 //// final POJOBean bean = new POJOBean(new Object()); 246 //// JavaBeanPropertyBuilder builder = null; 247 //// try { 248 //// builder = new JavaBeanPropertyBuilder("x", POJOBean.class); 249 //// } catch (NoSuchMethodException e) { 250 //// e.printStackTrace(); 251 //// fail(); 252 //// } 253 //// builder.createBooleanProperty(bean); 254 //// } 255 //// 256 //// @Test 257 //// public void testDisposal_GeneralAddRemove() { 258 //// JavaBeanPropertyBuilder builder = null; 259 //// try { 260 //// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); 261 //// } catch (NoSuchMethodException e) { 262 //// e.printStackTrace(); 263 //// fail(); 264 //// } 265 //// final Object value0 = new Object(); 266 //// final Object value1 = new Object(); 267 //// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); 268 //// JavaBeanObjectProperty<Object> property = builder.createObjectProperty(bean); 269 //// 270 //// // initial state 271 //// assertEquals(value0, property.get()); 272 //// assertTrue(bean.hasChangeListeners()); 273 //// assertTrue(bean.hasVetoListeners()); 274 //// 275 //// // dispose 276 //// property.dispose(); 277 //// try { 278 //// bean.setX(value1); 279 //// } catch (PropertyVetoException e) { 280 //// e.printStackTrace(); 281 //// fail(); 282 //// } 283 //// assertFalse(bean.hasChangeListeners()); 284 //// assertFalse(bean.hasVetoListeners()); 285 //// } 286 //// 287 //// @Test 288 //// public void testDisposal_ParameterizedAddRemove() { 289 //// JavaBeanPropertyBuilder builder = null; 290 //// try { 291 //// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); 292 //// } catch (NoSuchMethodException e) { 293 //// e.printStackTrace(); 294 //// fail(); 295 //// } 296 //// final Object value0 = new Object(); 297 //// final Object value1 = new Object(); 298 //// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); 299 //// JavaBeanObjectProperty<Object> property = builder.createObjectProperty(bean); 300 //// 301 //// // initial state 302 //// assertEquals(value0, property.get()); 303 //// assertTrue(bean.hasChangeListeners()); 304 //// assertTrue(bean.hasVetoListeners()); 305 //// 306 //// // dispose 307 //// property.dispose(); 308 //// try { 309 //// bean.setX(value1); 310 //// } catch (PropertyVetoException e) { 311 //// e.printStackTrace(); 312 //// fail(); 313 //// } 314 //// assertFalse(bean.hasChangeListeners()); 315 //// assertFalse(bean.hasVetoListeners()); 316 //// } 317 //// 318 //// @Test 319 //// public void testDisposal_NamedAddRemove() { 320 //// JavaBeanPropertyBuilder builder = null; 321 //// try { 322 //// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); 323 //// } catch (NoSuchMethodException e) { 324 //// e.printStackTrace(); 325 //// fail(); 326 //// } 327 //// final Object value0 = new Object(); 328 //// final Object value1 = new Object(); 329 //// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); 330 //// JavaBeanObjectProperty<Object> property = builder.createObjectProperty(bean); 331 //// 332 //// // initial state 333 //// assertEquals(value0, property.get()); 334 //// assertTrue(bean.hasChangeListeners()); 335 //// assertTrue(bean.hasVetoListeners()); 336 //// 337 //// // dispose 338 //// property.dispose(); 339 //// try { 340 //// bean.setX(value1); 341 //// } catch (PropertyVetoException e) { 342 //// e.printStackTrace(); 343 //// fail(); 344 //// } 345 //// assertFalse(bean.hasChangeListeners()); 346 //// assertFalse(bean.hasVetoListeners()); 347 //// } 348 //// 349 //// @Test 350 //// public void testDisposal_Bound() { 351 //// JavaBeanPropertyBuilder builder = null; 352 //// try { 353 //// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); 354 //// } catch (NoSuchMethodException e) { 355 //// e.printStackTrace(); 356 //// fail(); 357 //// } 358 //// final Object value0 = new Object(); 359 //// final Object value1 = new Object(); 360 //// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); 361 //// JavaBeanObjectProperty<Object> property = builder.createObjectProperty(bean); 362 //// final ObjectProperty<Object> observable = new SimpleObjectProperty<Object>(value1); 363 //// property.bind(observable); 364 //// 365 //// // initial state 366 //// assertEquals(value1, property.get()); 367 //// assertTrue(bean.hasChangeListeners()); 368 //// assertTrue(bean.hasVetoListeners()); 369 //// 370 //// // dispose 371 //// property.dispose(); 372 //// observable.set(value0); 373 //// assertFalse(bean.hasChangeListeners()); 374 //// assertFalse(bean.hasVetoListeners()); 375 //// } 376 //// 377 //// @Test 378 //// public void testInvalidationListener_GeneralAddRemove() { 379 //// JavaBeanPropertyBuilder builder = null; 380 //// try { 381 //// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); 382 //// } catch (NoSuchMethodException e) { 383 //// e.printStackTrace(); 384 //// fail(); 385 //// } 386 //// final BooleanProperty fired = new SimpleBooleanProperty(false); 387 //// final InvalidationListener listener = new InvalidationListener() { 388 //// @Override 389 //// public void invalidated(Observable observable) { 390 //// fired.set(true); 391 //// } 392 //// }; 393 //// final Object value0 = new Object(); 394 //// final Object value1 = new Object(); 395 //// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); 396 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 397 //// 398 //// property.addListener(listener); 399 //// fired.set(false); 400 //// property.setValue(value1); 401 //// assertTrue(fired.get()); 402 //// 403 //// property.removeListener(listener); 404 //// fired.set(false); 405 //// property.setValue(value0); 406 //// assertFalse(fired.get()); 407 //// } 408 //// 409 //// @Test 410 //// public void testChangeListener_GeneralAddRemove() { 411 //// JavaBeanPropertyBuilder builder = null; 412 //// try { 413 //// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); 414 //// } catch (NoSuchMethodException e) { 415 //// e.printStackTrace(); 416 //// fail(); 417 //// } 418 //// final BooleanProperty fired = new SimpleBooleanProperty(false); 419 //// final ChangeListener<Object> listener = new ChangeListener<Object>() { 420 //// @Override 421 //// public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) { 422 //// fired.set(true); 423 //// } 424 //// }; 425 //// final Object value0 = new Object(); 426 //// final Object value1 = new Object(); 427 //// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); 428 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 429 //// 430 //// property.addListener(listener); 431 //// fired.set(false); 432 //// property.setValue(value1); 433 //// assertTrue(fired.get()); 434 //// 435 //// property.removeListener(listener); 436 //// fired.set(false); 437 //// property.setValue(value0); 438 //// assertFalse(fired.get()); 439 //// } 440 //// 441 //// @Test 442 //// public void testInvalidationListener_ParameterizedAddRemove() { 443 //// JavaBeanPropertyBuilder builder = null; 444 //// try { 445 //// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); 446 //// } catch (NoSuchMethodException e) { 447 //// e.printStackTrace(); 448 //// fail(); 449 //// } 450 //// final BooleanProperty fired = new SimpleBooleanProperty(false); 451 //// final InvalidationListener listener = new InvalidationListener() { 452 //// @Override 453 //// public void invalidated(Observable observable) { 454 //// fired.set(true); 455 //// } 456 //// }; 457 //// final Object value0 = new Object(); 458 //// final Object value1 = new Object(); 459 //// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); 460 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 461 //// 462 //// property.addListener(listener); 463 //// fired.set(false); 464 //// property.setValue(value1); 465 //// assertTrue(fired.get()); 466 //// 467 //// property.removeListener(listener); 468 //// fired.set(false); 469 //// property.setValue(value0); 470 //// assertFalse(fired.get()); 471 //// } 472 //// 473 //// @Test 474 //// public void testChangeListener_ParameterizedAddRemove() { 475 //// JavaBeanPropertyBuilder builder = null; 476 //// try { 477 //// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); 478 //// } catch (NoSuchMethodException e) { 479 //// e.printStackTrace(); 480 //// fail(); 481 //// } 482 //// final BooleanProperty fired = new SimpleBooleanProperty(false); 483 //// final ChangeListener<Object> listener = new ChangeListener<Object>() { 484 //// @Override 485 //// public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) { 486 //// fired.set(true); 487 //// } 488 //// }; 489 //// final Object value0 = new Object(); 490 //// final Object value1 = new Object(); 491 //// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); 492 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 493 //// 494 //// property.addListener(listener); 495 //// fired.set(false); 496 //// property.setValue(value1); 497 //// assertTrue(fired.get()); 498 //// 499 //// property.removeListener(listener); 500 //// fired.set(false); 501 //// property.setValue(value0); 502 //// assertFalse(fired.get()); 503 //// } 504 //// 505 //// @Test 506 //// public void testInvalidationListener_NamedAddRemove() { 507 //// JavaBeanPropertyBuilder builder = null; 508 //// try { 509 //// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); 510 //// } catch (NoSuchMethodException e) { 511 //// e.printStackTrace(); 512 //// fail(); 513 //// } 514 //// final BooleanProperty fired = new SimpleBooleanProperty(false); 515 //// final InvalidationListener listener = new InvalidationListener() { 516 //// @Override 517 //// public void invalidated(Observable observable) { 518 //// fired.set(true); 519 //// } 520 //// }; 521 //// final Object value0 = new Object(); 522 //// final Object value1 = new Object(); 523 //// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); 524 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 525 //// 526 //// property.addListener(listener); 527 //// fired.set(false); 528 //// property.setValue(value1); 529 //// assertTrue(fired.get()); 530 //// 531 //// property.removeListener(listener); 532 //// fired.set(false); 533 //// property.setValue(value0); 534 //// assertFalse(fired.get()); 535 //// } 536 //// 537 //// @Test 538 //// public void testChangeListener_NamedAddRemove() { 539 //// JavaBeanPropertyBuilder builder = null; 540 //// try { 541 //// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); 542 //// } catch (NoSuchMethodException e) { 543 //// e.printStackTrace(); 544 //// fail(); 545 //// } 546 //// final BooleanProperty fired = new SimpleBooleanProperty(false); 547 //// final ChangeListener<Object> listener = new ChangeListener<Object>() { 548 //// @Override 549 //// public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) { 550 //// fired.set(true); 551 //// } 552 //// }; 553 //// final Object value0 = new Object(); 554 //// final Object value1 = new Object(); 555 //// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); 556 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 557 //// 558 //// property.addListener(listener); 559 //// fired.set(false); 560 //// property.setValue(value1); 561 //// assertTrue(fired.get()); 562 //// 563 //// property.removeListener(listener); 564 //// fired.set(false); 565 //// property.setValue(value0); 566 //// assertFalse(fired.get()); 567 //// } 568 //// 569 //// @Test 570 //// public void testSet_Bound() { 571 //// JavaBeanPropertyBuilder builder = null; 572 //// try { 573 //// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); 574 //// } catch (NoSuchMethodException e) { 575 //// e.printStackTrace(); 576 //// fail(); 577 //// } 578 //// final Object value0 = new Object(); 579 //// final Object value1 = new Object(); 580 //// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); 581 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 582 //// final Property<Object> observable = new SimpleObjectProperty<Object>(); 583 //// property.bind(observable); 584 //// 585 //// try { 586 //// bean.setX(value1); 587 //// fail(); 588 //// } catch (PropertyVetoException e) { 589 //// final PropertyChangeEvent event = e.getPropertyChangeEvent(); 590 //// assertEquals("x", event.getPropertyName()); 591 //// assertEquals(bean, event.getSource()); 592 //// } 593 //// } 594 //// 595 //// @Test 596 //// public void testListenerWithOtherParameters() { 597 //// JavaBeanPropertyBuilder builder = null; 598 //// try { 599 //// builder = new JavaBeanPropertyBuilder("x", BeanWithRawListenerSupport.class); 600 //// } catch (NoSuchMethodException e) { 601 //// e.printStackTrace(); 602 //// fail(); 603 //// } 604 //// final Object value0 = new Object(); 605 //// final Object value1 = new Object(); 606 //// final BeanWithRawListenerSupport bean = new BeanWithRawListenerSupport(value0); 607 //// final ObjectProperty<Object> property = builder.createObjectProperty(bean); 608 //// final Property<Object> observable = new SimpleObjectProperty<Object>(value1); 609 //// property.bind(observable); 610 //// 611 //// try { 612 //// bean.fireVetoableChange(new PropertyChangeEvent(new Object(), "x", value1, value0)); 613 //// assertEquals(value1, property.get()); 614 //// assertEquals(value1, bean.getX()); 615 //// bean.fireVetoableChange(new PropertyChangeEvent(bean, "y", value1, value0)); 616 //// assertEquals(value1, property.get()); 617 //// assertEquals(value1, bean.getX()); 618 //// } catch (PropertyVetoException e) { 619 //// fail(); 620 //// } 621 //// 622 //// bean.firePropertyChange(new PropertyChangeEvent(new Object(), "x", value1, value0)); 623 //// assertEquals(value1, property.get()); 624 //// assertEquals(value1, bean.getX()); 625 //// bean.firePropertyChange(new PropertyChangeEvent(bean, "y", value1, value0)); 626 //// assertEquals(value1, property.get()); 627 //// assertEquals(value1, bean.getX()); 628 //// } 629 // 630 // public static class POJOBean { 631 // private Object x; 632 // 633 // public POJOBean(Object x) {this.x = x;} 634 // 635 // public Object getX() {return x;} 636 // public void setX(Object x) {this.x = x;} 637 // } 638 // 639 // public static class POJOBeanWithNonStandardNames { 640 // private Object x; 641 // 642 // public POJOBeanWithNonStandardNames(Object x) {this.x = x;} 643 // 644 // public Object readX() {return x;} 645 // public void writeX(Object x) {this.x = x;} 646 // } 647 // 648 // public static class BeanWithGeneralAddRemove { 649 // private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); 650 // private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); 651 // 652 // private Object x; 653 // private int changeListenerCount; 654 // private int vetoListenerCount; 655 // 656 // public Object getX() {return x;} 657 // public void setX(Object x) throws PropertyVetoException { 658 // final Object oldX = this.x; 659 // vetoableChangeSupport.fireVetoableChange("x", oldX, x); 660 // this.x = x; 661 // propertyChangeSupport.firePropertyChange("x", oldX, x); 662 // } 663 // 664 // public BeanWithGeneralAddRemove(Object x) {this.x = x;} 665 // 666 // public boolean hasChangeListeners() { 667 // return changeListenerCount > 0; 668 // } 669 // 670 // public boolean hasVetoListeners() { 671 // return vetoListenerCount > 0; 672 // } 673 // 674 // public void addPropertyChangeListener(PropertyChangeListener listener) { 675 // changeListenerCount++; 676 // propertyChangeSupport.addPropertyChangeListener(listener); 677 // } 678 // 679 // public void removePropertyChangeListener(PropertyChangeListener listener) { 680 // changeListenerCount = Math.max(0, changeListenerCount-1); 681 // propertyChangeSupport.removePropertyChangeListener(listener); 682 // } 683 // 684 // public void addVetoableChangeListener(VetoableChangeListener listener) { 685 // vetoListenerCount++; 686 // vetoableChangeSupport.addVetoableChangeListener(listener); 687 // } 688 // 689 // public void removeVetoableChangeListener(VetoableChangeListener listener) { 690 // vetoListenerCount = Math.max(0, vetoListenerCount-1); 691 // vetoableChangeSupport.removeVetoableChangeListener(listener); 692 // } 693 // } 694 // 695 // public static class BeanWithParameterizedAddRemove { 696 // private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); 697 // private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); 698 // 699 // private Object x; 700 // private int changeListenerCount; 701 // private int vetoListenerCount; 702 // 703 // public Object getX() {return x;} 704 // public void setX(Object x) throws PropertyVetoException { 705 // final Object oldX = this.x; 706 // vetoableChangeSupport.fireVetoableChange("x", oldX, x); 707 // this.x = x; 708 // propertyChangeSupport.firePropertyChange("x", oldX, x); 709 // } 710 // 711 // public BeanWithParameterizedAddRemove(Object x) {this.x = x;} 712 // 713 // public boolean hasChangeListeners() { 714 // return changeListenerCount > 0; 715 // } 716 // 717 // public boolean hasVetoListeners() { 718 // return vetoListenerCount > 0; 719 // } 720 // 721 // public void addPropertyChangeListener(String name, PropertyChangeListener listener) { 722 // changeListenerCount++; 723 // propertyChangeSupport.addPropertyChangeListener(name, listener); 724 // } 725 // 726 // public void removePropertyChangeListener(String name, PropertyChangeListener listener) { 727 // changeListenerCount = Math.max(0, changeListenerCount-1); 728 // propertyChangeSupport.removePropertyChangeListener(name, listener); 729 // } 730 // 731 // public void addVetoableChangeListener(String name, VetoableChangeListener listener) { 732 // vetoListenerCount++; 733 // vetoableChangeSupport.addVetoableChangeListener(name, listener); 734 // } 735 // 736 // public void removeVetoableChangeListener(String name, VetoableChangeListener listener) { 737 // vetoListenerCount = Math.max(0, vetoListenerCount-1); 738 // vetoableChangeSupport.removeVetoableChangeListener(name, listener); 739 // } 740 // } 741 // 742 // public static class BeanWithNamedAddRemove { 743 // private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); 744 // private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); 745 // 746 // private Object x; 747 // private int changeListenerCount; 748 // private int vetoListenerCount; 749 // 750 // public Object getX() {return x;} 751 // public void setX(Object x) throws PropertyVetoException { 752 // final Object oldX = this.x; 753 // vetoableChangeSupport.fireVetoableChange("x", oldX, x); 754 // this.x = x; 755 // propertyChangeSupport.firePropertyChange("x", oldX, x); 756 // } 757 // 758 // public BeanWithNamedAddRemove(Object x) {this.x = x;} 759 // 760 // public boolean hasChangeListeners() { 761 // return changeListenerCount > 0; 762 // } 763 // 764 // public boolean hasVetoListeners() { 765 // return vetoListenerCount > 0; 766 // } 767 // 768 // public void addXListener(PropertyChangeListener listener) { 769 // changeListenerCount++; 770 // propertyChangeSupport.addPropertyChangeListener("x", listener); 771 // } 772 // 773 // public void removeXListener(PropertyChangeListener listener) { 774 // changeListenerCount = Math.max(0, changeListenerCount-1); 775 // propertyChangeSupport.removePropertyChangeListener("x", listener); 776 // } 777 // 778 // public void addXListener(VetoableChangeListener listener) { 779 // vetoListenerCount++; 780 // vetoableChangeSupport.addVetoableChangeListener("x", listener); 781 // } 782 // 783 // public void removeXListener(VetoableChangeListener listener) { 784 // vetoListenerCount = Math.max(0, vetoListenerCount-1); 785 // vetoableChangeSupport.removeVetoableChangeListener("x", listener); 786 // } 787 // } 788 // 789 // public class BeanWithRawListenerSupport { 790 // private final List<VetoableChangeListener> vetoListeners = new ArrayList<VetoableChangeListener>(); 791 // private final List<PropertyChangeListener> changeListeners = new ArrayList<PropertyChangeListener>(); 792 // 793 // private Object x; 794 // 795 // public Object getX() {return x;} 796 // public void setX(Object x) throws PropertyVetoException { 797 // final Object oldX = this.x; 798 // final PropertyChangeEvent event = new PropertyChangeEvent(this, "x", oldX, x); 799 // fireVetoableChange(event); 800 // this.x = x; 801 // firePropertyChange(event); 802 // } 803 // 804 // private void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException { 805 // for (final VetoableChangeListener listener : vetoListeners) { 806 // listener.vetoableChange(event); 807 // } 808 // } 809 // 810 // private void firePropertyChange(PropertyChangeEvent event) { 811 // for (final PropertyChangeListener listener : changeListeners) { 812 // listener.propertyChange(event); 813 // } 814 // } 815 // 816 // public BeanWithRawListenerSupport(Object x) {this.x = x;} 817 // 818 // public boolean hasChangeListeners() { 819 // return !changeListeners.isEmpty(); 820 // } 821 // 822 // public boolean hasVetoListeners() { 823 // return !vetoListeners.isEmpty(); 824 // } 825 // 826 // public void addPropertyChangeListener(PropertyChangeListener listener) { 827 // changeListeners.add(listener); 828 // } 829 // 830 // public void removePropertyChangeListener(PropertyChangeListener listener) { 831 // changeListeners.remove(listener); 832 // } 833 // 834 // public void addVetoableChangeListener(VetoableChangeListener listener) { 835 // vetoListeners.add(listener); 836 // } 837 // 838 // public void removeVetoableChangeListener(VetoableChangeListener listener) { 839 // vetoListeners.remove(listener); 840 // } 841 // } 842 //}