From: David ‘Bombe’ Roden Date: Thu, 30 Jul 2015 05:08:34 +0000 (+0200) Subject: Use internal image IDs for temporary images X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=449c24942c72153666e261b4b35df5cf2e0ac2ac;p=Sone.git Use internal image IDs for temporary images --- diff --git a/src/main/java/net/pterodactylus/sone/core/ImageInserter.java b/src/main/java/net/pterodactylus/sone/core/ImageInserter.java index 6b33897..9e38dd1 100644 --- a/src/main/java/net/pterodactylus/sone/core/ImageInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/ImageInserter.java @@ -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); diff --git a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java index 65e8cdb..31f53a7 100644 --- a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java @@ -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(); diff --git a/src/test/java/net/pterodactylus/sone/core/ImageInserterTest.java b/src/test/java/net/pterodactylus/sone/core/ImageInserterTest.java index 0912391..611908b 100644 --- a/src/test/java/net/pterodactylus/sone/core/ImageInserterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/ImageInserterTest.java @@ -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 insertTokenSupplier = when(mock(Function.class).apply(any(Image.class))).thenReturn(insertToken).getMock(); diff --git a/src/test/java/net/pterodactylus/sone/template/ImageLinkFilterTest.java b/src/test/java/net/pterodactylus/sone/template/ImageLinkFilterTest.java index 20d2362..4640d9c 100644 --- a/src/test/java/net/pterodactylus/sone/template/ImageLinkFilterTest.java +++ b/src/test/java/net/pterodactylus/sone/template/ImageLinkFilterTest.java @@ -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.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"));