@Test public void an_unkown_guest_results_in_an_empty_optional() { Optional<Guest> result = guestService.findByPublicId(randomUUID().toString()); assertThat(result.isPresent()).isFalse(); }
public Optional<Guest> findByPublicId(String publicId) { TypedQuery<Guest> query = em.createNamedQuery(Guest.GUEST_FIND_BY_PUBLIC_ID, Guest.class); query.setParameter("publicId", publicId); List<Guest> resultList = query.getResultList(); if (resultList.isEmpty()) { return empty(); } return of(resultList.get(0)); }
GuestService { public Optional<Guest> findByPublicId(String publicId) { TypedQuery<Guest> query = em.createNamedQuery(Guest.GUEST_FIND_BY_PUBLIC_ID, Guest.class); query.setParameter("publicId", publicId); List<Guest> resultList = query.getResultList(); if (resultList.isEmpty()) { return empty(); } return of(resultList.get(0)); } }
GuestService { public Optional<Guest> findByPublicId(String publicId) { TypedQuery<Guest> query = em.createNamedQuery(Guest.GUEST_FIND_BY_PUBLIC_ID, Guest.class); query.setParameter("publicId", publicId); List<Guest> resultList = query.getResultList(); if (resultList.isEmpty()) { return empty(); } return of(resultList.get(0)); } GuestService(); @Inject  GuestService(@Background Event<Guest> guestEvents); }
GuestService { public Optional<Guest> findByPublicId(String publicId) { TypedQuery<Guest> query = em.createNamedQuery(Guest.GUEST_FIND_BY_PUBLIC_ID, Guest.class); query.setParameter("publicId", publicId); List<Guest> resultList = query.getResultList(); if (resultList.isEmpty()) { return empty(); } return of(resultList.get(0)); } GuestService(); @Inject  GuestService(@Background Event<Guest> guestEvents); void setEntityManager(EntityManager em); void saveGuest(Guest guest); Guest findSingleGuestById(@PathParam("guestId") Long guestId); List<Guest> getAllGuests(); Optional<Guest> findById(@PathParam("guestId") Long guestId); Optional<Guest> updateGuestDetails(Guest guest); Optional<Guest> findByPublicId(String publicId); boolean deleteGuest(@NotNull String publicId); }
GuestService { public Optional<Guest> findByPublicId(String publicId) { TypedQuery<Guest> query = em.createNamedQuery(Guest.GUEST_FIND_BY_PUBLIC_ID, Guest.class); query.setParameter("publicId", publicId); List<Guest> resultList = query.getResultList(); if (resultList.isEmpty()) { return empty(); } return of(resultList.get(0)); } GuestService(); @Inject  GuestService(@Background Event<Guest> guestEvents); void setEntityManager(EntityManager em); void saveGuest(Guest guest); Guest findSingleGuestById(@PathParam("guestId") Long guestId); List<Guest> getAllGuests(); Optional<Guest> findById(@PathParam("guestId") Long guestId); Optional<Guest> updateGuestDetails(Guest guest); Optional<Guest> findByPublicId(String publicId); boolean deleteGuest(@NotNull String publicId);  }