Skip to content

Commit 254dd05

Browse files
committed
ServiceIndexTest: dispose contexts in unit tests
1 parent b430008 commit 254dd05

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/test/java/org/scijava/service/ServiceIndexTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void testGetAll() {
6565
assertSame(DefaultPluginService.class, all.get(1).getClass());
6666
assertSame(DefaultThreadService.class, all.get(2).getClass());
6767
assertSame(StderrLogService.class, all.get(3).getClass());
68+
context.dispose();
6869
}
6970

7071
@Test
@@ -73,16 +74,19 @@ public void testMarkerInterfaces() {
7374
for (Service s : context.getServiceIndex().getAll()) {
7475
assertTrue(s.getClass().getName(), s instanceof SciJavaService);
7576
}
77+
context.dispose();
7678
}
7779

7880
/**
7981
* Test the {@link ServiceIndex#getPrevService(Class, Class)} operation.
8082
*/
8183
@Test
8284
public void testGetPrevService() {
85+
final Context context = new Context(SciJavaService.class);
86+
8387
// Create a service index where the OptionsService hierarchy should be:
8488
// HigherOptionsService > DefaultOptionsService > LowerOptionsService
85-
final ServiceIndex serviceIndex = setUpPrivateServices();
89+
final ServiceIndex serviceIndex = setUpPrivateServices(context);
8690

8791
// DefaultOptionsService should be the previous service to LowerOptionsService
8892
assertEquals(DefaultOptionsService.class, serviceIndex.getPrevService(
@@ -96,16 +100,20 @@ public void testGetPrevService() {
96100
// There should not be a previous service before HigherOptionsService
97101
assertNull(serviceIndex.getPrevService(OptionsService.class,
98102
HigherOptionsService.class));
103+
104+
context.dispose();
99105
}
100106

101107
/**
102108
* Test the {@link ServiceIndex#getNextService(Class, Class)} operation.
103109
*/
104110
@Test
105111
public void testGetNextService() {
112+
final Context context = new Context(SciJavaService.class);
113+
106114
// Create a service index where the OptionsService hierarchy should be:
107115
// HigherOptionService > DefaultOptionService > LowerOptionService
108-
final ServiceIndex serviceIndex = setUpPrivateServices();
116+
final ServiceIndex serviceIndex = setUpPrivateServices(context);
109117

110118
// DefaultOptionsService should be the next service to HigherOptionsService
111119
assertEquals(DefaultOptionsService.class, serviceIndex.getNextService(
@@ -119,15 +127,16 @@ public void testGetNextService() {
119127
// There should not be a next service after LowerOptionsService
120128
assertNull(serviceIndex.getNextService(OptionsService.class,
121129
LowerOptionsService.class));
130+
131+
context.dispose();
122132
}
123133

124134
// -- Helper methods --
125135

126136
/**
127137
* @return A {@link ServiceIndex} with all private services manually added.
128138
*/
129-
private ServiceIndex setUpPrivateServices() {
130-
final Context context = new Context(SciJavaService.class);
139+
private ServiceIndex setUpPrivateServices(final Context context) {
131140
final ServiceIndex serviceIndex = context.getServiceIndex();
132141
serviceIndex.add(new HigherOptionsService());
133142
serviceIndex.add(new LowerOptionsService());

0 commit comments

Comments
 (0)