Use internal image IDs for temporary images
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 30 Jul 2015 05:08:34 +0000 (07:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 30 Jul 2015 05:08:34 +0000 (07:08 +0200)
src/main/java/net/pterodactylus/sone/core/ImageInserter.java
src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java
src/test/java/net/pterodactylus/sone/core/ImageInserterTest.java
src/test/java/net/pterodactylus/sone/template/ImageLinkFilterTest.java

index 6b33897..9e38dd1 100644 (file)
@@ -77,7 +77,7 @@ public class ImageInserter {
        public void insertImage(TemporaryImage temporaryImage, Image image) {
                checkNotNull(temporaryImage, "temporaryImage must not be null");
                checkNotNull(image, "image must not be null");
-               checkArgument(image.getId().equals(temporaryImage.getId()), "image IDs must match");
+               checkArgument(image.getInternalId().equals(temporaryImage.getId()), "image IDs must match");
                try {
                        InsertToken insertToken = insertTokenSupplier.apply(image);
                        insertTokens.put(image.getId(), insertToken);
index 65e8cdb..31f53a7 100644 (file)
@@ -92,7 +92,7 @@ public class ImageLinkFilter implements Filter {
                        linkTemplateContext.set("src", "/" + image.getKey());
                        linkTemplateContext.set("forceDownload", true);
                } else {
-                       linkTemplateContext.set("src", "getImage.html?image=" + image.getId());
+                       linkTemplateContext.set("src", "getImage.html?image=" + image.getInternalId());
                }
                int imageWidth = image.getWidth();
                int imageHeight = image.getHeight();
index 0912391..611908b 100644 (file)
@@ -23,7 +23,7 @@ import org.junit.Test;
 public class ImageInserterTest {
 
        private final TemporaryImage temporaryImage = when(mock(TemporaryImage.class).getId()).thenReturn("image-id").getMock();
-       private final Image image = when(mock(Image.class).getId()).thenReturn("image-id").getMock();
+       private final Image image = when(mock(Image.class).getInternalId()).thenReturn("image-id").getMock();
        private final FreenetInterface freenetInterface = mock(FreenetInterface.class);
        private final InsertToken insertToken = mock(InsertToken.class);
        private final Function<Image, InsertToken> insertTokenSupplier = when(mock(Function.class).apply(any(Image.class))).thenReturn(insertToken).getMock();
index 20d2362..4640d9c 100644 (file)
@@ -47,6 +47,7 @@ public class ImageLinkFilterTest {
        @Before
        public void setupImage() {
                when(image.getId()).thenReturn("image-id");
+               when(image.getInternalId()).thenReturn("internal-image-id");
                when(image.getKey()).thenReturn("image-key");
                when(image.isInserted()).thenReturn(true);
                when(image.getWidth()).thenReturn(640);
@@ -61,7 +62,7 @@ public class ImageLinkFilterTest {
                String result = String.valueOf(imageLinkFilter.format(templateContext, image, ImmutableMap.<String, Object>of()));
                Element imageElement = getSingleElement(result);
                assertThat(imageElement.attr("class"), is(""));
-               assertThat(imageElement.attr("src"), is("getImage.html?image=image-id"));
+               assertThat(imageElement.attr("src"), is("getImage.html?image=internal-image-id"));
                assertThat(imageElement.attr("title"), is("image title"));
                assertThat(imageElement.attr("alt"), is("image description"));
                assertThat(imageElement.attr("width"), is("640"));