### Question:
NestedCommand implements Command { @Override public void execute(CommandExecution execution) { if (execution.getArguments().isEmpty() || !nestedCommands.containsKey(execution.getArguments().get(0))) { this.sendHelp(execution); } else { this.executeInternal(execution, execution.getArguments().get(0)); } } NestedCommand(Map<String, CommandRegistration> nestedCommands, CommandExecutor commandExecutor, InternalizationService internalizationService); @Override void execute(CommandExecution execution);  }### Answer:
@Test public void executeExisting() { CommandExecution commandExecution = mock(CommandExecution.class); ArgumentSet argumentSet = mock(ArgumentSet.class); when(argumentSet.get(eq(0))).thenReturn("subA"); when(argumentSet.isEmpty()).thenReturn(false); when(argumentSet.toArray()).thenReturn(new String[]{"subA", "arg1", "arg2"}); when(commandExecution.getArguments()).thenReturn( argumentSet ); nestedCommand.execute(commandExecution); verify(commandExecutor).execute( eq(nestedCommands.get("subA")), any(), eq(new String[]{"arg1", "arg2"}) ); }
@Test public void executeInexistent() { CommandExecution commandExecution = mock(CommandExecution.class); ArgumentSet argumentSet = mock(ArgumentSet.class); when(argumentSet.get(eq(0))).thenReturn("absent"); when(argumentSet.isEmpty()).thenReturn(false); when(argumentSet.toArray()).thenReturn(new String[]{"absent", "arg1", "arg2"}); when(commandExecution.getArguments()).thenReturn( argumentSet ); when(commandExecution.getSender()).thenReturn(mock(Sender.class)); nestedCommand.execute(commandExecution); verify(commandExecutor, times(0)).execute( any(), any(), any() ); }