MailRepositoryUrl { public static MailRepositoryUrl from(String url) { Preconditions.checkNotNull(url); Preconditions.checkArgument(url.contains(PROTOCOL_SEPARATOR), "The expected format is: <protocol> \"%s\" <path>", PROTOCOL_SEPARATOR); List<String> urlParts = Splitter.on(PROTOCOL_SEPARATOR).splitToList(url); Protocol protocol = new Protocol(urlParts.get(PROTOCOL_PART)); MailRepositoryPath path = MailRepositoryPath.from( Joiner.on(PROTOCOL_SEPARATOR) .join(Iterables.skip(urlParts, SKIP_PROTOCOL))); return new MailRepositoryUrl(path, protocol); } private  MailRepositoryUrl(MailRepositoryPath path, Protocol protocol); static MailRepositoryUrl fromEncoded(String encodedUrl); static MailRepositoryUrl from(String url); static MailRepositoryUrl fromPathAndProtocol(MailRepositoryPath path, String protocol); static MailRepositoryUrl fromPathAndProtocol(Protocol protocol, MailRepositoryPath path); String asString(); MailRepositoryPath getPath(); MailRepositoryUrl subUrl(String suffix); String urlEncoded(); boolean hasPrefix(MailRepositoryUrl other); Protocol getProtocol(); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString();  }
@Test void constructorShouldThrowWhenNull() { assertThatThrownBy(() -> MailRepositoryUrl.from(null)) .isInstanceOf(NullPointerException.class); }
@Test void constructorShouldThrowWhenNoSeparator() { assertThatThrownBy(() -> MailRepositoryUrl.from("invalid")) .isInstanceOf(IllegalArgumentException.class); }