🎨 Update current edition of rescuer after fetch
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 30 Jul 2019 20:25:55 +0000 (22:25 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 30 Jul 2019 20:25:55 +0000 (22:25 +0200)
src/main/java/net/pterodactylus/sone/core/SoneRescuer.java
src/test/kotlin/net/pterodactylus/sone/core/SoneRescuerTest.kt

index 93c77c2..adc0925 100644 (file)
@@ -108,17 +108,6 @@ public class SoneRescuer extends AbstractService {
        }
 
        /**
-        * Sets the edition to rescue.
-        *
-        * @param edition
-        *            The edition to rescue
-        * @return This Sone rescuer
-        */
-       public void setEdition(long edition) {
-               currentEdition = edition;
-       }
-
-       /**
         * Sets whether the last fetch was successful.
         *
         * @return {@code true} if the last fetch was successful, {@code false}
@@ -134,9 +123,7 @@ public class SoneRescuer extends AbstractService {
        //
 
        /**
-        * Starts the next fetch. If you want to fetch a different edition than “the
-        * next older one,” remember to call {@link #setEdition(long)} before
-        * calling this method.
+        * Starts the next fetch.
         */
        public void startNextFetch() {
                fetching = true;
@@ -165,6 +152,7 @@ public class SoneRescuer extends AbstractService {
                                lastFetchSuccessful = (fetchedSone != null);
                                if (lastFetchSuccessful) {
                                        core.updateSone(fetchedSone, true);
+                                       currentEdition = getNextEdition();
                                }
                                fetching = false;
                        }
index 68e08e3..a74b874 100644 (file)
@@ -74,6 +74,7 @@ class SoneRescuerTest {
                verify(core).updateSone(eq(fetchedSone), eq(true))
                assertThat(soneRescuer.isLastFetchSuccessful, equalTo(true))
                assertThat(soneRescuer.isFetching, equalTo(false))
+               assertThat(soneRescuer.currentEdition, equalTo(currentEdition - 1))
        }
 
        @Test
@@ -85,6 +86,7 @@ class SoneRescuerTest {
                verify(core, never()).updateSone(any(Sone::class.java), eq(true))
                assertThat(soneRescuer.isLastFetchSuccessful, equalTo(false))
                assertThat(soneRescuer.isFetching, equalTo(false))
+               assertThat(soneRescuer.currentEdition, equalTo(currentEdition))
        }
 
        private fun returnUriOnInsert(fetchedSone: Sone?) {