@Test public void testGetLoans() { ILoan loan = EasyMock.createMock(ILoan.class); member.addLoan(loan); member.addLoan(loan); member.addLoan(loan); EasyMock.expect(memberMock.getLoans()).andReturn(member.getLoans()); EasyMock.replay(memberMock); System.out.println( "\nThis test demonstrates a function process where" + "\nthe list of loans are returned. This test is successful " + "\nif the loans list is returned and exists."); List<ILoan> loansList = memberMock.getLoans(); boolean b; if (loansList.isEmpty()) { b = false; System.out.println("The loans list is empty. -- FAIL"); } else { b = true; System.out.println( "The loans list is not empty and contains " + loansList.size() + " elements. -- PASS"); } assertTrue(b); }
@Test public void testHasReachedLoanLimit() { ILoan loan = EasyMock.createMock(ILoan.class); member.addLoan(loan); member.addLoan(loan); member.addLoan(loan); member.addLoan(loan); member.addLoan(loan); member.addLoan(loan); EasyMock.expect(memberMock.hasReachedLoanLimit()).andReturn(member.hasReachedLoanLimit()); EasyMock.replay(memberMock); System.out.println( "\nThis test demonstrates a scenario where the member has not exceeded the limit " + "\nimposed on the number of loans a member can have at any one time."); boolean b = memberMock.hasReachedLoanLimit(); assertTrue(b); if (b) System.out.println( "This member has exceeded the loan limit with " + member.getLoans().size() + " loans! -- PASS"); else System.out.println( "This member has not exceeded the loan limit with " + member.getLoans().size() + " loans! -- FAIL"); }
@Test public void testRemoveLoan() { ILoan loan = EasyMock.createMock(ILoan.class); member.addLoan(loan); member.addLoan(loan); member.addLoan(loan); float initLoanAmount = member.getLoans().size(); member.removeLoan(loan); float loanAmount = member.getLoans().size(); System.out.println( "\nThis test demonstrates the procedure for removing a loan that is identical to the" + "\nloan provided as input to the function removeLoan()."); boolean b; if (loanAmount < initLoanAmount) { b = true; System.out.println( "There are now only " + loanAmount + " loans remaining for member out of an initial of " + initLoanAmount + " loans! -- PASS"); } else { b = false; System.out.println( "There are now only " + loanAmount + " loans remaining for member out of an initial of " + initLoanAmount + " loans! -- FAIL"); } assertTrue(b); }
@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"); }
@Test public void testAddLoan() { ILoan loan = EasyMock.createMock(ILoan.class); member.addLoan(loan); EasyMock.expect(memberMock.getLoans()).andReturn(member.getLoans()); EasyMock.replay(memberMock); System.out.println("\nThis test demonstrates the process where a loan is added."); List<ILoan> loan2 = memberMock.getLoans(); boolean b; if (loan2.isEmpty()) { b = false; System.out.println("Loan created but does not exist! -- FAIL"); } else { b = true; System.out.println("Loan created and exist! -- PASS"); } assertTrue(b); }