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

PathTestHelper should accept default Gradle build paths now #1546

Merged
merged 1 commit into from
Mar 18, 2019
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
4 changes: 4 additions & 0 deletions devtools/gradle-it/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ repositories {
mavenCentral()
}

test {
useJUnitPlatform()
}

dependencies {
// quarkus-resteasy, quarkus-junit5, rest are copied in pom.xml
compileOnly fileTree(dir: 'target/dependencies/compile', include: '*.jar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

public final class PathTestHelper {

private static final String TEST_CLASSES_FRAGMENT = File.separator + "test-classes";
private static final String CLASSES_FRAGMENT = File.separator + "classes";
private static final String TEST_CLASSES_FRAGMENT_MAVEN = File.separator + "test-classes";
private static final String CLASSES_FRAGMENT_MAVEN = File.separator + "classes";
private static final String TEST_CLASSES_FRAGMENT_GRADLE = "classes" + File.separator + "java" + File.separator + "test";
private static final String CLASSES_FRAGMENT_GRADLE = "classes" + File.separator + "java" + File.separator + "main";

private PathTestHelper() {
}
Expand All @@ -36,19 +38,29 @@ public static Path getTestClassesLocation(Class<?> testClass) {

try {
Path path = Paths.get(resource.toURI());
if (!path.toString().contains(TEST_CLASSES_FRAGMENT)) {
throw new RuntimeException(
"The test class " + testClass + " is not located in the " + TEST_CLASSES_FRAGMENT + " directory.");
if (path.toString().contains(TEST_CLASSES_FRAGMENT_MAVEN) ||
path.toString().contains(TEST_CLASSES_FRAGMENT_GRADLE)) {
return path.getRoot().resolve(path.subpath(0, path.getNameCount() - Paths.get(classFileName).getNameCount()));
}
throw new RuntimeException(
"The test class " + testClass + " is not located in the " + TEST_CLASSES_FRAGMENT_MAVEN +
" nor in " + TEST_CLASSES_FRAGMENT_GRADLE + " directory.");

return path.getRoot().resolve(path.subpath(0, path.getNameCount() - Paths.get(classFileName).getNameCount()));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}

}

public static Path getAppClassLocation(Class<?> testClass) {
return Paths.get(getTestClassesLocation(testClass).toString().replace(TEST_CLASSES_FRAGMENT, CLASSES_FRAGMENT));
String testClassPath = getTestClassesLocation(testClass).toString();
//maven
if (testClassPath.contains(TEST_CLASSES_FRAGMENT_MAVEN))
return Paths.get(getTestClassesLocation(testClass).toString()
.replace(TEST_CLASSES_FRAGMENT_MAVEN, CLASSES_FRAGMENT_MAVEN));
//gradle
else
return Paths.get(getTestClassesLocation(testClass).toString()
.replace(TEST_CLASSES_FRAGMENT_GRADLE, CLASSES_FRAGMENT_GRADLE));
}
}