Group { public static Group deserialize(String serializedGroup) throws GroupDeserializationException { try { Preconditions.checkNotNull(serializedGroup, "A serialized group can not be null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(serializedGroup), "A serialized group can not be empty"); if (serializedGroup.startsWith(GenericGroup.class.getName() + GenericGroup.DELIMITER)) { return new GenericGroup(serializedGroup.substring(GenericGroup.class.getName().length() + 1)); } Class<?> groupClass = Class.forName(serializedGroup); return instantiateGroup(groupClass); } catch (Exception e) { throw new GroupDeserializationException(e); } }  static Group deserialize(String serializedGroup); String asString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test void deserializeShouldReturnGroupWhenGenericGroup() throws Exception { assertThat(Group.deserialize("org.apache.james.mailbox.events.GenericGroup-abc")) .isEqualTo(new GenericGroup("abc")); }
@Test void deserializeShouldReturnGroupWhenEmptyGenericGroup() throws Exception { assertThat(Group.deserialize("org.apache.james.mailbox.events.GenericGroup-")) .isEqualTo(new GenericGroup("")); }
@Test void deserializeShouldReturnGroupWhenExtendsGroup() throws Exception { assertThat(Group.deserialize("org.apache.james.mailbox.events.EventBusTestFixture$GroupA")) .isEqualTo(new EventBusTestFixture.GroupA()); }
@Test void deserializeShouldThrowWhenClassNotFound() { assertThatThrownBy(() -> Group.deserialize("org.apache.james.mailbox.events.Noone")) .isInstanceOf(Group.GroupDeserializationException.class); }
@Test void deserializeShouldThrowWhenNotAGroup() { assertThatThrownBy(() -> Group.deserialize("java.lang.String")) .isInstanceOf(Group.GroupDeserializationException.class); }
@Test void deserializeShouldThrowWhenConstructorArgumentsRequired() { assertThatThrownBy(() -> Group.deserialize("org.apache.james.mailbox.events.GenericGroup")) .isInstanceOf(Group.GroupDeserializationException.class); }
@Test void deserializeShouldThrowWhenNull() { assertThatThrownBy(() -> Group.deserialize(null)) .isInstanceOf(Group.GroupDeserializationException.class); }
@Test void deserializeShouldThrowWhenEmpty() { assertThatThrownBy(() -> Group.deserialize("")) .isInstanceOf(Group.GroupDeserializationException.class); }