MessageIdDto { public MessageId instantiate(MessageId.Factory factory) { return factory.fromString(messageId); } MessageIdDto(String messageId);  MessageIdDto(MessageId messageId); MessageId instantiate(MessageId.Factory factory); String asString(); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString();  }
@Test void shouldAcceptMessageIdAndGiveItBack() { assertThat(new MessageIdDto(SAMPLE_ID).instantiate(factory)) .isEqualTo(SAMPLE_ID); }
@Test void shouldAcceptStringAndGiveAnInstantiatedMessageId() { assertThat(new MessageIdDto(SAMPLE_ID_STRING).instantiate(factory)) .isEqualTo(SAMPLE_ID); }
@Test void shouldThrowAnExceptionOnWronglyFormattedString() { MessageIdDto messageIdDto = new MessageIdDto("Definitively not a number"); assertThatThrownBy(() -> messageIdDto.instantiate(factory)) .isInstanceOf(Exception.class); }