### Question:
OrdersService { public Order getById(Long id) { Span span = tracer.buildSpan("getById").start(); log.debug("Entering OrdersService.getById()"); Order o = orderRepository.getOrderById(id); if (o != null) { o.setCustomer(customerRepository.getCustomerById(o.getCustomer().getId())); o.setItems(inventoryRepository.getProductDetails(o.getItems())); } span.finish(); return o; }  Order getById(Long id);  }### Answer:
@Test public void getByIdWithNonExistingOrderTest() { Mockito.when(orderRepository.getOrderById(new Long(1))) .thenReturn(null); Order found = ordersService.getById(new Long(1)); assertThat(found).isNull(); }
@Test public void getByIdWithExistingOrderTest() { Order o = new Order(); o.setId(new Long(1)); o.setDate(new GregorianCalendar(2018, 5, 30).getTime()); Product p = new Product(); p.setId(new Long(1)); Customer c = new Customer(); c.setId(new Long(1)); OrderItem i = new OrderItem(); i.setPrice(new BigDecimal(30)); i.setQuantity(3); i.setProduct(p); List<OrderItem> items = new ArrayList<OrderItem>(); items.add(item); List<OrderItem> detaileditems = new ArrayList<OrderItem>(); detaileditems.add((OrderItem)SerializationUtils.clone(item)); o.setItems(items); o.setCustomer(c); Mockito.when(orderRepository.getOrderById(new Long(1))) .thenReturn(o); Mockito.when(customerRepository.getCustomerById(new Long(1))) .thenReturn((Customer)SerializationUtils.clone(customer)); Mockito.when(inventoryRepository.getProductDetails(items)) .thenReturn(detaileditems); Order found = ordersService.getById(new Long(1)); assertThat(found).isEqualTo(order); }