EmailFieldFormat { public static Function<Locale, String> localeFormatterFrom(@NonNull final LoggingStrategy loggingStrategy) { switch (loggingStrategy) { case PLAIN_TEXT: return EmailFieldFormat::plainText; case HIDDEN: break; case FIRST_DOZEN_THEN_STARS: case FULL_TEXT_FROM_COMMERCIAL_AT: case FULL_TEXT_UP_TO_COMMERCIAL_AT: case STANDARD_DATE_FORMAT: case STANDARD_DATE_FORMAT_WITH_ZONE_ID: default: logUnsupportedLoggingStrategy(loggingStrategy, "Locale"); } 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 shouldLocaleFormatterFromThrowExceptionGivenNullLoggingStrategy() { expectedException.expect(NullPointerException.class); EmailFieldFormat.localeFormatterFrom(null); fail(); }
@Test public void shouldLocaleFormatterFromReturnProperFormatter() throws Exception { Locale locale = Locale.ENGLISH; Function<Locale, String> expectedPlainTextOperator = EmailFieldFormat::plainText; Function<Locale, String> expectedHiddenOperator = null; Function<Locale, String> expectedFirstDozenThenStartsOperator = null; ; Function<Locale, String> expectedFullTextFromCommercialAtOperator = null; Function<Locale, String> expectedFullTextUpToCommercialAtOperator = null; Function<Locale, String> expectedStandardDateOperator = null; Function<Locale, String> expectedStandardDateWithZoneIdOperator = null; Function<Locale, String> givenPlainTextOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.PLAIN_TEXT); Function<Locale, String> givenHiddenOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.HIDDEN); Function<Locale, String> givenFirstDozenThenStartsOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.FIRST_DOZEN_THEN_STARS); Function<Locale, String> givenFullTextFromCommercialAtOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.FULL_TEXT_FROM_COMMERCIAL_AT); Function<Locale, String> givenFullTextUpToCommercialAtOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.FULL_TEXT_UP_TO_COMMERCIAL_AT); Function<Locale, String> givenStandardDateOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.STANDARD_DATE_FORMAT); Function<Locale, String> givenStandardDateWithZoneIdOperator = EmailFieldFormat.localeFormatterFrom(LoggingStrategy.STANDARD_DATE_FORMAT_WITH_ZONE_ID); assertions.assertThat(givenPlainTextOperator.apply(locale)).isEqualTo(expectedPlainTextOperator.apply(locale)); assertions.assertThat(givenHiddenOperator).isEqualTo(expectedHiddenOperator).isNull(); assertions.assertThat(givenFirstDozenThenStartsOperator).isEqualTo(expectedFirstDozenThenStartsOperator).isNull(); assertions.assertThat(givenFullTextFromCommercialAtOperator).isEqualTo(expectedFullTextFromCommercialAtOperator).isNull(); assertions.assertThat(givenFullTextUpToCommercialAtOperator).isEqualTo(expectedFullTextUpToCommercialAtOperator).isNull(); assertions.assertThat(givenStandardDateOperator).isEqualTo(expectedStandardDateOperator).isNull(); assertions.assertThat(givenStandardDateWithZoneIdOperator).isEqualTo(expectedStandardDateWithZoneIdOperator).isNull(); }