DefaultCommandExecutor implements CommandExecutor { @Override public String execute(CommandContext commandContext) throws NoSuchCommandException { BaseCommand command = null; try { command = ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(commandContext.getCommandName()); } catch (Throwable throwable) { } if (command == null) { throw new NoSuchCommandException(commandContext.getCommandName()); } return command.execute(commandContext, commandContext.getArgs()); }  @Override String execute(CommandContext commandContext);  }
@Test public void testExecute1() throws Exception { Assertions.assertThrows(NoSuchCommandException.class, () -> { DefaultCommandExecutor executor = new DefaultCommandExecutor(); executor.execute(CommandContextFactory.newInstance("not-exit")); }); }
@Test public void testExecute2() throws Exception { DefaultCommandExecutor executor = new DefaultCommandExecutor(); String result = executor.execute(CommandContextFactory.newInstance("greeting", new String[]{"dubbo"}, false)); assertThat(result, equalTo("greeting dubbo")); }