CommandController { @PostMapping("/commands/{commandId}/restart") public ResponseEntity<?> restartCommand(@PathVariable("commandId") final String commandId) { final AbstractCommand command = commandRepository.findOneOpt(commandId).orElseThrow(CommandNotFoundException::new); if(command instanceof InboundCommand) { commandOrchestrator.receive((InboundCommand) command); } else if(command instanceof OutboundCommand){ commandOrchestrator.receive((OutboundCommand) command); } return new ResponseEntity<>(HttpStatus.ACCEPTED); } @Autowired  CommandController(
        final CommandMapper commandMapper,		
        final CommandOrchestrator commandOrchestrator,
        final CommandRepository commandRepository
    ); @PostMapping("/commands") ResponseEntity<?> createCommand(@RequestBody final TransporterCommand command); @PostMapping("/commands/{commandId}/restart") ResponseEntity<?> restartCommand(@PathVariable("commandId") final String commandId); @PostMapping("/commands/prepare") ResponseEntity<?> prepareCommand(@RequestBody final TransporterCommand command);  }
@Test public void testRestartInboundCommand() { final String commandId = "commandId"; final InboundCommand command = mock(InboundCommand.class); when(mockCommandRepository.findOneOpt(commandId)).thenReturn(Optional.of(command)); final ResponseEntity<?> result = commandControllerUnderTest.restartCommand(commandId); assertEquals(result.getStatusCode(), HttpStatus.ACCEPTED); verify(mockCommandOrchestrator).receive(any(InboundCommand.class)); }
@Test public void testRestartOutboundCommand() { final String commandId = "commandId"; final OutboundCommand command = mock(OutboundCommand.class); when(mockCommandRepository.findOneOpt(commandId)).thenReturn(Optional.of(command)); final ResponseEntity<?> result = commandControllerUnderTest.restartCommand(commandId); assertEquals(result.getStatusCode(), HttpStatus.ACCEPTED); verify(mockCommandOrchestrator).receive(any(OutboundCommand.class)); }