protected String getReplacementFor(String placeholder) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.getReplacementFor(placeholder, data); } }
/** * 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); }
protected String getReplacementFor(String placeholder) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.getReplacementFor(placeholder, data); } }
protected String getReplacementFor(String placeholder) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.getReplacementFor(placeholder, data); } }
protected String getReplacementFor(String placeholder) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.getReplacementFor(placeholder, data); } }
@Test public void testProcessShouldReplacePlaceholder() { // Given: final Method method = Methods.anyMethod(); ReplacementData data = ReplacementData.of(method, 0, Arrays.<Object>asList(0)); // When: String result = underTest.process(data, "%c"); // Then: assertThat(result).isEqualTo(method.getDeclaringClass().getSimpleName()); } }
@Test public void testProcessShouldReplacePlaceholder() { // Given: final Method method = Methods.anyMethod(); ReplacementData data = ReplacementData.of(method, 0, Arrays.<Object>asList(0)); // When: String result = underTest.process(data, "%m"); // Then: assertThat(result).isEqualTo(method.getName()); } }
@Test public void testProcessShouldReplacePlaceholder() { // Given: final Method method = Methods.anyMethod(); ReplacementData data = ReplacementData.of(method, 0, Arrays.<Object>asList(0)); // When: String result = underTest.process(data, "%cm"); // Then: assertThat(result).isEqualTo(method.toString()); } }
@Test public void testProcessShouldReplacePlaceholder() { // Given: final int index = 42; ReplacementData data = ReplacementData.of(Methods.anyMethod(), index, Arrays.<Object>asList(0)); // When: String result = underTest.process(data, "%i"); // Then: assertThat(result).isEqualTo(String.valueOf(index)); } }
@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 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 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 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 public void testOfShouldThrowNullPointerExceptionIfTestMethodIsNull() throws Exception { // Given: expectedException.expect(NullPointerException.class); expectedException.expectMessage("'testMethod' must not be null"); // When: ReplacementData.of(null, 0, new ArrayList<Object>()); // Then: expect exception }
@Test public void testGetArgumentsShouldReturnUnmodifiableListToKeepReplacementDataImmutable() throws Exception { // Given: ReplacementData underTest = ReplacementData.of(Methods.anyMethod(), 11, Arrays.<Object>asList("1", 2, 3L)); List<Object> arguments = underTest.getArguments(); expectedException.expect(UnsupportedOperationException.class); // When: arguments.clear(); // Then: expect exception }
@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"); }