@Test(expected = SeatNotAvailable.class) public void test_seat_not_available_exception() throws FlightCapacityExceededException, SeatNotAvailable, UnknownAirTicketException { // given Timestamp date = Timestamp.valueOf("2012-12-20 16:00:00"); Flight flight1 = new Flight(date, 200, "praha", "london", 300); genericDao.save(flight1); AirTicket airTicket1 = bookingService.bookFlight(flight1.getId()); // when bookingService.changeSeat(airTicket1.getId(), airTicket1.getSeatNumber()); }
@Test public void test_change_ticket() throws FlightCapacityExceededException, SeatNotAvailable, UnknownAirTicketException { // given Timestamp date = Timestamp.valueOf("2012-12-20 16:00:00"); Flight flight1 = new Flight(date, 200, "praha", "london", 300); genericDao.save(flight1); int initialCapacity = flight1.getCapacity(); AirTicket airTicket1 = bookingService.bookFlight(flight1.getId()); Random r = new Random(); int seatNumber = r.nextInt(flight1.getCapacity()); while (seatNumber == airTicket1.getSeatNumber()) { seatNumber = r.nextInt(flight1.getCapacity()); } // when AirTicket retrieved = bookingService.changeSeat(airTicket1.getId(), seatNumber); // then System.out.println(">>>" + retrieved.getSeatNumber() + " " + airTicket1.getSeatNumber()); assertNotSame(retrieved.getSeatNumber(), airTicket1.getSeatNumber()); assertEquals(airTicket1.getFlight(), retrieved.getFlight()); assertEquals(flight1.getCapacity() + 1, initialCapacity); }