Skip to content

Commit

Permalink
Fix handling of @WithTestResource and global resources
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 5, 2024
1 parent a4559dd commit bd6ce05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,13 @@ public static boolean testResourcesRequireReload(Set<TestResourceComparisonInfo>

// now we need to check whether the sets contain the exact same MATCHING_RESOURCE test resources

Set<TestResourceComparisonInfo> inExistingAndNotNext = onlyMatchingResourceItems(existing);
Set<TestResourceComparisonInfo> inExistingAndNotNext = new HashSet<>(existing);
inExistingAndNotNext.removeAll(next);
if (!inExistingAndNotNext.isEmpty()) {
return true;
}

Set<TestResourceComparisonInfo> inNextAndNotExisting = onlyMatchingResourceItems(next);
Set<TestResourceComparisonInfo> inNextAndNotExisting = new HashSet<>(next);
inNextAndNotExisting.removeAll(existing);
if (!inNextAndNotExisting.isEmpty()) {
return true;
Expand All @@ -538,11 +538,6 @@ public static boolean testResourcesRequireReload(Set<TestResourceComparisonInfo>
return false;
}

private static Set<TestResourceComparisonInfo> onlyMatchingResourceItems(Set<TestResourceComparisonInfo> set) {
return set.stream().filter(i -> i.scope == MATCHING_RESOURCES).collect(
Collectors.toSet());
}

private static boolean hasRestrictedToClassScope(Set<TestResourceComparisonInfo> existing) {
for (TestResourceComparisonInfo info : existing) {
if (info.scope == RESTRICTED_TO_CLASS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ public void differentMultipleMatchingResource() {
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
}

@Test
public void differentGlobalMultipleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test4", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ static Set<TestResourceManager.TestResourceComparisonInfo> existingTestResources
return Collections.emptySet();
}
Closeable closeable = state.testResourceManager;
if (closeable instanceof TestResourceManager testResourceManager) {
if (closeable == null) {
return Collections.emptySet();
}
// we can't compare with instanceof because of the different CL
if (TestResourceManager.class.getName().equals(closeable.getClass().getName())) {
return TestResourceManagerReflections
.testResourceComparisonInfo(testResourceManager);
.testResourceComparisonInfo(closeable);
}
return Collections.emptySet();
}
Expand Down

0 comments on commit bd6ce05

Please sign in to comment.