@Test void testFormatAllHandleListsCorrectly() { // Given: final List<Object> arguments = list(list("test", 1, 1723940567289346512L), 3); // When: String result = underTest.formatAll(paramsWith(2), arguments); // Then: assertThat(result).isEqualTo("c0=[test, 1, 1723940567289346512], i1=3"); }
@Test void testProcessShouldReplaceSingleValueRangeSubscriptArgumentPlaceholderUsingOnlyNegativeIndices() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[-3..-3]"); // Then: assertThat(result).isEqualTo("l7=7"); }
@Test void testProcessToDoShouldReplaceSingleValueRangeSubscriptArgumentPlaceholderUsingOnlyNegativeIndices() { // Given: final Method testMethod = ReflectionSupport .findMethod(Assertions.class, "assertTrue", new Class<?>[] { boolean.class }) .orElseThrow(() -> new IllegalStateException("Could not find method")); final List<Object> arguments = list('x'); ReplacementData data = ReplacementData.of(testMethod, 0, arguments); // When: String result = underTest.process(data, "%na[0]"); // Then: assertThat(result).isEqualTo("arg0=x"); assertThat(getTestCapturedLog()).containsPattern( "WARNING: Parameter names on method '.*' are not available. To store formal parameter names, compile the source file with the '-parameters' option"); }
@Test void testProcessShouldReplaceWholeWithoutFirstRangeSubscriptArgumentPlaceholder() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[1..-1]"); // Then: assertThat(result).isEqualTo("i1=1, l2=2, d3=3.3, s4=four, c5=f, i6=6, l7=7, d8=8.8, f9=9.99"); }
@Test void testFormatAllShouldHandleSingleValueCorrectly() { // Given: final List<Object> arguments = list(12.45); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=12.45"); }
@Test void testProcessShouldReplaceWholeRangeSubscriptArgumentPlaceholderUsingOnlyPositiveIndices() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[0..9]"); // Then: assertThat(result).isEqualTo("c0=a, i1=1, l2=2, d3=3.3, s4=four, c5=f, i6=6, l7=7, d8=8.8, f9=9.99"); }
@Test void testFormatAllReplacesNonPrintableCharactersWithPredefinedPrintableCounterpartEvenIfWithText() { // Given: final List<Object> arguments = list("test\btest\uFFFF"); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=test" + STRING_NON_PRINTABLE + "test" + STRING_NON_PRINTABLE); }
@Test void testProcessShouldReplaceWholeRangeSubscriptArgumentPlaceholderUsingMixedIndicesOtherWayRound() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[-10..9]"); // Then: assertThat(result).isEqualTo("c0=a, i1=1, l2=2, d3=3.3, s4=four, c5=f, i6=6, l7=7, d8=8.8, f9=9.99"); }
@Test void testFormatAllHandlePrimitiveCharTypeArrayCorrectly() { // Given: final List<Object> arguments = list(new char[] { 'a', '0' }); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=[a, 0]"); }
@Test void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingOnlyPositiveIndices() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[4..6]"); // Then: assertThat(result).isEqualTo("s4=four, c5=f, i6=6"); }
@Test void testFormatAllReplacesLineFeedsWithTheirPrintableCounterpartEvenIfWithText() { // Given: final List<Object> arguments = list("1\n2\n3"); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=1\\n2\\n3"); }
@Test void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingMixedIndices() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[4..-4]"); // Then: assertThat(result).isEqualTo("s4=four, c5=f, i6=6"); }
@Test void testFormatAllReplacesNonPrintableCharactersWithPredefinedPrintableCounterpart() { // Given: final List<Object> arguments = list("\u001F"); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=" + STRING_NON_PRINTABLE); }
@Test void testProcessShouldReplaceIndexSubscriptArgumentPlaceholderUsingNegativeIndex() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[-3]"); // Then: assertThat(result).isEqualTo("l7=7"); }
@Test void testFormatAllReplacesCarriageReturnsAndLineFeedsWithTheirPrintableCounterpart() { // Given: final List<Object> arguments = list("A very\r\nlong text\nwith multiple\rdifferent newline\n\rvariations."); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=A very\\r\\nlong text\\nwith multiple\\rdifferent newline\\n\\rvariations."); }
@Test void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingMixedIndicesOtherWayRound() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[-6..6]"); // Then: assertThat(result).isEqualTo("s4=four, c5=f, i6=6"); }
@Test void testFormatAllHandleFurtherNestedArraysCorrectly() { // Given: final List<Object> arguments = list(new Object[] { 2, new char[] { 'a', 'b' }, new String[] { "a", "b" } }); // When: String result = underTest.formatAll(paramsWith(2), arguments); // Then: assertThat(result).isEqualTo("c0=[2, [a, b], [a, b]]"); }
@Test void testProcessShouldReplaceSingleValueRangeSubscriptArgumentPlaceholderUsingMixedIndices() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[7..-3]"); // Then: assertThat(result).isEqualTo("l7=7"); }
@Test void testFormatAllHandleEnumsCorrectly() { // Given: final List<Object> arguments = list(Thread.State.RUNNABLE); // When: String result = underTest.formatAll(paramsWith(1), arguments); // Then: assertThat(result).isEqualTo("c0=RUNNABLE"); }
@Test void testProcessShouldReplaceIndexSubscriptArgumentPlaceholderUsingPositiveIndex() { // Given: final List<Object> arguments = list('a', 1, 2l, 3.3, "four", 'f', 6, 7l, 8.8, 9.99f); ReplacementData data = ReplacementData.of(tenParamMethod, 0, arguments); // When: String result = underTest.process(data, "%na[2]"); // Then: assertThat(result).isEqualTo("l2=2"); }