|
13 | 13 | import java.util.Arrays; |
14 | 14 | import java.util.Optional; |
15 | 15 |
|
16 | | -import org.jspecify.annotations.Nullable; |
17 | 16 | import org.junit.jupiter.api.extension.ExtensionConfigurationException; |
18 | 17 | import org.junit.jupiter.api.extension.ExtensionContext; |
19 | 18 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; |
| 19 | +import org.junit.jupiter.params.ResolverFacade.RequiredParameterCount; |
20 | 20 | import org.junit.platform.commons.logging.Logger; |
21 | 21 | import org.junit.platform.commons.logging.LoggerFactory; |
22 | 22 | import org.junit.platform.commons.util.Preconditions; |
@@ -49,30 +49,33 @@ void validate(ExtensionContext extensionContext) { |
49 | 49 | int totalCount = this.arguments.getTotalLength(); |
50 | 50 | Preconditions.condition(consumedCount == totalCount, |
51 | 51 | () -> wrongNumberOfArgumentsMessages("consumes", consumedCount, null, null)); |
52 | | - } |
53 | | - default -> throw new ExtensionConfigurationException( |
54 | | - "Unsupported argument count validation mode: " + argumentCountValidationMode); |
| 52 | + break; |
| 53 | + default: |
| 54 | + throw new ExtensionConfigurationException( |
| 55 | + "Unsupported argument count validation mode: " + argumentCountValidationMode); |
55 | 56 | } |
56 | 57 | } |
57 | 58 |
|
58 | 59 | private void validateRequiredArgumentsArePresent() { |
59 | | - var requiredParameterCount = this.declarationContext.getResolverFacade().getRequiredParameterCount(); |
| 60 | + RequiredParameterCount requiredParameterCount = this.declarationContext.getResolverFacade().getRequiredParameterCount(); |
60 | 61 | if (requiredParameterCount != null) { |
61 | | - var totalCount = this.arguments.getTotalLength(); |
| 62 | + int totalCount = this.arguments.getTotalLength(); |
62 | 63 | Preconditions.condition(requiredParameterCount.value() <= totalCount, |
63 | 64 | () -> wrongNumberOfArgumentsMessages("has", requiredParameterCount.value(), "required", |
64 | 65 | requiredParameterCount.reason())); |
65 | 66 | } |
66 | 67 | } |
67 | 68 |
|
68 | | - private String wrongNumberOfArgumentsMessages(String verb, int actualCount, @Nullable String parameterAdjective, |
69 | | - @Nullable String reason) { |
| 69 | + private String wrongNumberOfArgumentsMessages(String verb, int actualCount, String parameterAdjective, |
| 70 | + String reason) { |
70 | 71 | int totalCount = this.arguments.getTotalLength(); |
71 | | - return "Configuration error: @%s %s %s %s%s%s but there %s %s %s provided.%nNote: the provided arguments were %s".formatted( |
| 72 | + return String.format( |
| 73 | + "Configuration error: @%s %s %s %s%s%s but there %s %s %s provided.%nNote: the provided arguments were %s", |
72 | 74 | this.declarationContext.getAnnotationName(), verb, actualCount, |
73 | 75 | parameterAdjective == null ? "" : parameterAdjective + " ", |
74 | | - pluralize(actualCount, "parameter", "parameters"), reason == null ? "" : " (due to %s)".formatted(reason), |
75 | | - pluralize(totalCount, "was", "were"), totalCount, pluralize(totalCount, "argument", "arguments"), |
| 76 | + pluralize(actualCount, "parameter", "parameters"), |
| 77 | + reason == null ? "" : String.format(" (due to %s)", reason), pluralize(totalCount, "was", "were"), |
| 78 | + totalCount, pluralize(totalCount, "argument", "arguments"), |
76 | 79 | Arrays.toString(this.arguments.getAllPayloads())); |
77 | 80 | } |
78 | 81 |
|
|
0 commit comments