/** * Executes this placeholder for the given {@link String} by searching all occurrences of the regular expression * supplied in the constructor and replaces them with the retrieved replacement from * {@link #getReplacementFor(String)}. If the regular expression does not match, an exact copy of the given * {@link String} is returned. * * @param formatPattern to be processed * @return the given {@code formatPattern} containing the generated replacements instead of matching patterns */ public String process(String formatPattern) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.process(data, formatPattern); }
/** * Executes this placeholder for the given {@link String} by searching all occurrences of the regular expression * supplied in the constructor and replaces them with the retrieved replacement from * {@link #getReplacementFor(String)}. If the regular expression does not match, an exact copy of the given * {@link String} is returned. * * @param formatPattern to be processed * @return the given {@code formatPattern} containing the generated replacements instead of matching patterns */ public String process(String formatPattern) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.process(data, formatPattern); }
@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 testProcessShouldReplaceIndexSubscriptArgumentPlaceholderUsingPositiveIndex() { // 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, "%p[2]"); // Then: assertThat(result).isEqualTo("2"); }
@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 testProcessShouldReplaceWholeRangeSubscriptArgumentPlaceholderUsingOnlyNegativeIndices() { // 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[-10..-1]"); // Then: assertThat(result).isEqualTo("0, 1, 2, 3, 4, 5, 6, 7, 8, 9"); }
@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"); }
@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 testProcessShouldReplaceWholeRangeSubscriptArgumentPlaceholderUsingOnlyPositiveIndices() { // 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, "%p[0..9]"); // Then: assertThat(result).isEqualTo("0, 1, 2, 3, 4, 5, 6, 7, 8, 9"); }
@Test public void testProcessShouldReplaceWholeRangeSubscriptArgumentPlaceholderUsingMixedIndices() { // 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..-1]"); // Then: assertThat(result).isEqualTo("0, 1, 2, 3, 4, 5, 6, 7, 8, 9"); }
@Test public void testProcessShouldReplaceWholeRangeSubscriptArgumentPlaceholderUsingMixedIndicesOtherWayRound() { // 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[-10..9]"); // Then: assertThat(result).isEqualTo("0, 1, 2, 3, 4, 5, 6, 7, 8, 9"); }
@Test public void testProcessShouldReplaceWholeWithoutFirstRangeSubscriptArgumentPlaceholder() { // 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[1..-1]"); // Then: assertThat(result).isEqualTo("1, 2, 3, 4, 5, 6, 7, 8, 9"); }
@Test public void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingOnlyPositiveIndices() { // 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[4..6]"); // Then: assertThat(result).isEqualTo("4, 5, 6"); }
@Test public void testProcessShouldReplacePartialRangeSubscriptArgumentPlaceholderContainingJustOneValueUsingMixedIndices() { // 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[4..-4]"); // Then: assertThat(result).isEqualTo("4, 5, 6"); }
@Test public void testProcessShouldReplaceSingleValueRangeSubscriptArgumentPlaceholderUsingOnlyPositiveIndices() { // 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..7]"); // Then: assertThat(result).isEqualTo("7"); }