Preview { public static Preview from(String value) { return new Preview(value); } @VisibleForTesting  Preview(String value); static Preview from(String value); static Preview compute(String textBody); String getValue(); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString(); static final Preview EMPTY; }
@Test void fromShouldReturnACorrectPreview() { assertThat(Preview.from(PREVIEW_RAW_VALUE)) .isEqualTo(new Preview(PREVIEW_RAW_VALUE)); }
@Test void fromShouldThrowWhenNullValue() { assertThatThrownBy(() -> Preview.from(null)) .isInstanceOf(NullPointerException.class); }
@Test void fromShouldThrowWhenValueLengthIsLongerThanMaximum256() { String errorMessageRegex = "the preview value '.*' has length longer than 256"; assertThatThrownBy(() -> Preview.from(Strings.repeat("a", 257))) .isInstanceOf(IllegalArgumentException.class) .hasMessageMatching(errorMessageRegex); }
@Test void fromShouldNotThrowWhenValueLengthIsEqualsToMaximum256() { assertThatCode(() -> Preview.from(Strings.repeat("a", 256))) .doesNotThrowAnyException(); }