### Question:
EPPolicyTemplateDaoFacadeImpl implements EPPolicyTemplateDaoFacade { @Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key) { final ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> templateFu = epPolicyTemplateDao.read(key); return Futures.transformAsync(templateFu, new AsyncFunction<Optional<EndpointPolicyTemplateBySgt>, Optional<EndpointPolicyTemplateBySgt>>() { @Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> apply( @Nonnull final Optional<EndpointPolicyTemplateBySgt> templateOpt) throws Exception { return templateOpt.transform(template -> Futures.immediateFuture(templateOpt)) .or(() -> java.util.Optional.ofNullable(templateProvider) .map(provider -> templateProvider.provideTemplate(key)) .map(template -> rewrapOptionalToGuavaOptional(template)) .orElse(Futures.immediateFuture(Optional.absent())) ); } }, MoreExecutors.directExecutor()); } EPPolicyTemplateDaoFacadeImpl(final DataBroker dataBroker, final EPPolicyTemplateDaoImpl epPolicyTemplateDao,
                                         final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> epPolicyTemplateCachedDao,
                                         final SgtGeneratorImpl sgtGenerator); @Override void setTemplateProvider(final EPPolicyTemplateProvider templateProvider); @Override ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key); @Override ListenableFuture<Collection<EndpointPolicyTemplateBySgt>> readBy(@Nonnull final EpPolicyTemplateValueKey templateLookupKey);  }### Answer:
@Test public void testRead_trivial() throws Exception { final EndpointPolicyTemplateBySgt template = templateBld.build(); Mockito.when(delegateDao.read(SGT)).thenReturn(Futures.immediateFuture(Optional.of(template))); final ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> actual = facade.read(SGT); Assert.assertTrue(actual.isDone()); Assert.assertTrue(actual.get().isPresent()); Assert.assertEquals(template, actual.get().get()); }
@Test public void testRead_failNoProvider() throws Exception { Mockito.when(delegateDao.read(SGT)).thenReturn(Futures.immediateFuture(Optional.absent())); final ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> actual = facade.read(SGT); Assert.assertTrue(actual.isDone()); Assert.assertFalse(actual.get().isPresent()); }