### Question:
OrderService { public Order findById(Long id) { Span span = tracer.buildSpan("findById").start(); log.debug("Entering OrderService.findById()"); Optional<Order> o = repository.findById(id); try { Order order = o.get(); order.getItems().size(); log.debug("Returning element: " + o); return order; } catch (NoSuchElementException nsee) { log.debug("No element found, returning null"); return null; } finally { span.finish(); } }  Order findById(Long id);  }### Answer:
@Test public void findByIdExistingTest() { OrderItem item = new OrderItem(); item.setId(new Long(1)); item.setPrice(new BigDecimal(30)); item.setProductUID(new Long (1)); item.setQuantity(3); List<OrderItem> items = new ArrayList<OrderItem>(); items.add(item); Order o = new Order(); o.setId(new Long(1)); o.setCustomerUID(new Long(1)); o.setDate(new GregorianCalendar(2018, 5, 30).getTime()); o.setItems(items); Order shallowOrder= new Order(); shallowOrder.setId(new Long(1)); item.setOrder(shallowOrder); Mockito.when(repository.findById(new Long (1))) .thenReturn(Optional.of(SerializationUtils.clone(o))); Order found = service.findById(new Long(1)); assertThat(found).isEqualTo(o); }
@Test public void findByIdNonExistingTest() { Mockito.when(repository.findById(new Long (1))) .thenReturn(Optional.empty()); Order found = service.findById(new Long(1)); assertThat(found).isNull(); }