예제 #1
0
  @Test
  public void testborrow() throws Exception {

    when(mockLoan.getBook()).thenReturn(testingBook);
    when(mockLoan.isOverDue()).thenReturn(false);

    assertEquals(mockLoan.getBook(), testingBook);
  }
예제 #2
0
 @Override
 public boolean hasOverDueLoans() {
   for (ILoan loan : loanList) {
     if (loan.isOverDue()) {
       return true;
     }
   }
   return false;
 }
예제 #3
0
  @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 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");
  }