CachingDiscoveryProvider implements DiscoveryProvider { @Override public RpcDescription getRpcDocument(final String root, final String name, final String version) throws NotFoundException, InternalServerErrorException { return getDiscoveryDoc(rpcDocuments, root, name, version, new Callable<RpcDescription>() { @Override public RpcDescription call() throws NotFoundException, InternalServerErrorException { return delegate.getRpcDocument(root, name, version); } }); } CachingDiscoveryProvider(DiscoveryProvider delegate);  CachingDiscoveryProvider(
      DiscoveryProvider delegate, long cacheExpiry, TimeUnit cacheExpiryUnit); @Override RestDescription getRestDocument(final String root, final String name, final String version); @Override RpcDescription getRpcDocument(final String root, final String name, final String version); @Override DirectoryList getDirectory(final String root);  }
@Test public void getRpcDocument() throws Exception { CachingDiscoveryProvider provider = createNonExpiringProvider(); setupNormalMockDelegate(); assertThat(provider.getRpcDocument(ROOT, NAME, VERSION)).isEqualTo(RPC_DOC); assertThat(provider.getRpcDocument(ROOT, NAME, VERSION)).isEqualTo(RPC_DOC); verify(delegate, times(1)).getRpcDocument(ROOT, NAME, VERSION); }
@Test public void getRpcDocument_notFound() throws Exception { CachingDiscoveryProvider provider = createNonExpiringProvider(); when(delegate.getRpcDocument(ROOT, NAME, VERSION)).thenThrow(new NotFoundException("")); try { provider.getRpcDocument(ROOT, NAME, VERSION); fail("expected NotFoundException"); } catch (NotFoundException e) { } }
@Test public void getRpcDocument_internalServerError() throws Exception { CachingDiscoveryProvider provider = createNonExpiringProvider(); when(delegate.getRpcDocument(ROOT, NAME, VERSION)) .thenThrow(new InternalServerErrorException("")); try { provider.getRpcDocument(ROOT, NAME, VERSION); fail("expected InternalServerErrorException"); } catch (InternalServerErrorException e) { } }
@Test public void getRpcDocument_runtimeException() throws Exception { CachingDiscoveryProvider provider = createNonExpiringProvider(); when(delegate.getRpcDocument(ROOT, NAME, VERSION)) .thenThrow(new RuntimeException("")); try { provider.getRpcDocument(ROOT, NAME, VERSION); fail("expected InternalServerErrorException"); } catch (InternalServerErrorException e) { } }