@Test
public void testPreUpgradeCheckClusterMissing() throws Exception {

  final Clusters clusters = Mockito.mock(Clusters.class);
  Mockito.when(clusters.getCluster(Mockito.anyString())).thenAnswer(new Answer<Cluster>() {
    @Override
    public Cluster answer(InvocationOnMock invocation) throws Throwable {
      final String clusterName = invocation.getArguments()[0].toString();
      if (clusterName.equals("existing")) {
        return Mockito.mock(Cluster.class);
      } else {
        throw new ClusterNotFoundException(clusterName);
      }
    }
  });
  final OsFamily osFamily = Mockito.mock(OsFamily.class);
  final Injector injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(Clusters.class).toInstance(clusters);
      bind(ClusterVersionDAO.class).toProvider(Providers.<ClusterVersionDAO>of(null));
      bind(HostVersionDAO.class).toProvider(Providers.<HostVersionDAO>of(null));
      bind(UpgradeDAO.class).toProvider(Providers.<UpgradeDAO>of(null));
      bind(RepositoryVersionDAO.class).toProvider(Providers.<RepositoryVersionDAO>of(null));
      bind(RepositoryVersionHelper.class).toProvider(Providers.<RepositoryVersionHelper>of(null));
      bind(AmbariMetaInfo.class).toProvider(Providers.<AmbariMetaInfo>of(null));
      bind(ServicesUpCheck.class).toInstance(new ServicesUpCheck());
      bind(OsFamily.class).toInstance(osFamily);
    }
  });
  final CheckHelper helper = injector.getInstance(CheckHelper.class);
  List<AbstractCheckDescriptor> updateChecksRegistry = new ArrayList<AbstractCheckDescriptor>();
  // mocked Cluster has no services, so the check should always be PASS
  updateChecksRegistry.add(injector.getInstance(ServicesUpCheck.class));
  List<PrerequisiteCheck> upgradeChecks = helper.performChecks(new PrereqCheckRequest("existing"), updateChecksRegistry);
  Assert.assertEquals(PrereqCheckStatus.PASS, upgradeChecks.get(0).getStatus());
  upgradeChecks = helper.performChecks(new PrereqCheckRequest("non-existing"), updateChecksRegistry);
  Assert.assertEquals(PrereqCheckStatus.FAIL, upgradeChecks.get(0).getStatus());
  //non existing cluster is an expected error
  Assert.assertTrue(!upgradeChecks.get(0).getFailReason().equals("Unexpected server error happened"));
}