VersionManagerImpl implements VersionManager { @Override public ReleaseInfo getRemoteReleaseInfo() { Release latestRelease = releaseDao.getLatestRelease(); boolean needsUpdate = new VersionComparator().compare(currentVersion, latestRelease.getName()) == -1; return new ReleaseInfo(latestRelease.getName(), needsUpdate, latestRelease.getUrl()); } @Inject  VersionManagerImpl(final ReleaseDao releaseDao, @Named("currentVersion") final String currentVersion); @Override String getCurrentVersion(); @Override ReleaseInfo getRemoteReleaseInfo(); @Override void updateRemoteReleaseInfo();  }
@Test public void testGetRemoteReleaseInfo() { ReleaseDao releaseDao = createMock(ReleaseDao.class); Release release = new Release(); release.setName("V 0.6.3"); release.setUrl("url"); release.setDraft(false); expect(releaseDao.getLatestRelease()).andReturn(release); replay(releaseDao); VersionManagerImpl versionManager = new VersionManagerImpl(releaseDao, "0.6.3"); ReleaseInfo releaseInfo = versionManager.getRemoteReleaseInfo(); assertNotNull(releaseInfo); assertNotNull(releaseInfo.getName()); assertNotNull(releaseInfo.getUrl()); assertFalse(releaseInfo.isNeedsUpdate()); verify(releaseDao); }
@Test public void testGetRemoteReleaseInfoNeedsUpdate() { ReleaseDao releaseDao = createMock(ReleaseDao.class); Release release = new Release(); release.setName("V 0.6.3"); release.setUrl("url"); release.setDraft(false); expect(releaseDao.getLatestRelease()).andReturn(release); replay(releaseDao); VersionManagerImpl versionManager = new VersionManagerImpl(releaseDao, "0.6.2"); ReleaseInfo releaseInfo = versionManager.getRemoteReleaseInfo(); assertNotNull(releaseInfo); assertNotNull(releaseInfo.getName()); assertNotNull(releaseInfo.getUrl()); assertTrue(releaseInfo.isNeedsUpdate()); verify(releaseDao); }