@Test
public void testFailWhenServiceWithOutdatedServiceCheckExists() throws AmbariException {

  ServiceComponent serviceComponent = mock(ServiceComponent.class);
  when(serviceComponent.isVersionAdvertised()).thenReturn(true);
  when(service.getMaintenanceState()).thenReturn(MaintenanceState.OFF);
  when(service.getServiceComponents()).thenReturn(ImmutableMap.of(SERVICE_COMPONENT_NAME, serviceComponent));
  ServiceConfigEntity serviceConfigEntity = new ServiceConfigEntity();
  serviceConfigEntity.setServiceName(SERVICE_NAME);
  serviceConfigEntity.setCreateTimestamp(CONFIG_CREATE_TIMESTAMP);
  HostRoleCommandEntity hostRoleCommandEntity = new HostRoleCommandEntity();
  hostRoleCommandEntity.setRoleCommand(RoleCommand.SERVICE_CHECK);
  hostRoleCommandEntity.setCommandDetail(COMMAND_DETAIL);
  hostRoleCommandEntity.setStartTime(SERVICE_CHECK_START_TIME);
  hostRoleCommandEntity.setRole(Role.HDFS_SERVICE_CHECK);
  when(serviceConfigDAO.getLastServiceConfig(eq(CLUSTER_ID), eq(SERVICE_NAME))).thenReturn(serviceConfigEntity);
  when(hostRoleCommandDAO.findAll(any(Request.class), any(Predicate.class))).thenReturn(singletonList(hostRoleCommandEntity));
  PrerequisiteCheck check = new PrerequisiteCheck(null, CLUSTER_NAME);
  serviceCheckValidityCheck.perform(check, new PrereqCheckRequest(CLUSTER_NAME));
  Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
}