|
34 | 34 | import static org.junit.Assert.assertEquals; |
35 | 35 | import static org.junit.Assert.assertFalse; |
36 | 36 | import static org.junit.Assert.assertNotNull; |
| 37 | +import static org.junit.Assert.assertSame; |
37 | 38 | import static org.junit.Assert.assertTrue; |
38 | 39 |
|
39 | 40 | import java.util.concurrent.ExecutionException; |
@@ -112,6 +113,20 @@ public void testValidation() throws InterruptedException, ExecutionException { |
112 | 113 | assertEquals("success", module.getOutput("result")); |
113 | 114 | } |
114 | 115 |
|
| 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 | + |
115 | 130 | // -- Helper classes -- |
116 | 131 |
|
117 | 132 | /** A command which implements {@link Cancelable}. */ |
@@ -235,4 +250,21 @@ public void process(final Module module) { |
235 | 250 |
|
236 | 251 | /** Placeholder class, for type safety. */ |
237 | 252 | 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 | + |
238 | 270 | } |
0 commit comments