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

Also use args when comparing test resources #44215

Closed
wants to merge 1 commit into from
Closed
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
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
Loading