@Test
public void testGetEffectiveStateForServiceAlert() throws Exception {

  Injector injector = createStrictMock(Injector.class);
  MaintenanceStateHelper maintenanceStateHelper = createMockBuilder(
      MaintenanceStateHelper.class).withConstructor(injector).createNiceMock();
  Clusters clusters = createMock(Clusters.class);
  Cluster cluster = createMock(Cluster.class);
  Service service = createNiceMock(Service.class);
  final Host host = createNiceMock(Host.class);
  long clusterId = 1L;
  String hostName = "c6401.ambari.apache.org";
  Alert alert = new Alert("foo-alert", null, "HDFS", null, hostName, AlertState.CRITICAL);
  expect(host.getMaintenanceState(clusterId)).andReturn(MaintenanceState.OFF).once();
  expect(clusters.getHost(hostName)).andReturn(host).once();
  expect(clusters.getClusterById(clusterId)).andReturn(cluster).once();
  expect(cluster.getService("HDFS")).andReturn(service).once();
  expect(service.getMaintenanceState()).andReturn(MaintenanceState.ON);
  injectField(maintenanceStateHelper, clusters);
  replay(maintenanceStateHelper, clusters, host, cluster, service);
  MaintenanceState state = maintenanceStateHelper.getEffectiveState(clusterId, alert);
  Assert.assertEquals(MaintenanceState.ON, state);
  verify(maintenanceStateHelper, clusters, host, cluster, service);
}