Skip to content

Commit

Permalink
Also use args when comparing test resources
Browse files Browse the repository at this point in the history
Relates to: #44129
  • Loading branch information
geoand committed Oct 31, 2024
1 parent 77350db commit 1c4e038
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public TestResourceManager(Class<?> testClass,
this.testResourceComparisonInfo = new HashSet<>();
for (TestResourceClassEntry uniqueEntry : uniqueEntries) {
testResourceComparisonInfo.add(new TestResourceComparisonInfo(
uniqueEntry.testResourceLifecycleManagerClass().getName(), uniqueEntry.getScope()));
uniqueEntry.testResourceLifecycleManagerClass().getName(), uniqueEntry.getScope(), uniqueEntry.args));
}

Set<TestResourceClassEntry> remainingUniqueEntries = initParallelTestResources(uniqueEntries);
Expand Down Expand Up @@ -326,7 +326,12 @@ public static Set<TestResourceManager.TestResourceComparisonInfo> testResourceCo
}
Set<TestResourceManager.TestResourceComparisonInfo> result = new HashSet<>(uniqueEntries.size());
for (TestResourceClassEntry entry : uniqueEntries) {
result.add(new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope()));
Map<String, String> args = new HashMap<>(entry.args);
if (entry.configAnnotation != null) {
args.put("configAnnotation", entry.configAnnotation.annotationType().getName());
}
result.add(new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope(),
args));
}
return result;
}
Expand Down Expand Up @@ -603,7 +608,8 @@ public TestResourceScope getScope() {
}
}

public record TestResourceComparisonInfo(String testResourceLifecycleManagerClass, TestResourceScope scope) {
public record TestResourceComparisonInfo(String testResourceLifecycleManagerClass, TestResourceScope scope,
Map<String, String> initArgs) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.Test;
Expand All @@ -22,66 +23,74 @@ public void emptyResources() {
@Test
public void differentCount() {
assertTrue(testResourcesRequireReload(Collections.emptySet(),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS))));
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS, Collections.emptyMap()))));

assertTrue(testResourcesRequireReload(Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS)),
assertTrue(testResourcesRequireReload(Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS,
Collections.emptyMap())),
Collections.emptySet()));
}

@Test
public void sameSingleRestrictedToClassResource() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS)),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS))));
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS, Collections.emptyMap()))));
}

@Test
public void sameSingleMatchingResource() {
assertFalse(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES)),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES))));
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void sameSingleMatchingResourceDifferentInitArgs() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Map.of("foo", "bar")))));
}

@Test
public void differentSingleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES)),
Set.of(new TestResourceComparisonInfo("test2", MATCHING_RESOURCES))));
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void sameMultipleMatchingResource() {
assertFalse(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test", MATCHING_RESOURCES))));
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void differentMultipleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@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))));
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test4", GLOBAL, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES, Collections.emptyMap()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ static Set<TestResourceManager.TestResourceComparisonInfo> testResourceCompariso
if (originalTestResourceScope != null) {
testResourceScope = TestResourceScope.valueOf(originalTestResourceScope.toString());
}
Map<String, String> initArgs = (Map<String, String>) entry.getClass()
.getMethod("initArgs").invoke(entry);
result.add(new TestResourceManager.TestResourceComparisonInfo(testResourceLifecycleManagerClass,
testResourceScope));
testResourceScope, initArgs));
}

return result;
Expand Down

0 comments on commit 1c4e038

Please sign in to comment.