|
25 | 25 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
26 | 26 | import org.springframework.context.ApplicationContext; |
27 | 27 | import org.springframework.core.convert.TypeDescriptor; |
28 | | -import org.springframework.core.env.Environment; |
29 | 28 | import org.springframework.core.convert.converter.Converter; |
30 | 29 | import org.springframework.core.convert.converter.ConverterFactory; |
31 | 30 | import org.springframework.core.convert.converter.GenericConverter; |
32 | 31 | import org.springframework.core.convert.support.ConfigurableConversionService; |
33 | | -import org.springframework.shell.core.command.CommandContext; |
| 32 | +import org.springframework.core.env.Environment; |
34 | 33 | import org.springframework.shell.core.command.CommandArgument; |
| 34 | +import org.springframework.shell.core.command.CommandContext; |
35 | 35 | import org.springframework.shell.core.command.CommandOption; |
36 | 36 | import org.springframework.shell.core.command.adapter.MethodInvokerCommandAdapter; |
37 | 37 | import org.springframework.shell.core.command.annotation.Argument; |
@@ -295,12 +295,32 @@ void noPrefixesLeaveNameUnchanged() throws Exception { |
295 | 295 | assertEquals("ping", result.getName()); |
296 | 296 | } |
297 | 297 |
|
| 298 | + @Test |
| 299 | + void globalPrefixIsChainedWithMethodNameFallback() throws Exception { |
| 300 | + ApplicationContext context = mockApplicationContext("app"); |
| 301 | + when(context.getBean(NoGroupCommands.class)).thenReturn(new NoGroupCommands()); |
| 302 | + Method method = Arrays.stream(NoGroupCommands.class.getDeclaredMethods()) |
| 303 | + .filter(m -> m.getName().equals("unnamed")) |
| 304 | + .findFirst() |
| 305 | + .orElseThrow(); |
| 306 | + CommandFactoryBean factory = new CommandFactoryBean(method); |
| 307 | + factory.setApplicationContext(context); |
| 308 | + |
| 309 | + org.springframework.shell.core.command.Command result = factory.getObject(); |
| 310 | + |
| 311 | + assertEquals("app unnamed", result.getName()); |
| 312 | + } |
| 313 | + |
298 | 314 | static class NoGroupCommands { |
299 | 315 |
|
300 | 316 | @Command(name = "ping") |
301 | 317 | public void ping() { |
302 | 318 | } |
303 | 319 |
|
| 320 | + @Command |
| 321 | + public void unnamed() { |
| 322 | + } |
| 323 | + |
304 | 324 | } |
305 | 325 |
|
306 | 326 | static class Message { |
|
0 commit comments