TaskIds implements TaskId, Serializable { static TaskId create(String name, Object... args) { if (name.contains("(") || name.contains(")")) { throw new IllegalArgumentException("Name can not contain any parenthesis"); } return new AutoValue_TaskIds( name, name.hashCode() * 1000003 ^ Objects.hash(args), argsString(args)); }  abstract String args(); @Override String toString();  }
@Test public void shouldHaveIdentity() { TaskId taskId1 = TaskId.create("MyTask", "a", 1, 2.3, new Param(7)); TaskId taskId2 = TaskId.create("MyTask", "a", 1, 2.3, new Param(7)); assertThat(taskId1, not(sameInstance(taskId2))); assertThat(taskId1, equalTo(taskId2)); assertThat(taskId2, equalTo(taskId1)); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowOpenParenthesisInName() throws Exception { TaskId.create("MyTa(sk"); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowCloseParenthesisInName() throws Exception { TaskId.create("MyTa)sk"); }