   @Test
   public void createImageRegistersInCacheAndAddsCredentials()  {

      ImageCacheSupplier imageCache = createMock(ImageCacheSupplier.class);
      ImageExtension delegate = createMock(ImageExtension.class);
      AddDefaultCredentialsToImage credsToImage = createMock(AddDefaultCredentialsToImage.class);

      ImageTemplate template = new ImageTemplateImpl("test") {
      };
      Image result = new ImageBuilder().id("test")
            .operatingSystem(OperatingSystem.builder().description("test").build()).status(Status.AVAILABLE).build();

      LoginCredentials credentials = LoginCredentials.builder().user("jclouds").password("pass").build();
      Image withCredentials = ImageBuilder.fromImage(result).defaultCredentials(credentials).build();

      expect(delegate.createImage(template)).andReturn(immediateFuture(result));
      expect(credsToImage.apply(result)).andReturn(withCredentials);
      imageCache.registerImage(withCredentials);
      expectLastCall();
      replay(delegate, imageCache, credsToImage);

      new DelegatingImageExtension(imageCache, delegate, credsToImage, null).createImage(template);

      verify(delegate, imageCache, credsToImage);
   }