Inject current version into update checker
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 26 Feb 2016 23:46:28 +0000 (00:46 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 26 Feb 2016 23:46:28 +0000 (00:46 +0100)
src/main/java/net/pterodactylus/sone/core/UpdateChecker.java
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java

index 07398ec..dbca3f1 100644 (file)
@@ -66,7 +66,8 @@ public class UpdateChecker {
        private long latestEdition;
 
        /** The current latest known version. */
-       private Version currentLatestVersion = SonePlugin.VERSION;
+       private Version currentLatestVersion;
+       private final Version currentRunningVersion;
 
        /** The release date of the latest version. */
        private long latestVersionDate;
@@ -80,9 +81,11 @@ public class UpdateChecker {
         *            The freenet interface to use
         */
        @Inject
-       public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface) {
+       public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface, Version currentVersion) {
                this.eventBus = eventBus;
                this.freenetInterface = freenetInterface;
+               this.currentRunningVersion = currentVersion;
+               this.currentLatestVersion = currentVersion;
        }
 
        //
@@ -96,7 +99,7 @@ public class UpdateChecker {
         * @return {@code true} if a new version was found
         */
        public boolean hasLatestVersion() {
-               return currentLatestVersion.compareTo(SonePlugin.VERSION) > 0;
+               return currentLatestVersion.compareTo(currentRunningVersion) > 0;
        }
 
        /**
index 828d1af..53a942d 100644 (file)
@@ -250,6 +250,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                                bind(Context.class).toInstance(context);
                                bind(getOptionalContextTypeLiteral()).toInstance(of(context));
                                bind(SonePlugin.class).toInstance(SonePlugin.this);
+                               bind(Version.class).toInstance(VERSION);
                                if (startConfiguration.getBooleanValue("Developer.LoadFromFilesystem").getValue(false)) {
                                        String path = startConfiguration.getStringValue("Developer.FilesystemPath").getValue(null);
                                        if (path != null) {
index a5e3b2a..fd7a02a 100644 (file)
@@ -44,7 +44,8 @@ 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 UpdateChecker updateChecker = new UpdateChecker(eventBus, freenetInterface, currentVersion);
 
        @Before
        public void startUpdateChecker() {
@@ -54,7 +55,7 @@ public class UpdateCheckerTest {
        @Test
        public void newUpdateCheckerDoesNotHaveALatestVersion() {
                assertThat(updateChecker.hasLatestVersion(), is(false));
-               assertThat(updateChecker.getLatestVersion(), is(VERSION));
+               assertThat(updateChecker.getLatestVersion(), is(currentVersion));
        }
 
        @Test