MasterSnapshotSource extends AbstractMasterSource<NamedSnapshot, MarketDataSnapshotDocument, MarketDataSnapshotMaster> implements MarketDataSnapshotSource { @Override public <S extends NamedSnapshot> S getSingle(Class<S> type, String snapshotName, VersionCorrection versionCorrection) { TypedSnapshotSearcher<S> searcher = new TypedSnapshotSearcher<>(getMaster(), type, snapshotName, versionCorrection); return searcher.search(); } MasterSnapshotSource(final MarketDataSnapshotMaster master); @Override void addChangeListener(final UniqueId uniqueId, final MarketDataSnapshotChangeListener listener); @Override void removeChangeListener(UniqueId uid, MarketDataSnapshotChangeListener listener); @Override S getSingle(Class<S> type,
                                               String snapshotName,
                                               VersionCorrection versionCorrection);  }
@Test(expectedExceptions = DataNotFoundException.class) public void testGetSingleWithNoMatchGivesException() { MarketDataSnapshotMaster mock = mock(MarketDataSnapshotMaster.class); when(mock.search(Matchers.<MarketDataSnapshotSearchRequest>anyObject())) .thenReturn(new MarketDataSnapshotSearchResult(ImmutableList.<MarketDataSnapshotDocument>of())); new MasterSnapshotSource(mock).getSingle(NamedSnapshot.class, "I dont exist", VersionCorrection.LATEST); }
@Test public void testMatchByTypeAndNameSucceeds() { NamedSnapshot snapshot = _populatedSource.getSingle(NamedSnapshot.class, "snap1", VersionCorrection.LATEST); assertThat(snapshot.getName(), is("snap1")); }
@Test public void testTypeUnmatchedAndNameMatchedStillSucceeds() { NamedSnapshot snapshot = _populatedSource.getSingle(NamedSnapshot.class, "snap2", VersionCorrection.LATEST); assertThat(snapshot.getName(), is("snap2")); }
@Test public void testSnapshotHasCorrectType() { ExtraSpecialSnapshot snapshot = _populatedSource.getSingle(ExtraSpecialSnapshot.class, "snap3", VersionCorrection.LATEST); assertThat(snapshot.getName(), is("snap3")); }
@Test public void testWrongTypeIsAvoided() { ExtraSpecialSnapshot snapshot = _populatedSource.getSingle(ExtraSpecialSnapshot.class, "snap4", VersionCorrection.LATEST); assertThat(snapshot.getName(), is("snap4")); assertThat(snapshot.getId(), is(42)); }
@Test public void testWithMultipleMatchesFirstIsReturned() { SpecialSnapshot snapshot = _populatedSource.getSingle(SpecialSnapshot.class, "snap4", VersionCorrection.LATEST); assertThat(snapshot.getName(), is("snap4")); assertThat(snapshot.getId(), is(41)); }
@Test(expectedExceptions = DataNotFoundException.class) public void testObjectMatchingCriteriaIsNotReturnedIfWrongType() { _populatedSource.getSingle(ExtraSpecialSnapshot.class, "snap5", VersionCorrection.LATEST); }