HistoricalShockMarketDataSnapshot implements MarketDataSnapshot { @Override public Object query(ValueSpecification specification) { Object value1 = _historicalSnapshot1.query(specification); Object value2 = _historicalSnapshot2.query(specification); Object baseValue = _baseSnapshot.query(specification); if (!(value1 instanceof Double) || !(value2 instanceof Double) || !(baseValue instanceof Double)) { return baseValue; } return _shockType.shock((Double) value1, (Double) value2, (Double) baseValue); } HistoricalShockMarketDataSnapshot(ShockType shockType,
                                           MarketDataSnapshot historicalSnapshot1,
                                           MarketDataSnapshot historicalSnapshot2,
                                           MarketDataSnapshot baseSnapshot); @Override UniqueId getUniqueId(); @Override Instant getSnapshotTimeIndication(); @Override void init(); @Override void init(Set<ValueSpecification> values, long timeout, TimeUnit ucUnit); @Override boolean isInitialized(); @Override boolean isEmpty(); @Override Instant getSnapshotTime(); @Override Object query(ValueSpecification specification); @Override Map<ValueSpecification, Object> query(Set<ValueSpecification> specifications);  }
@Test public void proportionalShock() { HistoricalShockMarketDataSnapshot snapshot = new HistoricalShockMarketDataSnapshot(HistoricalShockMarketDataSnapshot.ShockType.PROPORTIONAL, historicalSnapshot1(), historicalSnapshot2(), baseSnapshot()); assertEquals(11d, snapshot.query(SPEC1)); assertEquals(22d, snapshot.query(SPEC2)); assertEquals(44d, snapshot.query(SPEC3)); assertEquals(ImmutableMap.<ValueSpecification, Object>of(SPEC1, 11d, SPEC2, 22d, SPEC3, 44d), snapshot.query(ImmutableSet.of(SPEC1, SPEC2, SPEC3))); }
@Test public void absoluteShock() { HistoricalShockMarketDataSnapshot snapshot = new HistoricalShockMarketDataSnapshot(HistoricalShockMarketDataSnapshot.ShockType.ABSOLUTE, historicalSnapshot1(), historicalSnapshot2(), baseSnapshot()); assertEquals(10.1d, snapshot.query(SPEC1)); assertEquals(20.2d, snapshot.query(SPEC2)); assertEquals(40.4d, snapshot.query(SPEC3)); assertEquals(ImmutableMap.<ValueSpecification, Object>of(SPEC1, 10.1d, SPEC2, 20.2d, SPEC3, 40.4d), snapshot.query(ImmutableSet.of(SPEC1, SPEC2, SPEC3))); }