@Test
public void testCheckHostAndClusterVersions() throws Exception {

  StateRecoveryManager stateRecoveryManager = injector.getInstance(StateRecoveryManager.class);
  // Adding all possible host version states
  final Capture<RepositoryVersionState> installFailedHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> installingHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> installedHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> outOfSyncHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> upgradeFailedHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> upgradingHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> upgradedHostVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> currentHostVersionCapture = EasyMock.newCapture();
  expect(hostVersionDAOMock.findAll()).andReturn(new ArrayList<HostVersionEntity>() {{
    add(getHostVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedHostVersionCapture));
    add(getHostVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingHostVersionCapture));
    add(getHostVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedHostVersionCapture));
    add(getHostVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncHostVersionCapture));
    add(getHostVersionMock("current_version", RepositoryVersionState.CURRENT, currentHostVersionCapture));
  }});
  // Adding all possible cluster version states
  final Capture<RepositoryVersionState> installFailedClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> installingClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> installedClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> outOfSyncClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> upgradeFailedClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> upgradingClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> upgradedClusterVersionCapture = EasyMock.newCapture();
  final Capture<RepositoryVersionState> currentClusterVersionCapture = EasyMock.newCapture();
  expect(clusterVersionDAOMock.findAll()).andReturn(new ArrayList<ClusterVersionEntity>() {{
    add(getClusterVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedClusterVersionCapture));
    add(getClusterVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingClusterVersionCapture));
    add(getClusterVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedClusterVersionCapture));
    add(getClusterVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncClusterVersionCapture));
    add(getClusterVersionMock("current_version", RepositoryVersionState.CURRENT, currentClusterVersionCapture));
  }});
  replay(hostVersionDAOMock, clusterVersionDAOMock);
  stateRecoveryManager.checkHostAndClusterVersions();
  // Checking that only invalid host version states have been changed
  assertFalse(installFailedHostVersionCapture.hasCaptured());
  assertEquals(installingHostVersionCapture.getValue(), RepositoryVersionState.INSTALL_FAILED);
  assertFalse(installedHostVersionCapture.hasCaptured());
  assertFalse(outOfSyncHostVersionCapture.hasCaptured());
  assertFalse(upgradeFailedHostVersionCapture.hasCaptured());
  assertFalse(upgradingHostVersionCapture.hasCaptured());
  assertFalse(upgradedHostVersionCapture.hasCaptured());
  assertFalse(currentHostVersionCapture.hasCaptured());
  // Checking that only invalid cluster version states have been changed
  assertFalse(installFailedClusterVersionCapture.hasCaptured());
  assertEquals(installingClusterVersionCapture.getValue(), RepositoryVersionState.INSTALL_FAILED);
  assertFalse(installedClusterVersionCapture.hasCaptured());
  assertFalse(outOfSyncClusterVersionCapture.hasCaptured());
  assertFalse(upgradeFailedClusterVersionCapture.hasCaptured());
  assertFalse(upgradingClusterVersionCapture.hasCaptured());
  assertFalse(upgradedClusterVersionCapture.hasCaptured());
  assertFalse(currentClusterVersionCapture.hasCaptured());
}