3838import static org .junit .Assert .assertTrue ;
3939import static org .junit .Assert .fail ;
4040
41+ import org .junit .After ;
4142import org .junit .Test ;
4243import org .scijava .event .EventHandler ;
4344import org .scijava .event .EventService ;
5556 */
5657public 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