EmailFieldFormat { public static UnaryOperator<String> textFormatterFrom(@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: case FULL_TEXT_UP_TO_COMMERCIAL_AT: case STANDARD_DATE_FORMAT: case STANDARD_DATE_FORMAT_WITH_ZONE_ID: default: logUnsupportedLoggingStrategy(loggingStrategy, "String"); } 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 shouldTextFormatterFromThrowExceptionGivenNullLoggingStrategy() { expectedException.expect(NullPointerException.class); EmailFieldFormat.textFormatterFrom(null); fail(); }
@Test public void shouldTextFormatterFromReturnProperFormatter() { final String veryLongText = "qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM 0123456789 @#!$%^&*()_+=-?/|\"':;>.<,{[}]~`"; UnaryOperator<String> expectedPlainTextOperator = EmailFieldFormat::plainText; UnaryOperator<String> expectedHiddenOperator = null; UnaryOperator<String> expectedFirstDozenThenStartsOperator = EmailFieldFormat::firstDozenThenStars; UnaryOperator<String> expectedFullTextFromCommercialAtOperator = null; UnaryOperator<String> expectedFullTextUpToCommercialAtOperator = null; UnaryOperator<String> expectedStandardDateOperator = null; UnaryOperator<String> expectedStandardDateWithZoneIdOperator = null; UnaryOperator<String> givenPlainTextOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.PLAIN_TEXT); UnaryOperator<String> givenHiddenOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.HIDDEN); UnaryOperator<String> givenFirstDozenThenStartsOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.FIRST_DOZEN_THEN_STARS); UnaryOperator<String> givenFullTextFromCommercialAtOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.FULL_TEXT_FROM_COMMERCIAL_AT); UnaryOperator<String> givenFullTextUpToCommercialAtOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.FULL_TEXT_UP_TO_COMMERCIAL_AT); UnaryOperator<String> givenStandardDateOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.STANDARD_DATE_FORMAT); UnaryOperator<String> givenStandardDateWithZoneIdOperator = EmailFieldFormat.textFormatterFrom(LoggingStrategy.STANDARD_DATE_FORMAT_WITH_ZONE_ID); assertions.assertThat(givenPlainTextOperator.apply(veryLongText)).isEqualTo(expectedPlainTextOperator.apply(veryLongText)); assertions.assertThat(givenHiddenOperator).isEqualTo(expectedHiddenOperator).isNull(); assertions.assertThat(givenFirstDozenThenStartsOperator.apply(veryLongText)).isEqualTo(expectedFirstDozenThenStartsOperator.apply(veryLongText)); assertions.assertThat(givenFullTextFromCommercialAtOperator).isEqualTo(expectedFullTextFromCommercialAtOperator).isNull(); assertions.assertThat(givenFullTextUpToCommercialAtOperator).isEqualTo(expectedFullTextUpToCommercialAtOperator).isNull(); assertions.assertThat(givenStandardDateOperator).isEqualTo(expectedStandardDateOperator).isNull(); assertions.assertThat(givenStandardDateWithZoneIdOperator).isEqualTo(expectedStandardDateWithZoneIdOperator).isNull(); }