Skip to content

Commit

Permalink
Apply minor polish to ClassInclusionReport
Browse files Browse the repository at this point in the history
@Sanne introduced this very useful utility that can come in
handy for integration testing.
This change applies some minor polish, the most important
being to guard against a potential NPE
  • Loading branch information
geoand committed Jun 17, 2021
1 parent 1b888e4 commit f8df841
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class ClassInclusionReport {

private final Set<String> includedClasses;

private ClassInclusionReport(Set<String> strings, Path usedClassesReport) {
private ClassInclusionReport(Set<String> strings) {
includedClasses = strings;
}

Expand All @@ -40,7 +40,7 @@ public static ClassInclusionReport load() {
} catch (FileNotFoundException e) {
throw new RuntimeException("Could not load used classes report", e);
}
return new ClassInclusionReport(set, usedClassesReport);
return new ClassInclusionReport(set);
}

public void assertContains(final Class<?> type) {
Expand All @@ -55,26 +55,24 @@ public void assertContains(final String typeName) {
final boolean contains = includedClasses.contains(typeName);
if (!contains) {
Assertions.fail(
"Type '" + typeName + "' was not found in the report in " + getUsedClassesReport()
.toString());
"Type '" + typeName + "' was not found in the report in " + getUsedClassesReport());
}
}

public void assertContainsNot(final String typeName) {
final boolean contains = includedClasses.contains(typeName);
if (contains) {
Assertions.fail("Type '" + typeName + "' was found in the report in " + getUsedClassesReport()
.toString());
Assertions.fail("Type '" + typeName + "' was found in the report in " + getUsedClassesReport());
}
}

private static Path getUsedClassesReport() {
final Path reportsPath = nativeImageReportsPath();
final File[] usedClassesReports = reportsPath.toFile().listFiles((dir, name) -> name.toLowerCase(Locale.ROOT)
.startsWith("used_classes_"));
Assertions.assertNotNull(usedClassesReports, "Could not identify the native image build directory");
Assertions.assertEquals(1, usedClassesReports.length, "Could not identify the native image build directory");
final Path usedClassesReport = usedClassesReports[0].toPath();
return usedClassesReport;
return usedClassesReports[0].toPath();
}

private static Path nativeImageReportsPath() {
Expand All @@ -89,6 +87,7 @@ private static Path locateNativeImageBuildDirectory() {
Path buildPath = Paths.get("target");
final File[] files = buildPath.toFile().listFiles((dir, name) -> name.toLowerCase(Locale.ROOT)
.endsWith("-native-image-source-jar"));
Assertions.assertNotNull(files, "Could not identify the native image build directory");
Assertions.assertEquals(1, files.length, "Could not identify the native image build directory");
return files[0].toPath();
}
Expand Down

0 comments on commit f8df841

Please sign in to comment.