CommandController { @PostMapping("/commands") public ResponseEntity<?> createCommand(@RequestBody final TransporterCommand command) { if(commandOrchestrator.isInboundCommandExist(command.getRefId())){ return new ResponseEntity<>(HttpStatus.CONFLICT); } this.commandOrchestrator.receive(commandMapper.transform(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 testCreateCommandWhenInboundCommandNotExist() { final TransporterCommand command = mock(TransporterCommand.class); when(mockCommandOrchestrator.isInboundCommandExist(command.getRefId())).thenReturn(false); final ResponseEntity<?> result = commandControllerUnderTest.createCommand(command); assertEquals(result.getStatusCode(), HttpStatus.ACCEPTED); verify(mockCommandOrchestrator).receive(any(InboundCommand.class)); }
@Test public void testCreateCommandWhenInboundCommandExist() { final TransporterCommand command = mock(TransporterCommand.class); when(mockCommandOrchestrator.isInboundCommandExist(command.getRefId())).thenReturn(true); final ResponseEntity<?> result = commandControllerUnderTest.createCommand(command); assertEquals(result.getStatusCode(), HttpStatus.CONFLICT); verify(mockCommandOrchestrator, never()).receive(any(InboundCommand.class)); }