Exemplo n.º 1
0
  @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();
 }
Exemplo n.º 3
0
 @Override
 public boolean hasOverDueLoans() {
   for (ILoan loan : loanList) {
     if (loan.isOverDue()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
  @Test
  public void testLose() {

    testingBook.setState(EBookState.LOST);

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

    assertEquals(testingBook.getState(), EBookState.LOST);
  }
Exemplo n.º 6
0
  @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);
  }
Exemplo n.º 7
0
  @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");
  }