### Question:
DelegatingImageExtension implements ImageExtension { public boolean deleteImage(String id) { boolean success = delegate.deleteImage(id); if (success) { imageCache.removeImage(id); } return success; } @Inject  DelegatingImageExtension(@Assisted ImageCacheSupplier imageCache, @Assisted ImageExtension delegate,
         AddDefaultCredentialsToImage addDefaultCredentialsToImage, Map<String, Credentials> credentialStore); ImageTemplate buildImageTemplateFromNode(String name, String id); ListenableFuture<Image> createImage(final ImageTemplate template); boolean deleteImage(String id);  }### Answer:
@Test public void deleteUnregistersImageFromCache() { ImageCacheSupplier imageCache = createMock(ImageCacheSupplier.class); ImageExtension delegate = createMock(ImageExtension.class); expect(delegate.deleteImage("test")).andReturn(true); imageCache.removeImage("test"); expectLastCall(); replay(delegate, imageCache); new DelegatingImageExtension(imageCache, delegate, null, null).deleteImage("test"); verify(delegate, imageCache); }
@Test public void deleteDoesNotUnregisterImageFromCacheWhenFailed() { ImageCacheSupplier imageCache = createMock(ImageCacheSupplier.class); ImageExtension delegate = createMock(ImageExtension.class); expect(delegate.deleteImage("test")).andReturn(false); replay(delegate, imageCache); new DelegatingImageExtension(imageCache, delegate, null, null).deleteImage("test"); verify(delegate, imageCache); }