Skip to content

Commit 11bf7b5

Browse files
committed
Update the code to use Java 17+ syntax where applicable.
Signed-off-by: James R. Perkins <jperkins@ibm.com>
1 parent c9f7838 commit 11bf7b5

File tree

26 files changed

+100
-104
lines changed

26 files changed

+100
-104
lines changed

api/src/main/java/org/wildfly/testing/junit/condition/RequiresModuleExecutionCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ private ConditionEvaluationResult checkVersion(final RequiresModule requiresModu
121121
// Likely indicates the version could not be resolved.
122122
if (version.isBlank()) {
123123
return ConditionEvaluationResult
124-
.enabled(String.format("Could not determine version of module %s", moduleDefinition.path));
124+
.enabled("Could not determine version of module %s".formatted(moduleDefinition.path));
125125
}
126126
if (isAtLeastVersion(requiresModule.minVersion(), version)) {
127127
return ConditionEvaluationResult
128-
.enabled(String.format("Found version %s and required a minimum of version %s. Enabling tests.",
128+
.enabled("Found version %s and required a minimum of version %s. Enabling tests.".formatted(
129129
version, requiresModule.minVersion()));
130130
}
131131
return ConditionEvaluationResult
@@ -218,7 +218,7 @@ private static boolean isAtLeastVersion(final String minVersion, final String fo
218218
}
219219

220220
private static String formatReason(final RequiresModule requiresModule, final String fmt, final Object... args) {
221-
String msg = String.format(fmt, args);
221+
String msg = fmt.formatted(args);
222222
if (!requiresModule.issueRef().isBlank()) {
223223
msg = requiresModule.issueRef() + ": " + msg;
224224
}

api/src/test/java/org/wildfly/testing/junit/RequiresModuleTestCase.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public void artifactSkippedMissingModule(@JBossHome final Path jbossHome) {
7070
testEvents.assertStatistics((stats) -> stats.skipped(1L));
7171
testEvents.assertThatEvents().haveExactly(1, EventConditions.event(
7272
EventConditions.skippedWithReason(
73-
String.format(
74-
"Module org.wildfly.testing.junit.test.artifact.invalid not found in %s. Disabling test.",
73+
"Module org.wildfly.testing.junit.test.artifact.invalid not found in %s. Disabling test.".formatted(
7574
jbossHome.resolve("modules")))));
7675
}
7776

@@ -120,9 +119,9 @@ public void resourceRootSkippedMissingModule(@JBossHome final Path jbossHome) {
120119
testEvents.assertStatistics((stats) -> stats.skipped(1L));
121120
testEvents.assertThatEvents().haveExactly(1, EventConditions.event(
122121
EventConditions.skippedWithReason(
123-
String.format(
124-
"Module org.wildfly.testing.junit.test.resource-root.invalid not found in %s. Disabling test.",
125-
jbossHome.resolve("modules")))));
122+
"Module org.wildfly.testing.junit.test.resource-root.invalid not found in %s. Disabling test."
123+
.formatted(
124+
jbossHome.resolve("modules")))));
126125
}
127126

128127
@Test
@@ -269,7 +268,7 @@ private static void createJar(final String moduleName, final Path jbossHome, fin
269268
// Create the JAR with a manifest only
270269
final Path jarPath = jbossHome.resolve(
271270
Path.of("modules", "org", "wildfly", "testing", "junit", "test", moduleName, "main",
272-
String.format("test-%s.jar", version)));
271+
"test-%s.jar".formatted(version)));
273272
final Manifest manifest = new Manifest();
274273
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
275274
manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VERSION, version);

extension/src/main/java/org/wildfly/testing/junit/extension/DeploymentManagerProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Object produce(final ExtensionContext context, final Class<?> clazz, fina
3030
throws IllegalArgumentException {
3131
if (!DeploymentManager.class.isAssignableFrom(clazz)) {
3232
throw new IllegalArgumentException(
33-
String.format("Type %s is not assignable to %s", clazz.getName(), DeploymentManager.class.getName()));
33+
"Type %s is not assignable to %s".formatted(clazz.getName(), DeploymentManager.class.getName()));
3434
}
3535

3636
// Get the server from WildFlyExtension and return as managed which will not allow shutting down the server

extension/src/main/java/org/wildfly/testing/junit/extension/ModelControllerClientProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Object produce(final ExtensionContext context, final Class<?> clazz, fina
3030
throws IllegalArgumentException {
3131
if (!ModelControllerClient.class.isAssignableFrom(clazz)) {
3232
throw new IllegalArgumentException(
33-
String.format("Type %s is not assignable to %s", clazz.getName(), ModelControllerClient.class.getName()));
33+
"Type %s is not assignable to %s".formatted(clazz.getName(), ModelControllerClient.class.getName()));
3434
}
3535

3636
// Get the server from WildFlyExtension and return as managed which will not allow shutting down the server

extension/src/main/java/org/wildfly/testing/junit/extension/ServerManagerProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Object produce(final ExtensionContext context, final Class<?> clazz, fina
3030
throws IllegalArgumentException {
3131
if (!ServerManager.class.isAssignableFrom(clazz)) {
3232
throw new IllegalArgumentException(
33-
String.format("Type %s is not assignable to %s", clazz.getName(), ServerManager.class.getName()));
33+
"Type %s is not assignable to %s".formatted(clazz.getName(), ServerManager.class.getName()));
3434
}
3535

3636
// Get the server from WildFlyExtension and return as managed which will not allow shutting down the server

extension/src/main/java/org/wildfly/testing/junit/extension/ServerResourceExtension.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Object resolveParameter(final ParameterContext parameterContext, final Ex
8787
.getType(), parameterContext.getParameter().getAnnotations());
8888
} catch (Throwable e) {
8989
throw new ParameterResolutionException(
90-
String.format("Failed to resolve parameter '%s'.", parameterContext.getParameter()), e);
90+
"Failed to resolve parameter '%s'.".formatted(parameterContext.getParameter()), e);
9191
}
9292
}
9393

@@ -105,7 +105,7 @@ private void injectFields(final ExtensionContext context, final Object testInsta
105105
AnnotationSupport.findAnnotatedFields(testClass, ServerResource.class, predicate).forEach(field -> {
106106
if (Modifier.isFinal(field.getModifiers())) {
107107
throw new ExtensionConfigurationException(
108-
String.format("Field '%s' cannot be final for injection.", field));
108+
"Field '%s' cannot be final for injection.".formatted(field));
109109
}
110110
// Find the producer which can provide this parameter
111111
ServerResourceProducer injectionProducer = null;
@@ -117,7 +117,7 @@ private void injectFields(final ExtensionContext context, final Object testInsta
117117
}
118118
if (injectionProducer == null) {
119119
throw new ExtensionConfigurationException(
120-
String.format("Could not find InjectionProducer for field '%s' of type %s.", field, field.getType()
120+
"Could not find InjectionProducer for field '%s' of type %s.".formatted(field, field.getType()
121121
.getName()));
122122
}
123123
try {
@@ -126,14 +126,14 @@ private void injectFields(final ExtensionContext context, final Object testInsta
126126
field.set(testInstance, value);
127127
} else {
128128
throw new ParameterResolutionException(
129-
String.format("Could not make field %s accessible for injection.", field));
129+
"Could not make field %s accessible for injection.".formatted(field));
130130
}
131131
} catch (Throwable e) {
132-
if (e instanceof ParameterResolutionException) {
133-
throw (ParameterResolutionException) e;
132+
if (e instanceof ParameterResolutionException pre) {
133+
throw pre;
134134
}
135135
throw new ParameterResolutionException(
136-
String.format("Could not make field %s accessible for injection.", field), e);
136+
"Could not make field %s accessible for injection.".formatted(field), e);
137137
}
138138
});
139139
}

extension/src/main/java/org/wildfly/testing/junit/extension/TestSupport.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,41 +70,41 @@ static Optional<Archive<?>> findDeploymentMethod(final ExtensionContext context)
7070
final var method = validate(testClass, methods);
7171
// This must be a void return type
7272
if (!method.getReturnType().equals(Void.TYPE)) {
73-
throw new JUnitException(String.format("Method '%s' must return void", method));
73+
throw new JUnitException("Method '%s' must return void".formatted(method));
7474
}
7575
final int count = method.getParameterCount();
7676
if (count > 2) {
7777
throw new JUnitException(
78-
String.format("Method %s has too many parameters. Only two parameters are allowed.", method));
78+
"Method %s has too many parameters. Only two parameters are allowed.".formatted(method));
7979
}
8080
if (count == 0) {
81-
throw new JUnitException(String.format("Method '%s' must have at least one parameter.", method));
81+
throw new JUnitException("Method '%s' must have at least one parameter.".formatted(method));
8282
}
8383
final var testDeployment = method.getAnnotation(GenerateDeployment.class);
8484
final var parameterTypes = method.getParameterTypes();
8585
final var deploymentType = testDeployment.value() == GenerateDeployment.DeploymentType.INFER
86-
? inferredType(parameterTypes[0]).orElseThrow(() -> new JUnitException(String
87-
.format("Could not infer the type to create for argument %s on method %s. " +
88-
"If this is a custom %s type, please consider using a @DeploymentProducer", parameterTypes[0],
89-
method, Archive.class.getName())))
86+
? inferredType(parameterTypes[0]).orElseThrow(() -> new JUnitException(
87+
("Could not infer the type to create for argument %s on method %s. " +
88+
"If this is a custom %s type, please consider using a @DeploymentProducer")
89+
.formatted(parameterTypes[0], method, Archive.class.getName())))
9090
: testDeployment.value();
9191
// Check that first parameter is an Archive type
9292
if (!Archive.class.isAssignableFrom(parameterTypes[0])) {
93-
throw new JUnitException(String.format(
94-
"@GenerateDeployment method %s must have an Archive type as the first parameter, but was %s",
95-
method.getName(), parameterTypes[0].getName()));
93+
throw new JUnitException(
94+
"@GenerateDeployment method %s must have an Archive type as the first parameter, but was %s"
95+
.formatted(method.getName(), parameterTypes[0].getName()));
9696
}
9797
// Validate the parameter type is assignable from the deployment type
9898
if (!deploymentType.archiveType().isAssignableFrom(parameterTypes[0])) {
99-
throw new JUnitException(String.format("Parameter '%s' must be assignable from '%s'", parameterTypes[0],
99+
throw new JUnitException("Parameter '%s' must be assignable from '%s'".formatted(parameterTypes[0],
100100
deploymentType.archiveType()));
101101
}
102102
final TestInfo testInfo;
103103
// Check the second parameter if applicable
104104
if (parameterTypes.length == 2) {
105105
if (!TestInfo.class.isAssignableFrom(parameterTypes[1])) {
106106
throw new JUnitException(
107-
String.format("Parameter '%s' must be assignable from '%s'", parameterTypes[1], TestInfo.class));
107+
"Parameter '%s' must be assignable from '%s'".formatted(parameterTypes[1], TestInfo.class));
108108
}
109109
testInfo = new ParameterTestInfo(context);
110110
} else {
@@ -121,7 +121,7 @@ static Optional<Archive<?>> findDeploymentMethod(final ExtensionContext context)
121121

122122
return Optional.of(archive);
123123
} catch (Exception e) {
124-
throw new JUnitException(String.format("Failed to execute deployment method in %s: %s", method.getName(), method),
124+
throw new JUnitException("Failed to execute deployment method in %s: %s".formatted(method.getName(), method),
125125
e);
126126
}
127127
}
@@ -138,17 +138,18 @@ static Optional<Archive<?>> findDeploymentProducerMethod(final ExtensionContext
138138
// The return type must be an Archive<?> of some type
139139
if (!Archive.class.isAssignableFrom(method.getReturnType())) {
140140
throw new JUnitException(
141-
String.format("Method '%s' must return assignable from %s", method, Archive.class.getName()));
141+
"Method '%s' must return assignable from %s".formatted(method, Archive.class.getName()));
142142
}
143143
// A single parameter of type TestInfo is allowed, but not required
144144
final var parameterTypes = method.getParameterTypes();
145145
if (parameterTypes.length > 1) {
146-
throw new JUnitException(String.format(
147-
"Method %s has too many parameters. Only one parameter of type %s is allowed.", method, TestInfo.class));
146+
throw new JUnitException(
147+
"Method %s has too many parameters. Only one parameter of type %s is allowed.".formatted(method,
148+
TestInfo.class));
148149
}
149150
if (parameterTypes.length == 1 && !TestInfo.class.isAssignableFrom(parameterTypes[0])) {
150-
throw new JUnitException(String.format(
151-
"Method %s parameter must be of type %s, but was %s.", method, TestInfo.class, parameterTypes[0]));
151+
throw new JUnitException(
152+
"Method %s parameter must be of type %s, but was %s.".formatted(method, TestInfo.class, parameterTypes[0]));
152153
}
153154

154155
final TestInfo testInfo;
@@ -167,7 +168,7 @@ static Optional<Archive<?>> findDeploymentProducerMethod(final ExtensionContext
167168
}
168169
return Optional.of(archive);
169170
} catch (Exception e) {
170-
throw new JUnitException(String.format("Failed to execute deployment method in %s: %s", method.getName(), method),
171+
throw new JUnitException("Failed to execute deployment method in %s: %s".formatted(method.getName(), method),
171172
e);
172173
}
173174
}
@@ -176,15 +177,15 @@ private static Method validate(final Class<?> testClass, final List<Method> meth
176177
// Only one deployment method is allowed
177178
if (methods.size() > 1) {
178179
throw new JUnitException(
179-
String.format("Found more than one deployment method in %s: %s", testClass.getName(), methods));
180+
"Found more than one deployment method in %s: %s".formatted(testClass.getName(), methods));
180181
}
181182
final var method = methods.get(0);
182183
if (!Modifier.isStatic(method.getModifiers())) {
183184
throw new JUnitException(
184-
String.format("Deployment method %s in type %s must be static.", testClass.getName(), method));
185+
"Deployment method %s in type %s must be static.".formatted(testClass.getName(), method));
185186
}
186187
if (!method.trySetAccessible()) {
187-
throw new JUnitException(String.format("Method '%s' is not accessible", method));
188+
throw new JUnitException("Method '%s' is not accessible".formatted(method));
188189
}
189190
return method;
190191
}

extension/src/main/java/org/wildfly/testing/junit/extension/UriProducer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Object produce(final ExtensionContext context, final Class<?> clazz, fina
4444
throws IllegalArgumentException {
4545
if (!URI.class.isAssignableFrom(clazz)) {
4646
throw new IllegalArgumentException(
47-
String.format("Type %s is not assignable to %s", clazz.getName(), URI.class.getName()));
47+
"Type %s is not assignable to %s".formatted(clazz.getName(), URI.class.getName()));
4848
}
4949

5050
final Optional<ServerManager> opt = WildFlyExtension.getServer(context);
@@ -102,7 +102,7 @@ private URI createUri(final URI baseUri, final String path) {
102102
if (path.startsWith("/")) {
103103
return URI.create(uriString + path);
104104
}
105-
return URI.create(uriString + "/" + path);
105+
return URI.create("%s/%s".formatted(uriString, path));
106106
}
107107

108108
/**
@@ -183,7 +183,7 @@ private URI resolveDeploymentUri(final ExtensionContext context, final ServerMan
183183
}
184184
return URI.create(baseUri);
185185
}
186-
throw new JUnitException(String.format("ServerManager %s is not a DomainManager", serverManager));
186+
throw new JUnitException("ServerManager %s is not a DomainManager".formatted(serverManager));
187187
}
188188

189189
private static ModelNode resolveAddress(final ServerManager serverManager, final String domainServer,

extension/src/main/java/org/wildfly/testing/junit/extension/WildFlyExtension.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ private ServerManager createServer(final ExtensionContext context) {
151151

152152
// Validate that both annotations are not present
153153
if (hasWildFlyTest && hasDomainTest) {
154-
throw new JUnitException(String.format(
155-
"Test class %s cannot have both @WildFlyTest and @WildFlyDomainTest. Use only one to specify the test mode.",
156-
testClass.getName()));
154+
throw new JUnitException(
155+
"Test class %s cannot have both @WildFlyTest and @WildFlyDomainTest. Use only one to specify the test mode."
156+
.formatted(testClass.getName()));
157157
}
158158

159159
// Determine configuration based on launch type
@@ -234,13 +234,12 @@ private void deploy(final ServerManager serverManager, final ExtensionContext co
234234
// Deploy to server
235235
final var deploymentResult = serverManager.deploymentManager().deploy(deployment);
236236
if (!deploymentResult.successful()) {
237-
throw new JUnitException(String.format("Failed to deploy %s to server: %s", deploymentName,
237+
throw new JUnitException("Failed to deploy %s to server: %s".formatted(deploymentName,
238238
deploymentResult.getFailureMessage()));
239239
}
240240
DeploymentContext.cache(context, new DeploymentInfo(deploymentName, serverGroups));
241241
} catch (IOException e) {
242-
throw new JUnitException(
243-
String.format("Failed to export archive %s as deployment", deploymentName), e);
242+
throw new JUnitException("Failed to export archive %s as deployment".formatted(deploymentName), e);
244243
}
245244
}
246245

@@ -290,8 +289,8 @@ private static Optional<Archive<?>> resolveDeployment(final ExtensionContext con
290289
final Optional<Archive<?>> deploymentProducer = TestSupport.findDeploymentProducerMethod(context);
291290
if (testDeployment.isPresent() && deploymentProducer.isPresent()) {
292291
throw new JUnitException(
293-
String.format("Test %s cannot have both @GenerateDeployment and @DeploymentProducer methods. " +
294-
"Use only one deployment method type per test class.", testClass.getName()));
292+
"Test %s cannot have both @GenerateDeployment and @DeploymentProducer methods. Use only one deployment method type per test class."
293+
.formatted(testClass.getName()));
295294
}
296295
if (testDeployment.isPresent()) {
297296
return testDeployment;

extension/src/main/java/org/wildfly/testing/junit/extension/annotation/DomainServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* public void listOrders() throws Exception {
3333
* try (Response response = Client.newClient().target(uri).request().get()) {
3434
* Assertions.assertEquals(200, response.getStatus(),
35-
* () -> String.format("Failed to get orders: %s", response.readEntity(String.class)));
35+
* () -> "Failed to get orders: %s".formatted(response.readEntity(String.class)));
3636
* }
3737
* }
3838
* }

0 commit comments

Comments
 (0)