Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type safety of method signature #46625

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,27 @@ public static Path getTestClassesLocation(Class<?> testClass) {
* @return directory or JAR containing the application being tested by the test class
*/
public static Path getAppClassLocation(Class<?> testClass) {
return getAppClassLocationForTestLocation(getTestClassesLocation(testClass).toString());
return getAppClassLocationForTestLocation(getTestClassesLocation(testClass));
}

/**
* Resolves the directory or the JAR file containing the application being tested by a test from the given location.
*
* @param testClassLocation the test class location
* @param testClassLocationPath the test class location
* @return directory or JAR containing the application being tested by a test from the given location
*/
public static Path getAppClassLocationForTestLocation(String testClassLocation) {
if (testClassLocation.endsWith(".jar")) {
if (testClassLocation.endsWith("-tests.jar")) {
public static Path getAppClassLocationForTestLocation(Path testClassLocationPath) {
if (testClassLocationPath.endsWith(".jar")) {
if (testClassLocationPath.endsWith("-tests.jar")) {
String testClassLocation = testClassLocationPath.toString();
return Paths.get(new StringBuilder()
.append(testClassLocation, 0, testClassLocation.length() - "-tests.jar".length())
.append(".jar")
.toString());
}
return Path.of(testClassLocation);
return testClassLocationPath;
}
String testClassLocation = testClassLocationPath.toString();
Optional<Path> mainClassesDir = TEST_TO_MAIN_DIR_FRAGMENTS.entrySet().stream()
.filter(e -> testClassLocation.contains(e.getKey()))
.map(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public void close() throws Throwable {
// sources nor resources, we need to create an empty classes dir to satisfy the resolver
// as this project will appear as the root application artifact during the bootstrap
if (Files.isDirectory(testLocation)) {
final Path projectClassesDir = PathTestHelper.getAppClassLocationForTestLocation(testLocation.toString());
final Path projectClassesDir = PathTestHelper.getAppClassLocationForTestLocation(testLocation);
if (!Files.exists(projectClassesDir)) {
Files.createDirectories(projectClassesDir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class<? extend
}

testClassLocation = getTestClassesLocation(requiredTestClass);
appClassLocation = getAppClassLocationForTestLocation(testClassLocation.toString());
appClassLocation = getAppClassLocationForTestLocation(testClassLocation);
if (!appClassLocation.equals(testClassLocation)) {
addToBuilderIfConditionMet.accept(testClassLocation);
// if test classes is a dir, we should also check whether test resources dir exists as a separate dir (gradle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static ArtifactLauncher.InitContext.DevServicesLaunchResult handleDevServices(Ex
boolean isDockerAppLaunch) throws Exception {
Class<?> requiredTestClass = context.getRequiredTestClass();
Path testClassLocation = getTestClassesLocation(requiredTestClass);
final Path appClassLocation = getAppClassLocationForTestLocation(testClassLocation.toString());
final Path appClassLocation = getAppClassLocationForTestLocation(testClassLocation);

final PathList.Builder rootBuilder = PathList.builder();

Expand Down
Loading