Treat cancelled fetch request as failure
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 13 Nov 2016 08:41:13 +0000 (09:41 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 13 Nov 2016 08:41:13 +0000 (09:41 +0100)
src/main/java/net/pterodactylus/sone/core/FreenetInterface.java
src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java

index 48df732..82cc94b 100644 (file)
@@ -178,7 +178,11 @@ public class FreenetInterface {
                        @Override
                        public boolean snoopMetadata(Metadata meta, ClientContext context) {
                                String mimeType = meta.getMIMEType();
-                               return (mimeType == null) || backgroundFetchCallback.cancelForMimeType(uri, mimeType);
+                               boolean cancel = (mimeType == null) || backgroundFetchCallback.cancelForMimeType(uri, mimeType);
+                               if (cancel) {
+                                       backgroundFetchCallback.failed(uri);
+                               }
+                               return cancel;
                        }
                };
                FetchContext fetchContext = client.getFetchContext();
index 195876f..cf69136 100644 (file)
@@ -440,27 +440,32 @@ public class FreenetInterfaceTest {
        @Test
        public void requestIsNotCancelledForImageMimeType() {
                verifySnoopCancelsRequestForMimeType("image/png", false);
+               verify(backgroundFetchCallback, never()).failed(uri);
        }
 
        @Test
        public void requestIsCancelledForNullMimeType() {
                verifySnoopCancelsRequestForMimeType(null, true);
                verify(backgroundFetchCallback, never()).cancelForMimeType(eq(uri), ArgumentMatchers.<String>any());
+               verify(backgroundFetchCallback).failed(uri);
        }
 
        @Test
        public void requestIsCancelledForVideoMimeType() {
                verifySnoopCancelsRequestForMimeType("video/mkv", true);
+               verify(backgroundFetchCallback).failed(uri);
        }
 
        @Test
        public void requestIsCancelledForAudioMimeType() {
                verifySnoopCancelsRequestForMimeType("audio/mpeg", true);
+               verify(backgroundFetchCallback).failed(uri);
        }
 
        @Test
        public void requestIsCancelledForTextMimeType() {
                verifySnoopCancelsRequestForMimeType("text/plain", true);
+               verify(backgroundFetchCallback).failed(uri);
        }
 
        private void verifySnoopCancelsRequestForMimeType(String mimeType, boolean cancel) {