final double iniPrice = 3.56;
final double newPrice = iniPrice*1.0214; // changed +2.14%
// define Stock
final RelinkableHandle<Quote> h = new RelinkableHandle<Quote>(new SimpleQuote(iniPrice));
final Instrument s = new Stock(h);
// attach an Observer to Stock
final Flag priceChange = new Flag();
s.addObserver(priceChange);
// verify initial price
if (iniPrice != s.NPV()) {
fail("stock quote valuation failed");
}
// set a new price
h.linkTo(new SimpleQuote(newPrice));
// Observer must detect price change
if (!priceChange.isUp()) {
fail("Observer was not notified of instrument change");
}
if (newPrice != s.NPV()) {
fail("stock quote havent changed value");
}
}