@Test @UI public void testOtherObservablesPreservedWhenOptionInvalid() throws Exception { ITypedObservableValue<Instrument> instrument = TypedObservableValueDecorator.create(Instrument.class); Instrument option = new Option("ABC", "200910", BigDecimal.ONE, OptionType.Put); instrument.setValue(option); OptionObservable optionObservable = new OptionObservable(instrument); ImmutableList<IObservableValue> children = ImmutableList.<IObservableValue>of( optionObservable.observeSymbol(), optionObservable.observeExpiry(), optionObservable.observeStrikePrice(), optionObservable.observeOptionType()); for (IObservableValue observable : children) { Object value = observable.getValue(); observable.setValue(null); assertThat(instrument.getValue(), nullValue()); for (IObservableValue other : children) { if (other != observable) { assertThat(other.getValue(), not(nullValue())); } } observable.setValue(value); assertThat(instrument.getTypedValue(), is(option)); } }
public TestTemplate() { ITypedObservableValue<Instrument> instrument = TypedObservableValueDecorator.create(Instrument.class); Option option = new Option(mSymbol, mExpiry, mStrike, mType); instrument.setValue(option); OptionObservable optionObservable = new OptionObservable(instrument); ITypedObservableValue<T> child = observeChild(optionObservable); assertThat(child.getTypedValue(), is(get(option))); /* * Change the parent instrument's value. */ change(); Option previous = option; option = new Option(mSymbol, mExpiry, mStrike, mType); assertThat(option, not(previous)); instrument.setValue(option); assertThat(child.getTypedValue(), is(get(option))); /* * Make the parent instrument null. */ instrument.setValue(null); assertThat(child.getTypedValue(), nullValue()); /* * Set invalid instrument. */ instrument.setValue(option); assertThat(child.getTypedValue(), is(get(option))); instrument.setValue(new Equity("X")); assertThat(child.getTypedValue(), nullValue()); /* * Change the value on the child. */ instrument.setValue(option); child.setValue(changeAgain()); previous = option; option = new Option(mSymbol, mExpiry, mStrike, mType); assertThat(option, not(previous)); assertThat(instrument.getTypedValue(), is((Instrument) option)); /* * Make the child null. */ child.setValue(null); assertThat(instrument.getTypedValue(), nullValue()); /* * Subclasses can extend. */ additionalTests(instrument, child); /* * Dispose parent. */ instrument.dispose(); assertTrue(child.isDisposed()); }