Skip to content

Commit f2aa79e

Browse files
maarztctrueden
authored andcommitted
LoggerPreprocessorTest: test log redirection
1 parent b9c428b commit f2aa79e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/test/java/org/scijava/module/process/LoggerPreprocessorTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
package org.scijava.module.process;
3333

34+
import static org.junit.Assert.assertEquals;
3435
import static org.junit.Assert.assertTrue;
3536

3637
import java.util.concurrent.ExecutionException;
@@ -39,13 +40,14 @@
3940
import org.scijava.Context;
4041
import org.scijava.command.Command;
4142
import org.scijava.command.CommandService;
43+
import org.scijava.log.DefaultLogger;
44+
import org.scijava.log.LogLevel;
4245
import org.scijava.log.LogService;
46+
import org.scijava.log.LogSource;
4347
import org.scijava.log.Logger;
4448
import org.scijava.log.TestLogListener;
4549
import org.scijava.plugin.Parameter;
4650

47-
import static org.junit.Assert.assertEquals;
48-
4951
/**
5052
* Tests {@link LoggerPreprocessor}.
5153
*
@@ -64,6 +66,25 @@ public void testInjection() throws InterruptedException, ExecutionException {
6466
assertTrue(listener.hasLogged(m -> m.source().path().contains(CommandWithLogger.class.getSimpleName())));
6567
}
6668

69+
/** Tests redirection of a command's log output. */
70+
@Test
71+
public void testCustomLogger() throws ExecutionException,
72+
InterruptedException
73+
{
74+
// setup
75+
final Context context = new Context(CommandService.class);
76+
final CommandService commandService = context.service(CommandService.class);
77+
final TestLogListener listener = new TestLogListener();
78+
final LogSource source = LogSource.newRoot();
79+
final DefaultLogger customLogger = new DefaultLogger(listener, source,
80+
LogLevel.TRACE);
81+
// process
82+
commandService.run(CommandWithLogger.class, true, "log", customLogger)
83+
.get();
84+
// test
85+
assertTrue(listener.hasLogged(m -> m.source().equals(source)));
86+
}
87+
6788
public static class CommandWithLogger implements Command {
6889

6990
@Parameter

0 commit comments

Comments
 (0)