@Test
  public void testHashCodeAndEquals(){
    AlertDefinitionEntity definition1 = new AlertDefinitionEntity();
    definition1.setDefinitionId(1L);
    AlertDefinitionEntity definition2 = new AlertDefinitionEntity();
    definition2.setDefinitionId(2L);

    AlertHistoryEntity history1 = new AlertHistoryEntity();
    AlertHistoryEntity history2 = new AlertHistoryEntity();

    Assert.assertEquals(history1.hashCode(), history2.hashCode());
    Assert.assertTrue(Objects.equals(history1, history2));

    history1.setAlertDefinition(definition1);
    history2.setAlertDefinition(definition2);
    Assert.assertNotSame(history1.hashCode(), history2.hashCode());
    Assert.assertFalse(Objects.equals(history1, history2));

    history2.setAlertDefinition(definition1);
    Assert.assertEquals(history1.hashCode(), history2.hashCode());
    Assert.assertTrue(Objects.equals(history1, history2));

    history1.setAlertLabel("label");
    history1.setAlertState(AlertState.OK);
    history1.setAlertText("text");
    history1.setAlertTimestamp(1L);
    history1.setClusterId(1L);
    history1.setComponentName("component");
    history1.setServiceName("service");
    history1.setHostName("host");
    history2.setAlertLabel("label");
    history2.setAlertState(AlertState.OK);
    history2.setAlertText("text");
    history2.setAlertTimestamp(1L);
    history2.setClusterId(1L);
    history2.setComponentName("component");
    history2.setServiceName("service");
    history2.setHostName("host");
    Assert.assertEquals(history1.hashCode(), history2.hashCode());
    Assert.assertTrue(Objects.equals(history1, history2));

    history2.setAlertState(AlertState.CRITICAL);
    Assert.assertNotSame(history1.hashCode(), history2.hashCode());
    Assert.assertFalse(Objects.equals(history1, history2));

    history2.setAlertState(AlertState.OK);
    history1.setAlertId(1L);
    history2.setAlertId(1L);
    Assert.assertEquals(history1.hashCode(), history2.hashCode());
    Assert.assertTrue(Objects.equals(history1, history2));

    history2.setAlertId(2L);
    Assert.assertNotSame(history1.hashCode(), history2.hashCode());
    Assert.assertFalse(Objects.equals(history1, history2));
  }
Tests {@link AlertHistoryEntity#hashCode()} and {@link AlertHistoryEntity#equals(Object)}
ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AlertHistoryEntityTest.java