UpdateChecker { @Scheduled(fixedRate=24 * 60 * 60 * 1000) public void checkForUpdate() { if (isCheckNecessary()) { log.info("checking for documentr update"); lastCheckTime = System.currentTimeMillis(); Version currentVersion = getCurrentVersion(); if (currentVersion != null) { log.debug("current version: {}", currentVersion); Version latestVersion = getLatestVersionFromServer(); if (latestVersion != null) { log.debug("latest version: {}", latestVersion); if (latestVersion.compareTo(currentVersion) > 0) { updateAvailable = true; this.latestVersion = latestVersion.toString(); log.info("documentr update available: {}", latestVersion); } else { log.info("documentr version is up to date"); } } else { log.debug("couldn't determine latest version"); } } else { log.debug("couldn't determine current version"); } } }  @Scheduled(fixedRate=24 * 60 * 60 * 1000) void checkForUpdate();  }
@Test public void checkForUpdate() throws IOException { when(downloader.getTextFromUrl(updatePropertiesUrl, Charsets.UTF_8)) .thenReturn(LATEST_VERSION + "=2012-10-26"); updateChecker.checkForUpdate(); assertTrue(updateChecker.isUpdateAvailable()); assertEquals(LATEST_VERSION, updateChecker.getLatestVersion()); }
@Test public void checkForUpdateButNoUpdateAvailable() throws IOException { when(downloader.getTextFromUrl(updatePropertiesUrl, Charsets.UTF_8)) .thenReturn(CURRENT_VERSION + "=2012-10-26"); updateChecker.checkForUpdate(); assertFalse(updateChecker.isUpdateAvailable()); }