コード例 #1
0
ファイル: BookTestings.java プロジェクト: jpasal02/205A3
  @Test
  public void testborrow() throws Exception {

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

    assertEquals(mockLoan.getBook(), testingBook);
  }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: Member.java プロジェクト: PVipers/Assignment3
 @Override
 public boolean hasOverDueLoans() {
   for (ILoan loan : loanList) {
     if (loan.isOverDue()) {
       return true;
     }
   }
   return false;
 }
コード例 #4
0
ファイル: BookTestings.java プロジェクト: jpasal02/205A3
  @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);
  }
コード例 #5
0
ファイル: BookTestings.java プロジェクト: jpasal02/205A3
  @Test
  public void testLose() {

    testingBook.setState(EBookState.LOST);

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

    assertEquals(testingBook.getState(), EBookState.LOST);
  }
コード例 #6
0
ファイル: BookTestings.java プロジェクト: jpasal02/205A3
  @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);
  }
コード例 #7
0
ファイル: BookTestings.java プロジェクト: jpasal02/205A3
  @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);
  }
コード例 #8
0
  @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");
  }