public static User fromUsername(String username) { Preconditions.checkNotNull(username); Preconditions.checkArgument(!Strings.isNullOrEmpty(username)); List<String> parts = ImmutableList.copyOf(Splitter.on('@').split(username)); switch (parts.size()) { case 1: return fromLocalPartWithoutDomain(username); case 2: return fromLocalPartWithDomain(parts.get(0), parts.get(1)); } throw new IllegalArgumentException("The username should not contain multiple domain delimiter."); }
public static User fromUsername(String username) { Preconditions.checkNotNull(username); Preconditions.checkArgument(!Strings.isNullOrEmpty(username)); List<String> parts = ImmutableList.copyOf(Splitter.on('@').split(username)); switch (parts.size()) { case 1: return fromLocalPartWithoutDomain(username); case 2: return fromLocalPartWithDomain(parts.get(0), parts.get(1)); } throw new IllegalArgumentException("The username should not contain multiple domain delimiter."); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnNullDomainPart() { String domain = null; assertThatThrownBy(() -> User.fromLocalPartWithDomain("local", domain)) .isInstanceOf(NullPointerException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnEmptyDomainPart() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("local", "")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnDomainPartThatContainsDomainDelimiter() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("local", "aa@bb")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnEmptyDomainPart() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("local", "")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnNullLocalPart() { assertThatThrownBy(() -> User.fromLocalPartWithDomain(null, "domain")) .isInstanceOf(NullPointerException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnLocalPartThatContainsDomainDelimiter() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("aa@bb", "domain")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnNullDomainPart() { String domain = null; assertThatThrownBy(() -> User.fromLocalPartWithDomain("local", domain)) .isInstanceOf(NullPointerException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnEmptyLocalPart() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("", "domain")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnLocalPartThatContainsDomainDelimiter() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("aa@bb", "domain")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnEmptyLocalPart() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("", "domain")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnDomainPartThatContainsDomainDelimiter() { assertThatThrownBy(() -> User.fromLocalPartWithDomain("local", "aa@bb")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void fromLocalPartWithDomainStringVersionShouldThrowOnNullLocalPart() { assertThatThrownBy(() -> User.fromLocalPartWithDomain(null, "domain")) .isInstanceOf(NullPointerException.class); }
@Test public void fromLocalPartWithDomainShouldReturnAValidUser() { assertThat(User.fromLocalPartWithDomain("aa", "bb")) .isEqualTo(User.from("aa", Optional.of("bb"))); }
@Test public void hasDomainPartShouldReturnTrueWhenHasADomain() { assertThat(User.fromLocalPartWithDomain("aa", "domain").hasDomainPart()) .isTrue(); }
@Test public void hasDomainPartShouldReturnTrueWhenHasADomain() { assertThat(User.fromLocalPartWithDomain("aa", "domain").hasDomainPart()) .isTrue(); }
@Override protected Mappings mapAddress(String user, Domain domain) { return OptionalUtils.orSuppliers( () -> retrieveMappings(MappingSource.fromUser(User.fromLocalPartWithDomain(user, domain))), () -> retrieveMappings(MappingSource.fromDomain(domain))) .orElse(MappingsImpl.empty()); }
@Test public void withDefaultDomainShouldAppendDefaultDomainWhenNone() { assertThat(User.fromUsername("user") .withDefaultDomain(Domain.LOCALHOST)) .isEqualTo(User.fromLocalPartWithDomain("user", Domain.LOCALHOST)); }
@Test public void withDefaultDomainShouldAppendDefaultDomainWhenNone() { assertThat(User.fromUsername("user") .withDefaultDomain(Domain.LOCALHOST)) .isEqualTo(User.fromLocalPartWithDomain("user", Domain.LOCALHOST)); }