ArgumentPlaceholder extends AbstractArgumentPlaceholder { 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(); } ArgumentPlaceholder();   }
@Test public void testFormatAllShouldHandleSingleValueCorrectly() { final List<Object> arguments = list(12.45); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("12.45"); }
@Test public void testFormatAllShouldReturnAllThreeValuesCorrectly() { final List<Object> arguments = list("test", 1, 2L); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("test, 1, 2"); }
@Test public void testFormatAllHandleNullSpecially() { final List<Object> arguments = list(null); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo(STRING_NULL); }
@Test public void testFormatAllHandleNullNullCorrectly() { final List<Object> arguments = list(null, (Object) null); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("<null>, <null>"); }
@Test public void testFormatAllDoesNotThrowNullPointerExceptionIfParamsToStringReturningNull() { final List<Object> arguments = list(new TestToString(null)); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("<null>"); }
@Test public void testFormatAllHandleEmtpyStringSpecially() { final List<Object> arguments = list(""); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo(STRING_EMPTY); }
@Test public void testFormatAllReplacesNullTerminatorWithTheirPrintableCounterpart() { final List<Object> arguments = list("\0"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("\\0"); }
@Test public void testFormatAllReplacesNullTerminatorWithTheirPrintableCounterpartEvenIfWithText() { final List<Object> arguments = list("test\0test\0"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("test\\0test\\0"); }
@Test public void testFormatAllReplacesCarriageReturnWithTheirPrintableCounterpart() { final List<Object> arguments = list("\r"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("\\r"); }
@Test public void testFormatAllReplacesCarriageReturnsWithTheirPrintableCounterpartEvenIfWithText() { final List<Object> arguments = list("test\rtest\r"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("test\\rtest\\r"); }
@Test public void testFormatAllReplacesLineFeedWithTheirPrintableCounterpart() { final List<Object> arguments = list("\n"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("\\n"); }
@Test public void testFormatAllReplacesLineFeedsWithTheirPrintableCounterpartEvenIfWithText() { final List<Object> arguments = list("1\n2\n3"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("1\\n2\\n3"); }
@Test public void testFormatAllReplacesNonPrintableCharactersWithPredefinedPrintableCounterpart() { final List<Object> arguments = list("\u001F"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo(STRING_NON_PRINTABLE); }
@Test public void testFormatAllReplacesNonPrintableCharactersWithPredefinedPrintableCounterpartEvenIfWithText() { final List<Object> arguments = list("test\btest\uFFFF"); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("test" + STRING_NON_PRINTABLE + "test" + STRING_NON_PRINTABLE); }
@Test public void testFormatAllReplacesCarriageReturnsAndLineFeedsWithTheirPrintableCounterpart() { final List<Object> arguments = list("A very\r\nlong text\nwith multiple\rdifferent newline\n\rvariations."); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("A very\\r\\nlong text\\nwith multiple\\rdifferent newline\\n\\rvariations."); }
@Test public void testFormatAllHandleObjectArrayCorrectly() { final List<Object> arguments = list(new Object[] { 7.5, "test" }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[7.5, test]"); }
@Test public void testFormatAllHandlePrimitiveBooleanTypeArrayCorrectly() { final List<Object> arguments = list(new boolean[] { true, false }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[true, false]"); }
@Test public void testFormatAllHandlePrimitiveByteTypeArrayCorrectly() { final List<Object> arguments = list(new byte[] { 12, 24 }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[12, 24]"); }
@Test public void testFormatAllHandlePrimitiveCharTypeArrayCorrectly() { final List<Object> arguments = list(new char[] { 'a', '0' }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[a, 0]"); }
@Test public void testFormatAllHandlePrimitiveShortTypeArrayCorrectly() { final List<Object> arguments = list(new short[] { 1024 }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[1024]"); }
@Test public void testFormatAllHandlePrimitiveIntTypeArrayCorrectly() { final List<Object> arguments = list(new int[] { 11, 2 }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[11, 2]"); }
@Test public void testFormatAllHandlePrimitiveLongTypeArrayCorrectly() { final List<Object> arguments = list(new long[] { 111L, 222L, 333L }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[111, 222, 333]"); }
@Test public void testFormatAllHandlePrimitiveFloatTypeArrayCorrectly() { final List<Object> arguments = list(new float[] { 0.3f, 0.9f, 0.81f, 0.6561f }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[0.3, 0.9, 0.81, 0.6561]"); }
@Test public void testFormatAllHandlePrimitiveDoubleTypeArrayCorrectly() { final List<Object> arguments = list(new double[] { .78, 3.15E2 }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[0.78, 315.0]"); }
@Test public void testFormatAllHandleFurtherNestedArraysCorrectly() { final List<Object> arguments = list(new Object[] { 2, new char[] { 'a', 'b' }, new String[] { "a", "b" } }); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[2, [a, b], [a, b]]"); }
@Test public void testFormatAllHandleObjectCorrectly() { final List<Object> arguments = list(new Object()); String result = underTest.formatAll(arguments); assertThat(result).matches("java.lang.Object@[0-9a-f]+"); }
@Test public void testFormatAllHandleListsCorrectly() { final List<Object> arguments = list(list("test", 1, 1723940567289346512L), 3); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("[test, 1, 1723940567289346512], 3"); }
@Test public void testFormatAllHandleEnumsCorrectly() { final List<Object> arguments = list(Thread.State.RUNNABLE); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo("RUNNABLE"); }
@Test public void testFormatAllHandleComplexExampleCorrectly() { Date now = new Date(); final List<Object> arguments = list( now, Double.valueOf(3.5), new StringBuilder("1").append("|2").append("|3"), new File("src/main/java/com/tngtech") ); String result = underTest.formatAll(arguments); assertThat(result).isEqualTo(now.toString() + ", 3.5, 1|2|3, src/main/java/com/tngtech"); }