|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 | 20 | import java.io.IOException;
|
| 21 | +import java.lang.reflect.Constructor; |
21 | 22 | import java.net.URI;
|
22 | 23 | import java.nio.file.Files;
|
23 | 24 | import java.nio.file.Path;
|
|
41 | 42 | import org.junit.jupiter.api.extension.ParameterResolver;
|
42 | 43 | import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
43 | 44 | import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
44 |
| -import org.junit.platform.commons.util.ReflectionUtils; |
45 | 45 |
|
| 46 | +import org.springframework.beans.BeanUtils; |
46 | 47 | import org.springframework.boot.testsupport.BuildOutput;
|
47 | 48 | import org.springframework.http.client.ClientHttpResponse;
|
48 | 49 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
49 | 50 | import org.springframework.util.FileSystemUtils;
|
| 51 | +import org.springframework.util.ReflectionUtils; |
50 | 52 | import org.springframework.util.StringUtils;
|
51 | 53 | import org.springframework.web.client.ResponseErrorHandler;
|
52 | 54 | import org.springframework.web.client.RestTemplate;
|
@@ -119,10 +121,17 @@ private AbstractApplicationLauncher getAbstractApplicationLauncher(Application a
|
119 | 121 | if (this.launcherCache.containsKey(cacheKey)) {
|
120 | 122 | return this.launcherCache.get(cacheKey);
|
121 | 123 | }
|
122 |
| - AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application, |
123 |
| - new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID())); |
124 |
| - this.launcherCache.put(cacheKey, launcher); |
125 |
| - return launcher; |
| 124 | + try { |
| 125 | + Constructor<? extends AbstractApplicationLauncher> constructor = ReflectionUtils |
| 126 | + .accessibleConstructor(launcherClass, Application.class, File.class); |
| 127 | + AbstractApplicationLauncher launcher = BeanUtils.instantiateClass(constructor, application, |
| 128 | + new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID())); |
| 129 | + this.launcherCache.put(cacheKey, launcher); |
| 130 | + return launcher; |
| 131 | + } |
| 132 | + catch (NoSuchMethodException ex) { |
| 133 | + throw new IllegalStateException("Launcher class %s does not have an (Application, File) constructor"); |
| 134 | + } |
126 | 135 | }
|
127 | 136 |
|
128 | 137 | private Application getApplication(EmbeddedServletContainerTest annotation, String container) {
|
|
0 commit comments