public void testSingleArgumentNamedProperty() { TestModel testModel = new TestModel(7); Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); testModel.addPropertyChangeListener( TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener( target, "propertyChangedSingleArgument")); testModel.setValue(99); assertFalse(target.zeroArgumentFlag); assertTrue(target.singleArgumentFlag); }
/** test method that has more general method parameter type */ public void testSingleArgumentNamedProperty2() throws Exception { TestModel testModel = new TestModel(7); Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); Method method = ObjectTools.method(target, "propertyChangedSingleArgument2", new Class[] {Object.class}); testModel.addPropertyChangeListener( TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, method)); testModel.setValue(99); assertFalse(target.zeroArgumentFlag); assertTrue(target.singleArgumentFlag); }
public void testBogusDoubleArgument1() { TestModel testModel = new TestModel(7); Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); boolean exCaught = false; try { PropertyChangeListener listener = ReflectiveChangeListener.buildPropertyChangeListener( target, "stateChangedDoubleArgument"); fail("bogus listener: " + listener); } catch (RuntimeException ex) { if (ex.getCause().getClass() == NoSuchMethodException.class) { exCaught = true; } } assertTrue(exCaught); }
public void testListenerMismatch() { TestModel testModel = new TestModel(7); Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); // build a PROPERTY change listener and hack it so we // can add it as a STATE change listener Object listener = ReflectiveChangeListener.buildPropertyChangeListener( target, "propertyChangedSingleArgument"); testModel.addStateChangeListener((StateChangeListener) listener); boolean exCaught = false; try { testModel.setValue(99); fail("listener mismatch: " + listener); } catch (IllegalArgumentException ex) { exCaught = true; } assertTrue(exCaught); }
public void testBogusDoubleArgument2() throws Exception { TestModel testModel = new TestModel(7); Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); Method method = ObjectTools.method( target, "propertyChangedDoubleArgument", new Class[] {PropertyChangeEvent.class, Object.class}); boolean exCaught = false; try { PropertyChangeListener listener = ReflectiveChangeListener.buildPropertyChangeListener(target, method); fail("bogus listener: " + listener); } catch (RuntimeException ex) { if (ex.getMessage().equals(method.toString())) { exCaught = true; } } assertTrue(exCaught); }