Skip to content

Commit f9fe707

Browse files
committed
Remove duplication
1 parent 247da8e commit f9fe707

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherFactoryTests.java

+4-20
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,7 @@ void createWithPostDiscoveryFilters() {
124124

125125
@Test
126126
void applyPostDiscoveryFiltersViaServiceApi() {
127-
final var current = Thread.currentThread().getContextClassLoader();
128-
try {
129-
var url = getClass().getClassLoader().getResource("testservices/");
130-
var classLoader = new URLClassLoader(new URL[] { url }, current);
131-
Thread.currentThread().setContextClassLoader(classLoader);
132-
127+
withTestServices(() -> {
133128
var discoveryRequest = createLauncherDiscoveryRequestForBothStandardEngineExampleClasses();
134129

135130
var config = LauncherConfig.builder()//
@@ -141,20 +136,12 @@ void applyPostDiscoveryFiltersViaServiceApi() {
141136

142137
final var jupiter = testPlan.getChildren(UniqueId.parse("[engine:junit-jupiter]"));
143138
assertThat(jupiter).hasSize(1);
144-
}
145-
finally {
146-
Thread.currentThread().setContextClassLoader(current);
147-
}
139+
});
148140
}
149141

150142
@Test
151143
void notApplyIfDisabledPostDiscoveryFiltersViaServiceApi() {
152-
final var current = Thread.currentThread().getContextClassLoader();
153-
try {
154-
var url = getClass().getClassLoader().getResource("testservices/");
155-
var classLoader = new URLClassLoader(new URL[] { url }, current);
156-
Thread.currentThread().setContextClassLoader(classLoader);
157-
144+
withTestServices(() -> {
158145
var discoveryRequest = createLauncherDiscoveryRequestForBothStandardEngineExampleClasses();
159146

160147
var config = LauncherConfig.builder()//
@@ -166,10 +153,7 @@ void notApplyIfDisabledPostDiscoveryFiltersViaServiceApi() {
166153

167154
final var jupiter = testPlan.getChildren(UniqueId.parse("[engine:junit-jupiter]"));
168155
assertThat(jupiter).hasSize(1);
169-
}
170-
finally {
171-
Thread.currentThread().setContextClassLoader(current);
172-
}
156+
});
173157
}
174158

175159
@Test

0 commit comments

Comments
 (0)