@Test public void shouldGetConsumer() throws IOException { Mockito.when(consumerService.findById(1)).thenReturn(Optional.of(consumer)); given(). standaloneSetup(configureControllers(consumerController)). when(). get("/consumers/1"). then(). statusCode(200) ; }
@RequestMapping(method= RequestMethod.GET, path="/{consumerId}") public ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId) { return consumerService.findById(consumerId) .map(consumer -> new ResponseEntity<>(new GetConsumerResponse(consumer.getName()), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
ConsumerController { @RequestMapping(method= RequestMethod.GET, path="/{consumerId}") public ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId) { return consumerService.findById(consumerId) .map(consumer -> new ResponseEntity<>(new GetConsumerResponse(consumer.getName()), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } }
ConsumerController { @RequestMapping(method= RequestMethod.GET, path="/{consumerId}") public ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId) { return consumerService.findById(consumerId) .map(consumer -> new ResponseEntity<>(new GetConsumerResponse(consumer.getName()), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } ConsumerController(ConsumerService consumerService); }
ConsumerController { @RequestMapping(method= RequestMethod.GET, path="/{consumerId}") public ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId) { return consumerService.findById(consumerId) .map(consumer -> new ResponseEntity<>(new GetConsumerResponse(consumer.getName()), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } ConsumerController(ConsumerService consumerService); @RequestMapping(method= RequestMethod.POST) CreateConsumerResponse create(@RequestBody CreateConsumerRequest request); @RequestMapping(method= RequestMethod.GET, path="/{consumerId}") ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId); }
ConsumerController { @RequestMapping(method= RequestMethod.GET, path="/{consumerId}") public ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId) { return consumerService.findById(consumerId) .map(consumer -> new ResponseEntity<>(new GetConsumerResponse(consumer.getName()), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } ConsumerController(ConsumerService consumerService); @RequestMapping(method= RequestMethod.POST) CreateConsumerResponse create(@RequestBody CreateConsumerRequest request); @RequestMapping(method= RequestMethod.GET, path="/{consumerId}") ResponseEntity<GetConsumerResponse> get(@PathVariable long consumerId);  }