EHCachingExchangeSource extends AbstractEHCachingSourceWithExternalBundle<Exchange, ExchangeSource> implements ExchangeSource { @Override public Exchange getSingle(final ExternalId identifier) { final Exchange result = getUnderlying().getSingle(identifier); cacheItem(result); return result; } EHCachingExchangeSource(final ExchangeSource underlying, final CacheManager cacheManager); @Override Exchange getSingle(final ExternalId identifier);  }
@Test public void getById() throws InterruptedException { final AtomicLong getCount = new AtomicLong(0); final ExchangeSource underlying = Mockito.mock(ExchangeSource.class); Mockito.when(underlying.getSingle(Mockito.<ExternalId>anyObject())).thenAnswer(new Answer<Exchange>() { @Override public Exchange answer(InvocationOnMock invocation) throws Throwable { getCount.incrementAndGet(); SimpleExchange simpleExchange = new SimpleExchange(); simpleExchange.setUniqueId(UniqueId.of("Test", "Foo", "0")); simpleExchange.setExternalIdBundle(ExternalIdBundle.of((ExternalId) invocation.getArguments()[0])); return simpleExchange; } }); Mockito.when(underlying.changeManager()).thenReturn(Mockito.mock(ChangeManager.class)); EHCachingExchangeSource source = new EHCachingExchangeSource(underlying, _cacheManager); assertEquals(0, getCount.get()); ExternalScheme scheme = ExternalScheme.of("Scheme"); ExternalId id = ExternalId.of(scheme, "Value"); Exchange get1 = source.getSingle(id); assertEquals(1, getCount.get()); assertEquals(1, get1.getExternalIdBundle().size()); assertEquals(id, get1.getExternalIdBundle().getExternalId(scheme)); Exchange get2 = source.get(UniqueId.of("Test", "Foo", "0")); assertEquals(1, getCount.get()); assertTrue(get1 == get2); }