@Test public void returnOptionSuccess() { Session session = Session.createTestSession(); session.handleInput(Constants.checkoutBookCommand + " Book 1"); session.handleInput(Constants.returnBookCommand + " Book 1"); assertEquals("Book 1 " + Constants.returnSuccessString, session.history(-2)); }
@Test public void checkoutOptionRemoval() { Session session = Session.createTestSession(); session.handleInput(Constants.checkoutBookCommand + " Book 1"); session.handleInput(Constants.listBooksCommand); String[] lines = session.history(-2).split("\n"); assertEquals( String.format(Constants.bookFormatString, "Book 2", "Author 2", 1976, "1"), lines[1]); assertEquals(2, lines.length); }
@Test public void testInvalidOption() { Session session = Session.createTestSession(); session.handleInput("bogus"); assertEquals(Constants.invalidOptionString, session.history(-2)); assertTrue(session.lastMessage().startsWith(Constants.mainMenuString)); }
@Test public void testValidOptionListBooks() { Session session = Session.createTestSession(); session.handleInput(Constants.listBooksCommand); assertThat(session.history(-2).contains("Book 1"), is(true)); assertThat(session.history(-2).contains("Book 2"), is(true)); }
@Test public void checkoutOptionDoubleRemoval() { Session session = Session.createTestSession(); session.handleInput(Constants.checkoutBookCommand + " Book 1"); session.handleInput(Constants.checkoutBookCommand + " Book 1"); assertEquals(Constants.noMatchesString + " Book 1", session.history(-2)); }
@Test public void testQuitOption() { Session session = Session.createTestSession(); session.handleInput("quit"); assertEquals(Constants.quitString, session.lastMessage()); }
@Test public void returnOptionFailure() { Session session = Session.createTestSession(); session.handleInput(Constants.returnBookCommand + " Book 3"); assertEquals(Constants.noMatchesString + " Book 3", session.history(-2)); }