From: David ‘Bombe’ Roden Date: Fri, 26 Feb 2016 23:46:28 +0000 (+0100) Subject: Inject current version into update checker X-Git-Tag: 0.9.5^2~43^2~5 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=11bcfe02cef90ea88c19b30cd796d563c4567a96;p=Sone.git Inject current version into update checker --- diff --git a/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java b/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java index 07398ec..dbca3f1 100644 --- a/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java +++ b/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java @@ -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; } /** diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 828d1af..53a942d 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -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) { diff --git a/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java b/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java index a5e3b2a..fd7a02a 100644 --- a/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java +++ b/src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java @@ -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