@Override protected String format(Object param) { return super.format(param); } }
@Override protected String format(Object param) { return super.format(param); } }
/** * Formats the given arguments by retrieving it's {@link String} representation and separate it by comma (= * {@code ,}). * * @param arguments to be formatted * @return the {@link String} representation of the given {@link List}{@code <Object>} */ protected String formatAll(List<Object> arguments) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < arguments.size(); i++) { stringBuilder.append(format(arguments.get(i))); if (i < arguments.size() - 1) { stringBuilder.append(", "); } } return stringBuilder.toString(); } }
@Test public void testFormatForCustomObjectReplacesCarriageReturnWithTheirPrintableCounterpart() { // Given: final TestToString argument = new TestToString("\r"); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("\\r"); }
@Test public void testFormatForCustomObjectReplacesLineFeedWithTheirPrintableCounterpart() { // Given: final TestToString argument = new TestToString("\n"); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("\\n"); }
@Test public void testFormatForCustomObjectReplacesLineFeedsWithTheirPrintableCounterpartEvenIfWithText() { // Given: final TestToString argument = new TestToString("1\n2\n3"); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("1\\n2\\n3"); }
@Test public void testFormatForCustomObjectReplacesCarriageReturnsAndLineFeedsWithTheirPrintableCounterpart() { // Given: final TestToString argument = new TestToString( "A very\r\nlong text\nwith multiple\rdifferent newline\n\rvariations."); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("A very\\r\\nlong text\\nwith multiple\\rdifferent newline\\n\\rvariations."); }
@Test public void testFormatForCustomObjectReplacesCarriageReturnsWithTheirPrintableCounterpartEvenIfWithText() { // Given: final TestToString argument = new TestToString("test\rtest\r"); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("test\\rtest\\r"); }
@Test public void testFormatForCustomObjectReplacesNullFromToString() { // Given: final TestToString argument = new TestToString(null); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo(STRING_NULL); }