Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed May 20, 2024
1 parent 216758c commit f82aefa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ private ExtensionContext.Store getStore(ExtensionContext context) {

private TestTemplateInvocationContext createInvocationContext(ParameterizedTestNameFormatter formatter,
ParameterizedTestMethodContext methodContext, Object[] arguments, int invocationIndex) {

return new ParameterizedTestInvocationContext(formatter, methodContext, arguments, invocationIndex);
}

private ParameterizedTestNameFormatter createNameFormatter(ExtensionContext extensionContext, Method templateMethod,
ParameterizedTestMethodContext methodContext, String displayName, int argumentMaxLength) {

ParameterizedTest parameterizedTest = findAnnotation(templateMethod, ParameterizedTest.class).get();
String pattern = parameterizedTest.name().equals(DEFAULT_DISPLAY_NAME)
? extensionContext.getConfigurationParameter(DISPLAY_NAME_PATTERN_KEY).orElse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ParameterizedTestInvocationContext implements TestTemplateInvocationContex

ParameterizedTestInvocationContext(ParameterizedTestNameFormatter formatter,
ParameterizedTestMethodContext methodContext, Object[] arguments, int invocationIndex) {

this.formatter = formatter;
this.methodContext = methodContext;
this.arguments = arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ParameterizedTestNameFormatter {

ParameterizedTestNameFormatter(String pattern, String displayName, ParameterizedTestMethodContext methodContext,
int argumentMaxLength) {

this.pattern = pattern;
this.displayName = displayName;
this.methodContext = methodContext;
Expand Down Expand Up @@ -73,7 +74,7 @@ private Object[] extractNamedArguments(Object[] arguments) {
}

private String prepareMessageFormatPattern(int invocationIndex, Object[] arguments) {
String result = pattern//
String result = this.pattern//
.replace(DISPLAY_NAME_PLACEHOLDER, TEMPORARY_DISPLAY_NAME_PLACEHOLDER)//
.replace(INDEX_PLACEHOLDER, String.valueOf(invocationIndex));

Expand All @@ -90,7 +91,7 @@ private String prepareMessageFormatPattern(int invocationIndex, Object[] argumen

private String argumentsWithNamesPattern(Object[] arguments) {
return IntStream.range(0, arguments.length) //
.mapToObj(index -> methodContext.getParameterName(index).map(name -> name + "=").orElse("") + "{"
.mapToObj(index -> this.methodContext.getParameterName(index).map(name -> name + "=").orElse("") + "{"
+ index + "}") //
.collect(joining(", "));
}
Expand All @@ -113,8 +114,8 @@ private Object[] makeReadable(MessageFormat format, Object[] arguments) {
}

private String truncateIfExceedsMaxLength(String argument) {
if (argument != null && argument.length() > argumentMaxLength) {
return argument.substring(0, argumentMaxLength - 1) + ELLIPSIS;
if (argument != null && argument.length() > this.argumentMaxLength) {
return argument.substring(0, this.argumentMaxLength - 1) + ELLIPSIS;
}
return argument;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ParameterizedTestParameterResolver implements ParameterResolver, AfterTest

ParameterizedTestParameterResolver(ParameterizedTestMethodContext methodContext, Object[] arguments,
int invocationIndex) {

this.methodContext = methodContext;
this.arguments = arguments;
this.invocationIndex = invocationIndex;
Expand Down

0 comments on commit f82aefa

Please sign in to comment.