@Test public void testborrow() throws Exception { when(mockLoan.getBook()).thenReturn(testingBook); when(mockLoan.isOverDue()).thenReturn(false); assertEquals(mockLoan.getBook(), testingBook); }
private String buildLoanListDisplay(List<ILoan> loans) { StringBuilder bld = new StringBuilder(); for (ILoan ln : loans) { if (bld.length() > 0) bld.append("\n\n"); bld.append(ln.toString()); } return bld.toString(); }
@Override public boolean hasOverDueLoans() { for (ILoan loan : loanList) { if (loan.isOverDue()) { return true; } } return false; }
@Test public void testGetLoan() { testingBook.setState(EBookState.ON_LOAN); when(mockLoan.getBook()).thenReturn(testingBook); when(mockLoan.isOverDue()).thenReturn(false); assertEquals(testingBook.getState(), EBookState.ON_LOAN); }
@Test public void testLose() { testingBook.setState(EBookState.LOST); when(mockLoan.getBook()).thenReturn(testingBook); assertEquals(testingBook.getState(), EBookState.LOST); }
@Test public void testReturnBookNotDamaged() { testingBook.setState(EBookState.ON_LOAN); when(mockLoan.getBook()).thenReturn(testingBook); assertEquals(testingBook.getState(), EBookState.ON_LOAN); testingBook.returnBook(false); assertEquals(testingBook.getState(), EBookState.AVAILABLE); }
@Test public void testReturnBookDamaged() { testingBook.setState(EBookState.ON_LOAN); when(mockLoan.getBook()).thenReturn(testingBook); assertEquals(testingBook.getState(), EBookState.ON_LOAN); testingBook.returnBook(true); assertEquals(testingBook.getState(), EBookState.DAMAGED); }
@Test public void testHasNoOverDueLoans() { ILoan loan = EasyMock.createMock(ILoan.class); member.addLoan(loan); EasyMock.expect(loan.isOverDue()).andReturn(false); EasyMock.replay(loan); EasyMock.expect(memberMock.hasOverDueLoans()).andReturn(member.hasOverDueLoans()); EasyMock.replay(memberMock); System.out.println( "\nThis test demonstrates a scenario where the member has no overdue loans, which " + "\nshould result in the test being true if the boolean for having overdue loans is false."); boolean b = memberMock.hasOverDueLoans(); assertFalse(b); if (b) System.out.println("This member has overdue loans! -- FAIL"); else System.out.println("This member has no overdue loans! -- PASS"); }