UpdateCheck implements Updater { @Override public Version getLatestVersion() { assertCheckHasRun(); if (!latestVersionIsNewerThanInstalledVersion()) { return currentVersion; } return latestUpdate.getVersion(); } UpdateCheck(UpdateConnection updateConnection); @Override UpdateAvailability hasUpdate(); @Override Version getInstalledVersion(); @Override Version getLatestVersion(); @Override OngoingInstallation updateToLatestVersion(); @Override synchronized void runCheck();  }
@Test public void returnsCurrentVersionIfNoNewerIsAvailable() throws Exception { when(connection.getLatestAvailableUpdate()).thenReturn(update); Version version = getLatestVersion(); assertThat(version, is(currentVersion)); }
@Test public void doesNotChangeStateIfNewerVersionBecomesAvailableLater() throws Exception { when(connection.getLatestAvailableUpdate()).thenReturn(update); when(update.getVersion()).thenReturn(latestVersion); InstallableUpdate newUpdate = mock(InstallableUpdate.class); when(newUpdate.getVersion()).thenReturn(new NumericVersion(1, 1, 0)); when(connection.getLatestAvailableUpdate()).thenReturn(update, newUpdate); Version version = getLatestVersion(); assertThat(version, is(currentVersion)); }
@Test(expected = IllegalStateException.class) public void expectsCheckToBeRunBeforeQueryingLatestVersion() throws Exception { UpdateCheck updateCheck = createUpdateCheck(); updateCheck.getLatestVersion(); }