Skip to content

Commit fe04dab

Browse files
committed
CommandModuleTest: test that Command gets injected
When running a Command _without_ preprocessing, the services should nonetheless be populated, due to Context injection.
1 parent a822f7b commit fe04dab

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/java/org/scijava/command/CommandModuleTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import static org.junit.Assert.assertEquals;
3535
import static org.junit.Assert.assertFalse;
3636
import static org.junit.Assert.assertNotNull;
37+
import static org.junit.Assert.assertSame;
3738
import static org.junit.Assert.assertTrue;
3839

3940
import java.util.concurrent.ExecutionException;
@@ -112,6 +113,20 @@ public void testValidation() throws InterruptedException, ExecutionException {
112113
assertEquals("success", module.getOutput("result"));
113114
}
114115

116+
@Test
117+
public void testCommandInjection() throws InterruptedException,
118+
ExecutionException
119+
{
120+
final Context context = new Context(CommandService.class);
121+
final CommandService commandService = context.service(CommandService.class);
122+
final LogService logService = context.service(LogService.class);
123+
124+
final CommandModule module = //
125+
commandService.run(CommandWithService.class, false).get();
126+
assertSame(logService, module.getInput("log"));
127+
assertTrue((boolean) module.getOutput("success"));
128+
}
129+
115130
// -- Helper classes --
116131

117132
/** A command which implements {@link Cancelable}. */
@@ -235,4 +250,21 @@ public void process(final Module module) {
235250

236251
/** Placeholder class, for type safety. */
237252
public static class Stuff {}
253+
254+
/** A command which has a {@link Service} parameter. */
255+
@Plugin(type = Command.class)
256+
public static class CommandWithService implements Command {
257+
258+
@Parameter
259+
private LogService log;
260+
261+
@Parameter(type = ItemIO.OUTPUT)
262+
private boolean success;
263+
264+
@Override
265+
public void run() {
266+
success = log != null;
267+
}
268+
}
269+
238270
}

0 commit comments

Comments
 (0)