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 ad91929
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
public final class ClassInclusionReport {

private final Set<String> includedClasses;
private final Path usedClassesReport;

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

/**
Expand Down Expand Up @@ -55,26 +57,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 " + usedClassesReport);
}
}

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 " + usedClassesReport);
}
}

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 +89,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 ad91929

Please sign in to comment.