BookingService { public Reservation bookRoom(String guestId, String roomId, LocalDate checkin, LocalDate checkout) { Reservation reservation = new Reservation(guestId, newReservationNumber(), roomId, checkin, checkout, reservationCostCalculator.calculateRateFor(BUDGET, checkin, checkout)); LOGGER.info(() -> "Storing " + reservation); this.em.persist(reservation); this.reservationEvents.fire(new NewReservationEvent(reservation.getReservationNumber())); this.em.flush(); return reservation; } BookingService(); @Inject  BookingService(Event<NewReservationEvent> reservationEvents, Event<ReservationStatusChangeEvent> reservationStateChangeEvents, ReservationCostCalculator reservationCostCalculator); void setReservationStateChangeEvents(Event<ReservationStatusChangeEvent> reservationStateChangeEvents); void setReservationEvents(Event<NewReservationEvent> reservationEvents); boolean cancelReservation(String reservationNumber); String newReservationNumber(); List<Reservation> findReservationForGuest(String guestId); List<Reservation> getAllReservations(); Reservation getReservation(Long id); Reservation bookRoom(String guestId, String roomId, LocalDate checkin, LocalDate checkout); @PersistenceContext void setEntityManager(EntityManager entityManager); Optional<Reservation> findReservationByNumber(String reservationNumber); void reopenReservation(String reservationNumber); void confirmReservation(String reservationNumber);  }
@Test public void booking_a_room_sets_the_reservation_number() { Reservation reservation = bookingService.bookRoom("guest", "room", now(), now()); getEntityManager().flush(); assertThat(reservation).isNotNull(); assertThat(reservation.getReservationNumber()).isNotNull(); }