### Question:
OrdersController { @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public Order getById(@PathVariable("id") Long id) { Order o; Span span = tracer.buildSpan("getById").start(); try{ log.debug("Entering OrderController.getById()"); o = orderService.getById(id); if (o == null) { throw new ResourceNotFoundException("Requested order doesn't exist"); } log.debug("Returning element: " + o); } finally { span.finish(); } return o; }  @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) Order getById(@PathVariable("id") Long id);  }### Answer:
@Test public void getByIdExisting() { Mockito.when(service.getById(new Long (1))) .thenReturn(order); when().get(new Long(1).toString()) .then() .statusCode(200) .body("id", is(1)) .body("date", is("30-05-2018")) .body("customer.id", is(1)) .body("customer.name", is("Test Customer")) .body("customer.surname", is("Test Customer")) .body("customer.username", is("testcustomer")) .body("customer.zipCode", is("28080")) .body("customer.city", is("Madrid")) .body("customer.country", is("Spain")) .body("customer.address", is("Test Address")) .body("items.size()", is(1)) .body("items.get(0).quantity", is(3)) .body("items.get(0).price", is(30)) .body("items.get(0).product.id", is(1)) .body("items.get(0).product.name", is("Test Product")) .body("items.get(0).product.description", is("Test Description")); }
@Test public void getByIdNonExisting() { Mockito.when(service.getById(new Long (1))) .thenReturn(null); when().get(new Long(1).toString()) .then() .statusCode(404); }