@Test
public void testPerform() throws Exception {

  final ServicesMaintenanceModeCheck servicesMaintenanceModeCheck = new ServicesMaintenanceModeCheck();
  servicesMaintenanceModeCheck.clustersProvider = new Provider<Clusters>() {
    @Override
    public Clusters get() {
      return clusters;
    }
  };
  servicesMaintenanceModeCheck.ambariMetaInfo = new Provider<AmbariMetaInfo>() {
    @Override
    public AmbariMetaInfo get() {
      return Mockito.mock(AmbariMetaInfo.class);
    }
  };
  final Cluster cluster = Mockito.mock(Cluster.class);
  Mockito.when(cluster.getClusterId()).thenReturn(1L);
  Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP", "2.2"));
  Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
  final Service service = Mockito.mock(Service.class);
  Mockito.when(cluster.getServices()).thenReturn(Collections.singletonMap("service", service));
  Mockito.when(service.isClientOnlyService()).thenReturn(false);
  // We don't bother checking service desired state as it's performed by a separate check
  Mockito.when(service.getDesiredState()).thenReturn(State.UNKNOWN);
  PrerequisiteCheck check = new PrerequisiteCheck(null, null);
  servicesMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
  Mockito.when(service.getDesiredState()).thenReturn(State.STARTED);
  check = new PrerequisiteCheck(null, null);
  servicesMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster"));
  Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
}