3838import org .junit .Test ;
3939import org .scijava .Context ;
4040import org .scijava .command .Command ;
41- import org .scijava .command .CommandModule ;
4241import org .scijava .command .CommandService ;
4342import org .scijava .log .LogService ;
4443import org .scijava .log .Logger ;
4544import org .scijava .log .TestLogListener ;
4645import org .scijava .plugin .Parameter ;
47- import org .scijava .plugin .Plugin ;
46+
47+ import static org .junit .Assert .assertEquals ;
4848
4949/**
5050 * Tests {@link LoggerPreprocessor}.
@@ -57,16 +57,13 @@ public class LoggerPreprocessorTest {
5757 public void testInjection () throws InterruptedException , ExecutionException {
5858 final Context context = new Context (CommandService .class );
5959 final CommandService commandService = context .service (CommandService .class );
60- final LogService logService = context .service (LogService .class );
6160 final TestLogListener listener = new TestLogListener ();
62- logService .addListener (listener );
61+ context . service ( LogService . class ) .addListener (listener );
6362
64- final CommandModule module = //
65- commandService .run (CommandWithLogger .class , true ).get ();
63+ commandService .run (CommandWithLogger .class , true ).get ();
6664 assertTrue (listener .hasLogged (m -> m .source ().path ().contains (CommandWithLogger .class .getSimpleName ())));
6765 }
6866
69- @ Plugin (type = Command .class )
7067 public static class CommandWithLogger implements Command {
7168
7269 @ Parameter
@@ -78,4 +75,21 @@ public void run() {
7875 }
7976 }
8077
78+ @ Test
79+ public void testLoggerNameByAnnotation () throws ExecutionException , InterruptedException {
80+ final Context context = new Context (CommandService .class );
81+ final CommandService commandService = context .service (CommandService .class );
82+ commandService .run (CommandWithNamedLogger .class , true ).get ();
83+ }
84+
85+ public static class CommandWithNamedLogger implements Command {
86+
87+ @ Parameter (label = "MyLoggerName" )
88+ public Logger log ;
89+
90+ @ Override
91+ public void run () {
92+ assertEquals ("MyLoggerName" , log .getName ());
93+ }
94+ }
8195}
0 commit comments