X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FUpdateCheckerTest.java;h=548051a1177280507cf1bf140b291e208b422844;hb=a57dae72e505fec934a9516b88fea75c473f7641;hp=a5e3b2a9c8f58a18995c4a8a3fb52688326c7c8a;hpb=f229fe41f708d2b275c20ceb9aba5993761218a3;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java b/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java
index a5e3b2a..548051a 100644
--- a/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java
+++ b/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java
@@ -1,25 +1,24 @@
package net.pterodactylus.sone.core;
import static java.lang.Long.MAX_VALUE;
-import static net.pterodactylus.sone.main.SonePlugin.VERSION;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentCaptor.forClass;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.io.IOException;
import java.io.InputStream;
import net.pterodactylus.sone.core.FreenetInterface.Callback;
-import net.pterodactylus.sone.core.FreenetInterface.Fetched;
import net.pterodactylus.sone.core.event.UpdateFoundEvent;
+import net.pterodactylus.sone.main.PluginHomepage;
import net.pterodactylus.util.version.Version;
import freenet.client.ClientMetadata;
@@ -37,14 +36,14 @@ import org.mockito.stubbing.Answer;
/**
* Unit test for {@link UpdateChecker}.
- *
- * @author David âBombeâ Roden
*/
public class UpdateCheckerTest {
private final EventBus eventBus = mock(EventBus.class);
private final FreenetInterface freenetInterface = mock(FreenetInterface.class);
- private final UpdateChecker updateChecker = new UpdateChecker(eventBus, freenetInterface);
+ private final Version currentVersion = new Version(1, 0, 0);
+ private final PluginHomepage pluginHomepage = new PluginHomepage("KSK@homepage");
+ private final UpdateChecker updateChecker = new UpdateChecker(eventBus, freenetInterface, currentVersion, pluginHomepage);
@Before
public void startUpdateChecker() {
@@ -54,7 +53,7 @@ public class UpdateCheckerTest {
@Test
public void newUpdateCheckerDoesNotHaveALatestVersion() {
assertThat(updateChecker.hasLatestVersion(), is(false));
- assertThat(updateChecker.getLatestVersion(), is(VERSION));
+ assertThat(updateChecker.getLatestVersion(), is(currentVersion));
}
@Test
@@ -87,23 +86,33 @@ public class UpdateCheckerTest {
setupFetchResult(createFutureFetchResult());
setupCallbackWithEdition(MAX_VALUE, true, false);
verifyAFreenetUriIsFetched();
- ArgumentCaptor updateFoundEvent = forClass(UpdateFoundEvent.class);
- verify(eventBus, times(1)).post(updateFoundEvent.capture());
- assertThat(updateFoundEvent.getValue().version(), is(new Version(99, 0, 0)));
- assertThat(updateFoundEvent.getValue().releaseTime(), is(11865368297000L));
- assertThat(updateChecker.getLatestVersion(), is(new Version(99, 0, 0)));
- assertThat(updateChecker.getLatestVersionDate(), is(11865368297000L));
- assertThat(updateChecker.hasLatestVersion(), is(true));
+ verifyEventIsFired(new Version(99, 0, 0), 11865368297000L, false);
+ verifyThatUpdateCheckerKnowsLatestVersion(new Version(99, 0, 0), 11865368297000L);
}
private FetchResult createFutureFetchResult() {
ClientMetadata clientMetadata = new ClientMetadata("application/xml");
Bucket fetched = new ArrayBucket(("# MapConfigurationBackendVersion=1\n" +
"CurrentVersion/Version: 99.0.0\n" +
- "CurrentVersion/ReleaseTime: 11865368297000").getBytes());
+ "CurrentVersion/ReleaseTime: 11865368297000\n" +
+ "DisruptiveVersion/0.1.2: true").getBytes());
return new FetchResult(clientMetadata, fetched);
}
+ private void verifyEventIsFired(Version version, long releaseTime, boolean disruptive) {
+ ArgumentCaptor updateFoundEvent = forClass(UpdateFoundEvent.class);
+ verify(eventBus, times(1)).post(updateFoundEvent.capture());
+ assertThat(updateFoundEvent.getValue().getVersion(), is(version));
+ assertThat(updateFoundEvent.getValue().getReleaseTime(), is(releaseTime));
+ assertThat(updateFoundEvent.getValue().isDisruptive(), is(disruptive));
+ }
+
+ private void verifyThatUpdateCheckerKnowsLatestVersion(Version version, long releaseTime) {
+ assertThat(updateChecker.getLatestVersion(), is(version));
+ assertThat(updateChecker.getLatestVersionDate(), is(releaseTime));
+ assertThat(updateChecker.hasLatestVersion(), is(true));
+ }
+
@Test
public void callbackDoesNotStartIfNoNewEditionIsFound() {
setupFetchResult(createPastFetchResult());
@@ -230,4 +239,22 @@ public class UpdateCheckerTest {
return new FetchResult(clientMetadata, fetched);
}
+ @Test
+ public void disruptiveVersionGetsNotification() {
+ setupFetchResult(createDisruptiveVersionFetchResult());
+ setupCallbackWithEdition(MAX_VALUE, true, false);
+ verifyAFreenetUriIsFetched();
+ verifyEventIsFired(new Version(1, 2, 3), 1289417883000L, true);
+ verifyThatUpdateCheckerKnowsLatestVersion(new Version(1, 2, 3), 1289417883000L);
+ }
+
+ private FetchResult createDisruptiveVersionFetchResult() {
+ ClientMetadata clientMetadata = new ClientMetadata("application/xml");
+ Bucket fetched = new ArrayBucket(("# MapConfigurationBackendVersion=1\n" +
+ "CurrentVersion/Version: 1.2.3\n" +
+ "CurrentVersion/ReleaseTime: 1289417883000\n" +
+ "DisruptiveVersion/1.2.3: true").getBytes());
+ return new FetchResult(clientMetadata, fetched);
+ }
+
}