From 11bcfe02cef90ea88c19b30cd796d563c4567a96 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 27 Feb 2016 00:46:28 +0100 Subject: [PATCH] Inject current version into update checker --- src/main/java/net/pterodactylus/sone/core/UpdateChecker.java | 9 ++++++--- src/main/java/net/pterodactylus/sone/main/SonePlugin.java | 1 + src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) 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 -- 2.7.4