Cron { @Override public int hashCode() { if (expression == null) { return 0; } return Objects.hash(expression); } Cron(String expression); String getExpression(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void expressionHashcode() { String expression1 = "* * 8 0 * *"; String expression2 = "* * 8 * 0 *"; String expression3 = "* * 8 0 * *"; Cron cron1 = new Cron(expression1); Cron cron2 = new Cron(expression2); Cron cron3 = new Cron(expression3); Cron cron4 = new Cron(null); Cron cron5 = new Cron("0"); assertEquals(cron1.hashCode(), cron3.hashCode()); assertNotEquals(cron1.hashCode(), cron2.hashCode()); assertNotEquals(cron1.hashCode(), cron2.hashCode()); assertEquals(0, cron4.hashCode()); assertNotEquals(0, cron5.hashCode()); }