EmailDomain extends AbstractStringDomain { public boolean contains( String value) { return super.contains( value) && isEmail( value); } EmailDomain();  EmailDomain( int maxLength);  EmailDomain( Characters chars);  EmailDomain( int maxLength, Characters chars); boolean contains( String value); static boolean isEmail( String value);  }
@Test public void whenConstant() { String value = "me;myself;i@mydomain.org"; StringConstant domain = new EmailConstant( value); List<String> values = valuesOf( domain, 10); assertThat( "Constant values size", values.size(), is( 1)); assertThat( "Constant value", domain.select( getResolverContext()), matches( dataValueMatcher( value, Type.STRING, "email"))); assertThat( "Contains", domain.contains( value), is( true)); assertThat( "Contains", domain.contains( ""), is( false)); }
@Test public void whenEnum() { List<String> emails = Arrays.asList( "me@mydomain.org", "me@mydomain.org", "myself@mydomain.org"); EmailEnum domain = new EmailEnum( emails); List<String> values = valuesOf( domain, 1000); assertThat( "Enum values size", values.size(), is( 1000)); assertThat( "Enum values content", values.stream().collect( toSet()), containsMembers( Arrays.asList( "me@mydomain.org", "myself@mydomain.org"))); assertThat( "Contains", domain.contains( "myself@mydomain.org"), is( true)); assertThat( "Contains", domain.contains( "you@mydomain.org"), is( false)); }
@Test public void whenDefaultLength() { EmailDomain domain = new EmailDomain(); domain.setExcluded( Stream.of( "me@mydomain.org").collect( toSet())); verifyContainsValues( domain, 1000); assertThat( "Contains", domain.contains( "me@mydomain.org"), is( false)); assertThat( "Contains", domain.contains( "@"), is( false)); assertThat( "Contains", domain.contains( "@mydomain.org"), is( false)); assertThat( "Contains", domain.contains( "MeMyselfAndI"), is( false)); }
@Test public void whenLengthValid() { EmailDomain domain = new EmailDomain( 16); domain.setMatching( ".org$"); domain.setNotMatching( "^\\d"); verifyContainsValues( domain, 1000); assertThat( "Contains", domain.contains( "you@mydomain.org"), is( true)); assertThat( "Contains", domain.contains( "myself@mydomain.org"), is( false)); assertThat( "Contains", domain.contains( "you@mydomain.com"), is( false)); assertThat( "Contains", domain.contains( "9ou@mydomain.org"), is( false)); DataValue<String> value = domain.select( getResolverContext()); assertThat( "Value", value, matches( dataValueMatcher( value.getValue(), Type.STRING, "email"))); }
@Test public void whenCharsDefined() { EmailDomain domain = new EmailDomain( Characters.COOKIE_VALUE); assertThat( "Email cookie", domain.contains( "me;myself;i@mydomain.org"), is( false)); List<String> values = valuesOf( domain, 1000); assertThat( "Email cookies", values.stream().filter( e -> !Characters.COOKIE_VALUE.allowed( e)).findFirst(), is( Optional.empty())); }