EmailFieldFormat { public static Function<InternetAddress, String> emailFormatterFrom(@NonNull final LoggingStrategy loggingStrategy) { switch (loggingStrategy) { case PLAIN_TEXT: return EmailFieldFormat::plainText; case HIDDEN: break; case FIRST_DOZEN_THEN_STARS: return EmailFieldFormat::firstDozenThenStars; case FULL_TEXT_FROM_COMMERCIAL_AT: return EmailFieldFormat::textFromAt; case FULL_TEXT_UP_TO_COMMERCIAL_AT: return EmailFieldFormat::textUpToAt; case STANDARD_DATE_FORMAT: case STANDARD_DATE_FORMAT_WITH_ZONE_ID: default: logUnsupportedLoggingStrategy(loggingStrategy, "InternetAddress"); } return null; }  static UnaryOperator<String> textFormatterFrom(@NonNull final LoggingStrategy loggingStrategy); static Function<InternetAddress, String> emailFormatterFrom(@NonNull final LoggingStrategy loggingStrategy); static Function<Locale, String> localeFormatterFrom(@NonNull final LoggingStrategy loggingStrategy); static Function<Date, String> dateFormatterFrom(@NonNull final LoggingStrategy loggingStrategy); static String plainText(final Locale locale); static String plainText(final InternetAddress internetAddress); static String plainText(final String text); static String firstDozenThenStars(final InternetAddress internetAddress); static String firstDozenThenStars(final String text); static String textFromAt(final InternetAddress internetAddress); static String textFromAt(final String text); static String textUpToAt(final InternetAddress internetAddress); static String textUpToAt(final String text); static String dateFormat(final Date date); static String dateFormatWithZoneId(final Date date); static String nullValue();  }
@Test public void shouldEmailFormatterFromThrowExceptionGivenNullLoggingStrategy() { expectedException.expect(NullPointerException.class); EmailFieldFormat.emailFormatterFrom(null); fail(); }
@Test public void shouldEmailFormatterFromReturnProperFormatter() throws Exception { InternetAddress internetAddress = new InternetAddress("test@email.com", "Mr. Test"); Function<InternetAddress, String> expectedPlainTextOperator = EmailFieldFormat::plainText; Function<InternetAddress, String> expectedHiddenOperator = null; Function<InternetAddress, String> expectedFirstDozenThenStartsOperator = EmailFieldFormat::firstDozenThenStars; Function<InternetAddress, String> expectedFullTextFromCommercialAtOperator = EmailFieldFormat::textFromAt; Function<InternetAddress, String> expectedFullTextUpToCommercialAtOperator = EmailFieldFormat::textUpToAt; Function<InternetAddress, String> expectedStandardDateOperator = null; Function<InternetAddress, String> expectedStandardDateWithZoneIdOperator = null; Function<InternetAddress, String> givenPlainTextOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.PLAIN_TEXT); Function<InternetAddress, String> givenHiddenOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.HIDDEN); Function<InternetAddress, String> givenFirstDozenThenStartsOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.FIRST_DOZEN_THEN_STARS); Function<InternetAddress, String> givenFullTextFromCommercialAtOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.FULL_TEXT_FROM_COMMERCIAL_AT); Function<InternetAddress, String> givenFullTextUpToCommercialAtOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.FULL_TEXT_UP_TO_COMMERCIAL_AT); Function<InternetAddress, String> givenStandardDateOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.STANDARD_DATE_FORMAT); Function<InternetAddress, String> givenStandardDateWithZoneIdOperator = EmailFieldFormat.emailFormatterFrom(LoggingStrategy.STANDARD_DATE_FORMAT_WITH_ZONE_ID); assertions.assertThat(givenPlainTextOperator.apply(internetAddress)).isEqualTo(expectedPlainTextOperator.apply(internetAddress)); assertions.assertThat(givenHiddenOperator).isEqualTo(expectedHiddenOperator).isNull(); assertions.assertThat(givenFirstDozenThenStartsOperator.apply(internetAddress)).isEqualTo(expectedFirstDozenThenStartsOperator.apply(internetAddress)); assertions.assertThat(givenFullTextFromCommercialAtOperator.apply(internetAddress)).isEqualTo(expectedFullTextFromCommercialAtOperator.apply(internetAddress)); assertions.assertThat(givenFullTextUpToCommercialAtOperator.apply(internetAddress)).isEqualTo(expectedFullTextUpToCommercialAtOperator.apply(internetAddress)); assertions.assertThat(givenStandardDateOperator).isEqualTo(expectedStandardDateOperator).isNull(); assertions.assertThat(givenStandardDateWithZoneIdOperator).isEqualTo(expectedStandardDateWithZoneIdOperator).isNull(); }