@Test
public void testPerformWithVersion() throws Exception {

  final HostsRepositoryVersionCheck hostsRepositoryVersionCheck = new HostsRepositoryVersionCheck();
  hostsRepositoryVersionCheck.clustersProvider = new Provider<Clusters>() {
    @Override
    public Clusters get() {
      return clusters;
    }
  };
  hostsRepositoryVersionCheck.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() {
    @Override
    public RepositoryVersionDAO get() {
      return repositoryVersionDAO;
    }
  };
  hostsRepositoryVersionCheck.hostVersionDaoProvider = new Provider<HostVersionDAO>() {
    @Override
    public HostVersionDAO get() {
      return hostVersionDAO;
    }
  };
  final Cluster cluster = Mockito.mock(Cluster.class);
  Mockito.when(cluster.getClusterId()).thenReturn(1L);
  Mockito.when(cluster.getDesiredStackVersion()).thenReturn(new StackId());
  Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
  final Map<String, Host> hosts = new HashMap<String, Host>();
  final Host host1 = Mockito.mock(Host.class);
  final Host host2 = Mockito.mock(Host.class);
  final Host host3 = Mockito.mock(Host.class);
  Mockito.when(host1.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
  Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
  Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
  hosts.put("host1", host1);
  hosts.put("host2", host2);
  hosts.put("host3", host3);
  Mockito.when(clusters.getHostsForCluster("cluster")).thenReturn(hosts);
  RepositoryVersionEntity rve = new RepositoryVersionEntity();
  rve.setVersion("1.1.1");
  HostVersionEntity hve = new HostVersionEntity();
  hve.setRepositoryVersion(rve);
  hve.setState(RepositoryVersionState.INSTALLED);
  Mockito.when(
      hostVersionDAO.findByHost(Mockito.anyString())).thenReturn(
          Collections.singletonList(hve));
  PrerequisiteCheck check = new PrerequisiteCheck(null, null);
  PrereqCheckRequest request = new PrereqCheckRequest("cluster");
  request.setRepositoryVersion("1.1.1");
  hostsRepositoryVersionCheck.perform(check, request);
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
}