@Test
 public void should_format_iterable_with_custom_start_and_end() {
   List<? extends Object> list = asList("First", 3);
   assertThat(STANDARD_REPRESENTATION.singleLineFormat(list, "{", "}"))
       .isEqualTo("{\"First\", 3}");
   assertThat(STANDARD_REPRESENTATION.singleLineFormat(asList(), "{", "}")).isEqualTo("{}");
 }
 @Test
 public void should_format_iterable_on_one_line_if_description_is_short_enough() {
   String e1 = stringOfLength(StandardRepresentation.getMaxLengthForSingleLineDescription() / 10);
   String e2 = stringOfLength(StandardRepresentation.getMaxLengthForSingleLineDescription() / 10);
   assertThat(STANDARD_REPRESENTATION.smartFormat(asList(e1, e2)))
       .isEqualTo("[\"" + e1 + "\", \"" + e2 + "\"]");
 }
 @Test
 public void should_format_recursive_iterable() {
   List<Object> list = new ArrayList<>();
   list.add(list);
   list.add(list);
   String formatted = STANDARD_REPRESENTATION.multiLineFormat(list);
   assertThat(formatted).isEqualTo(format("[(this Collection),%n" + "    (this Collection)]"));
 }
 @Test
 public void
     should_format_iterable_with_one_element_per_line_when_single_line_description_is_too_long() {
   String e1 = stringOfLength(StandardRepresentation.getMaxLengthForSingleLineDescription());
   String e2 = stringOfLength(StandardRepresentation.getMaxLengthForSingleLineDescription());
   assertThat(STANDARD_REPRESENTATION.smartFormat(asList(e1, e2)))
       .isEqualTo(format("[\"" + e1 + "\",%n" + "    \"" + e2 + "\"]"));
 }
 @Test
 public void should_format_iterable_with_an_element_per_line() {
   String formatted = STANDARD_REPRESENTATION.multiLineFormat(asList("First", 3, "foo", "bar"));
   String formattedAfterNewLine =
       org.assertj.core.util.Compatibility.System.lineSeparator() + "  <" + formatted + ">";
   assertThat(formattedAfterNewLine)
       .isEqualTo(
           format("%n" + "  <[\"First\",%n" + "    3,%n" + "    \"foo\",%n" + "    \"bar\"]>"));
 }
Ejemplo n.º 6
0
 String formatLines(List<T> lines) {
   return STANDARD_REPRESENTATION.format(
       lines, DEFAULT_START, DEFAULT_END, ELEMENT_SEPARATOR_WITH_NEWLINE, "   ");
 }
 @Test
 public void should_return_empty_brackets_if_iterable_is_empty() {
   assertThat(STANDARD_REPRESENTATION.smartFormat(asList())).isEqualTo("[]");
 }
 @Test
 public void should_return_null_if_iterable_is_null() {
   assertThat(STANDARD_REPRESENTATION.smartFormat(null)).isNull();
 }