@Test public void findRoomWithPerson() { assertNull(manager.findRoomWithPerson(p1)); assertNull(manager.findRoomWithPerson(p2)); assertNull(manager.findRoomWithPerson(p3)); assertNull(manager.findRoomWithPerson(p4)); assertNull(manager.findRoomWithPerson(p5)); manager.checkIn(p1, r3); assertEquals(r3, manager.findRoomWithPerson(p1)); assertRoomDeepEquals(r3, manager.findRoomWithPerson(p1)); assertNull(manager.findRoomWithPerson(p2)); assertNull(manager.findRoomWithPerson(p3)); assertNull(manager.findRoomWithPerson(p4)); assertNull(manager.findRoomWithPerson(p5)); try { manager.findRoomWithPerson(null); fail(); } catch (IllegalArgumentException ex) { } try { manager.findRoomWithPerson(personWithNullId); fail(); } catch (IllegalEntityException ex) { } }
@Before public void setUp() throws SQLException { ds = prepareDataSource(); DBUtils.executeSqlScript(ds, RoomManager.class.getResource("createTables.sql")); manager = new HotelManagerImpl(); manager.setDataSource(ds); personManager = new PersonManagerImpl(); personManager.setDataSource(ds); roomManager = new RoomManagerImpl(); roomManager.setDataSource(ds); prepareTestData(); }
@Test public void checkOut() { manager.checkIn(p1, r3); manager.checkIn(p3, r3); manager.checkIn(p4, r3); manager.checkIn(p5, r1); assertEquals(r3, manager.findRoomWithPerson(p1)); assertNull(manager.findRoomWithPerson(p2)); assertEquals(r3, manager.findRoomWithPerson(p3)); assertEquals(r3, manager.findRoomWithPerson(p4)); assertEquals(r1, manager.findRoomWithPerson(p5)); manager.checkOut(p3, r3); List<Person> bodiesInRoom1 = Arrays.asList(p5); List<Person> bodiesInRoom2 = Collections.emptyList(); List<Person> bodiesInRoom3 = Arrays.asList(p1, p4); assertPersonCollectionDeepEquals(bodiesInRoom1, manager.findPersonsInRoom(r1)); assertPersonCollectionDeepEquals(bodiesInRoom2, manager.findPersonsInRoom(r2)); assertPersonCollectionDeepEquals(bodiesInRoom3, manager.findPersonsInRoom(r3)); assertEquals(r3, manager.findRoomWithPerson(p1)); assertNull(manager.findRoomWithPerson(p2)); assertNull(manager.findRoomWithPerson(p3)); assertEquals(r3, manager.findRoomWithPerson(p4)); assertEquals(r1, manager.findRoomWithPerson(p5)); try { manager.checkOut(p3, r1); fail(); } catch (IllegalEntityException ex) { } try { manager.checkOut(p1, r1); fail(); } catch (IllegalEntityException ex) { } try { manager.checkOut(null, r2); fail(); } catch (IllegalArgumentException ex) { } try { manager.checkOut(personWithNullId, r2); fail(); } catch (IllegalEntityException ex) { } try { manager.checkOut(personNotInDB, r2); fail(); } catch (IllegalEntityException ex) { } try { manager.checkOut(p2, null); fail(); } catch (IllegalArgumentException ex) { } try { manager.checkOut(p2, roomWithNullId); fail(); } catch (IllegalEntityException ex) { } try { manager.checkOut(p2, roomNotInDB); fail(); } catch (IllegalEntityException ex) { } // Check that previous tests didn't affect data in database assertPersonCollectionDeepEquals(bodiesInRoom1, manager.findPersonsInRoom(r1)); assertPersonCollectionDeepEquals(bodiesInRoom2, manager.findPersonsInRoom(r2)); assertPersonCollectionDeepEquals(bodiesInRoom3, manager.findPersonsInRoom(r3)); assertEquals(r3, manager.findRoomWithPerson(p1)); assertNull(manager.findRoomWithPerson(p2)); assertNull(manager.findRoomWithPerson(p3)); assertEquals(r3, manager.findRoomWithPerson(p4)); assertEquals(r1, manager.findRoomWithPerson(p5)); }