Skip to content

Commit 3c7a7de

Browse files
committed
ContextInjectionTest: clean up afterwards
1 parent 2b458fa commit 3c7a7de

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/test/java/org/scijava/ContextInjectionTest.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.junit.Assert.assertTrue;
3939
import static org.junit.Assert.fail;
4040

41+
import org.junit.After;
4142
import org.junit.Test;
4243
import org.scijava.event.EventHandler;
4344
import org.scijava.event.EventService;
@@ -55,14 +56,21 @@
5556
*/
5657
public class ContextInjectionTest {
5758

59+
private Context context;
60+
61+
@After
62+
public void tearDown() {
63+
context.dispose();
64+
}
65+
5866
/**
5967
* Tests that the {@link Context} and {@link Service} parameters are properly
6068
* injected when calling {@link Contextual#setContext} on an
6169
* {@link AbstractContextual}-based class.
6270
*/
6371
@Test
6472
public void testAbstractContextualSetContext() {
65-
final Context context = new Context(FooService.class);
73+
context = new Context(FooService.class);
6674

6775
final NeedsFooContextual needsFoo = new NeedsFooContextual();
6876
assertNull(needsFoo.fooService);
@@ -78,7 +86,7 @@ public void testAbstractContextualSetContext() {
7886
*/
7987
@Test
8088
public void testAbstractContextualContextInject() {
81-
final Context context = new Context(FooService.class);
89+
context = new Context(FooService.class);
8290

8391
final NeedsFooContextual needsFoo = new NeedsFooContextual();
8492
assertNull(needsFoo.fooService);
@@ -94,7 +102,7 @@ public void testAbstractContextualContextInject() {
94102
*/
95103
@Test
96104
public void testNonContextualServiceParameters() {
97-
final Context context = new Context(FooService.class);
105+
context = new Context(FooService.class);
98106

99107
final NeedsFooPlain needsFoo = new NeedsFooPlain();
100108
assertNull(needsFoo.fooService);
@@ -113,7 +121,7 @@ public void testNonContextualServiceParameters() {
113121
*/
114122
@Test
115123
public void testNonContextualContextParameters() {
116-
final Context context = new Context(true);
124+
context = new Context(true);
117125

118126
final NeedsContext needsContext = new NeedsContext();
119127
assertNull(needsContext.context);
@@ -139,13 +147,13 @@ public void testNonContextualContextParameters() {
139147
*/
140148
@Test
141149
public void testContextSubclassInjection() {
142-
final Context c = new Context(true);
150+
context = new Context(true);
143151
final FooContext foo = new FooContext();
144152
final BarContext bar = new BarContext();
145153

146154
final ContextSubclassParameters cspPlain = new ContextSubclassParameters();
147-
c.inject(cspPlain);
148-
assertSame(c, cspPlain.c);
155+
context.inject(cspPlain);
156+
assertSame(context, cspPlain.c);
149157
assertNull(cspPlain.foo);
150158
assertNull(cspPlain.bar);
151159

@@ -170,7 +178,7 @@ public void testContextSubclassInjection() {
170178
*/
171179
@Test
172180
public void testAbstractContextualEventSubscription() {
173-
final Context context = new Context(EventService.class);
181+
context = new Context(EventService.class);
174182
final EventService eventService = context.getService(EventService.class);
175183

176184
final HasEventsContextual hasEvents = new HasEventsContextual();
@@ -191,7 +199,7 @@ public void testAbstractContextualEventSubscription() {
191199
*/
192200
@Test
193201
public void testNonContextualEventSubscription() {
194-
final Context context = new Context(EventService.class);
202+
context = new Context(EventService.class);
195203
final EventService eventService = context.getService(EventService.class);
196204

197205
final HasEventsPlain hasEvents = new HasEventsPlain();

0 commit comments

Comments
 (0)