@Test public void testFormatAllHandlePrimitiveLongTypeArrayCorrectly() { // Given: final List<Object> arguments = list(new long[] { 111L, 222L, 333L }); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("[111, 222, 333]"); }
@Test public void testFormatAllHandleFurtherNestedArraysCorrectly() { // Given: final List<Object> arguments = list(new Object[] { 2, new char[] { 'a', 'b' }, new String[] { "a", "b" } }); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("[2, [a, b], [a, b]]"); }
@Test public void testFormatAllShouldReturnAllThreeValuesCorrectly() { // Given: final List<Object> arguments = list("test", 1, 2L); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("test, 1, 2"); }
@Test public void testFormatAllReplacesCarriageReturnsWithTheirPrintableCounterpartEvenIfWithText() { // Given: final List<Object> arguments = list("test\rtest\r"); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("test\\rtest\\r"); }
@Test public void testFormatAllReplacesNonPrintableCharactersWithPredefinedPrintableCounterpart() { // Given: final List<Object> arguments = list("\u001F"); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo(STRING_NON_PRINTABLE); }
@Test public void testFormatAllReplacesNonPrintableCharactersWithPredefinedPrintableCounterpartEvenIfWithText() { // Given: final List<Object> arguments = list("test\btest\uFFFF"); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("test" + STRING_NON_PRINTABLE + "test" + STRING_NON_PRINTABLE); }
@Test public void testFormatAllHandlePrimitiveByteTypeArrayCorrectly() { // Given: final List<Object> arguments = list(new byte[] { 12, 24 }); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("[12, 24]"); }
@Test public void testFormatAllShouldHandleSingleValueCorrectly() { // Given: final List<Object> arguments = list(12.45); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("12.45"); }
@Test public void testFormatAllReplacesCarriageReturnWithTheirPrintableCounterpart() { // Given: final List<Object> arguments = list("\r"); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("\\r"); }
@Test public void testFormatAllReplacesCarriageReturnsAndLineFeedsWithTheirPrintableCounterpart() { // Given: final List<Object> arguments = list("A very\r\nlong text\nwith multiple\rdifferent newline\n\rvariations."); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("A very\\r\\nlong text\\nwith multiple\\rdifferent newline\\n\\rvariations."); }
@Test public void testFormatAllHandlePrimitiveFloatTypeArrayCorrectly() { // Given: final List<Object> arguments = list(new float[] { 0.3f, 0.9f, 0.81f, 0.6561f }); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("[0.3, 0.9, 0.81, 0.6561]"); }
@Test public void testFormatAllHandleEnumsCorrectly() { // Given: final List<Object> arguments = list(Thread.State.RUNNABLE); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("RUNNABLE"); }
@Test public void testFormatAllHandlePrimitiveShortTypeArrayCorrectly() { // Given: final List<Object> arguments = list(new short[] { 1024 }); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo("[1024]"); }
@Test public void testFormatAllHandleObjectCorrectly() { // Given: final List<Object> arguments = list(new Object()); // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).matches("java.lang.Object@[0-9a-f]+"); }
@Test public void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingMixedIndicesOtherWayRound() { // Given: final List<Object> arguments = list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); ReplacementData data = ReplacementData.of(Methods.anyMethod(), 0, arguments); // When: String result = underTest.process(data, "%a[-6..6]"); // Then: assertThat(result).isEqualTo("4, 5, 6"); }
@Test public void testProcessShouldReplaceWholeWithoutLastRangeSubscriptArgumentPlaceholderUsingOnlyPositiveIndices() { // Given: final List<Object> arguments = list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); ReplacementData data = ReplacementData.of(Methods.anyMethod(), 0, arguments); // When: String result = underTest.process(data, "%a[0..8]"); // Then: assertThat(result).isEqualTo("0, 1, 2, 3, 4, 5, 6, 7, 8"); }
@Test public void testProcessShouldReplaceSingleValueRangeSubscriptArgumentPlaceholderUsingMixedIndices() { // Given: final List<Object> arguments = list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); ReplacementData data = ReplacementData.of(Methods.anyMethod(), 0, arguments); // When: String result = underTest.process(data, "%a[7..-3]"); // Then: assertThat(result).isEqualTo("7"); }
@Test public void testProcessShouldReplaceSingleValueRangeSubscriptArgumentPlaceholderUsingOnlyNegativeIndices() { // Given: final List<Object> arguments = list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); ReplacementData data = ReplacementData.of(Methods.anyMethod(), 0, arguments); // When: String result = underTest.process(data, "%a[-3..-3]"); // Then: assertThat(result).isEqualTo("7"); }
@Test public void testProcessShouldReplaceIndexSubscriptArgumentPlaceholderUsingNegativeIndex() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3); ReplacementData data = ReplacementData.of(Methods.anyMethod(), 0, arguments); // When: String result = underTest.process(data, "%a[-3]"); // Then: assertThat(result).isEqualTo("1"); }
@Test public void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingOnlyNegativeIndices() { // Given: final List<Object> arguments = list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); ReplacementData data = ReplacementData.of(Methods.anyMethod(), 0, arguments); // When: String result = underTest.process(data, "%a[-6..-4]"); // Then: assertThat(result).isEqualTo("4, 5, 6"); }