@Test public void testGetOrder() { when(orderHistoryDao.findOrder("1")).thenReturn(Optional.of(new Order("1", null, null, null, null, 101L, "Ajanta"))); given(). standaloneSetup(configureControllers(orderHistoryController)). when(). get("/orders/1"). then(). statusCode(200). body("restaurantName", equalTo("Ajanta")) ; }
@RequestMapping(path = "/{orderId}", method = RequestMethod.GET) public ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId) { return orderHistoryDao.findOrder(orderId) .map(order -> new ResponseEntity<>(makeGetOrderResponse(order), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
OrderHistoryController { @RequestMapping(path = "/{orderId}", method = RequestMethod.GET) public ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId) { return orderHistoryDao.findOrder(orderId) .map(order -> new ResponseEntity<>(makeGetOrderResponse(order), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } }
OrderHistoryController { @RequestMapping(path = "/{orderId}", method = RequestMethod.GET) public ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId) { return orderHistoryDao.findOrder(orderId) .map(order -> new ResponseEntity<>(makeGetOrderResponse(order), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } OrderHistoryController(OrderHistoryDao orderHistoryDao); }
OrderHistoryController { @RequestMapping(path = "/{orderId}", method = RequestMethod.GET) public ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId) { return orderHistoryDao.findOrder(orderId) .map(order -> new ResponseEntity<>(makeGetOrderResponse(order), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } OrderHistoryController(OrderHistoryDao orderHistoryDao); @RequestMapping(method = RequestMethod.GET) ResponseEntity<GetOrdersResponse> getOrders(@RequestParam(name = "consumerId") String consumerId); @RequestMapping(path = "/{orderId}", method = RequestMethod.GET) ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId); }
OrderHistoryController { @RequestMapping(path = "/{orderId}", method = RequestMethod.GET) public ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId) { return orderHistoryDao.findOrder(orderId) .map(order -> new ResponseEntity<>(makeGetOrderResponse(order), HttpStatus.OK)) .orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND)); } OrderHistoryController(OrderHistoryDao orderHistoryDao); @RequestMapping(method = RequestMethod.GET) ResponseEntity<GetOrdersResponse> getOrders(@RequestParam(name = "consumerId") String consumerId); @RequestMapping(path = "/{orderId}", method = RequestMethod.GET) ResponseEntity<GetOrderResponse> getOrder(@PathVariable String orderId);  }