@Override protected String format(Object param) { return super.format(param); } }
/** * Formats the given parameters by retrieving it's {@link String} representation and separate it by comma (= * {@code ,}). * <p> * Note: For new and future-proof implementations, please use {@link #formatAll(java.util.List)} instead. * * @param parameters to be formatted * @return the {@link String} representation of the given {@link Object}{@code []} * * @see #formatAll(java.util.List) */ protected String formatAll(Object[] parameters) { return super.formatAll(Arrays.asList(parameters)); }
/** * 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); }
@Override protected String getReplacementFor(String placeholder, ReplacementData data) { FromAndTo fromAndTo = calcFromAndToForSubscriptAndArguments(placeholder, 3, data.getArguments().size()); return formatAll(data.getArguments().subList(fromAndTo.from, fromAndTo.to)); }
protected String getReplacementFor(String placeholder) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.getReplacementFor(placeholder, data); }
/** * @return the list of placeholders used to create the display name for each dataprovider test case */ protected List<? extends BasePlaceholder> getDefaultPlaceholders() { List<BasePlaceholder> result = new ArrayList<>(); result.add(new ArgumentPlaceholder()); result.add(new CanonicalClassNamePlaceholder()); // must be before SimpleClassNamePlaceholder result.add(new CompleteMethodSignaturePlaceholder()); // must be before SimpleClassNamePlaceholder result.add(new IndexPlaceholder()); result.add(new NamedArgumentPlaceholder()); result.add(new SimpleClassNamePlaceholder()); result.add(new SimpleMethodNamePlaceholder()); return result; }
protected String getReplacementFor(String placeholder) { ReplacementData data = ReplacementData.of(method, idx, Arrays.asList(parameters)); return super.getReplacementFor(placeholder, data); }
/** * Formats the given parameters by retrieving it's {@link String} representation and separate it by comma (= * {@code ,}). * <p> * Note: For new and future-proof implementations, please use {@link #formatAll(java.util.List)} instead. * * @param parameters to be formatted * @return the {@link String} representation of the given {@link Object}{@code []} * * @see #formatAll(java.util.List) */ protected String formatAll(Object[] parameters) { return super.formatAll(Arrays.asList(parameters)); }
/** * 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); }
@Override protected String format(Object param) { return super.format(param); } }
@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 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"); }
/** * Formats the given arguments by retrieving it's {@link String} representation and separate it by comma (= * {@code ,}). * * @param arguments to be formatted * @return the {@link String} representation of the given {@link List}{@code <Object>} */ 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(); } }
@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 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 testFormatForCustomObjectReplacesCarriageReturnWithTheirPrintableCounterpart() { // Given: final TestToString argument = new TestToString("\r"); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("\\r"); }
@Test public void testFormatAllHandleComplexExampleCorrectly() { // Given: Date now = new Date(); // @formatter:off final List<Object> arguments = list( now, Double.valueOf(3.5), new StringBuilder("1").append("|2").append("|3"), new File("src/main/java/com/tngtech") ); // @formatter:on // When: String result = underTest.formatAll(arguments); // Then: assertThat(result).isEqualTo(now.toString() + ", 3.5, 1|2|3, src/main/java/com/tngtech"); }
@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 testFormatForCustomObjectReplacesCarriageReturnsWithTheirPrintableCounterpartEvenIfWithText() { // Given: final TestToString argument = new TestToString("test\rtest\r"); // When: String result = underTest.format(argument); // Then: assertThat(result).isEqualTo("test\\rtest\\r"); }
@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"); }