private void setupTestData() {
    IBook[] book = new IBook[15];
    IMember[] member = new IMember[6];

    book[0] = bookDao_.addBook("author1", "title1", "callNo1");
    book[1] = bookDao_.addBook("author1", "title2", "callNo2");
    book[2] = bookDao_.addBook("author1", "title3", "callNo3");
    book[3] = bookDao_.addBook("author1", "title4", "callNo4");
    book[4] = bookDao_.addBook("author2", "title5", "callNo5");
    book[5] = bookDao_.addBook("author2", "title6", "callNo6");
    book[6] = bookDao_.addBook("author2", "title7", "callNo7");
    book[7] = bookDao_.addBook("author2", "title8", "callNo8");
    book[8] = bookDao_.addBook("author3", "title9", "callNo9");
    book[9] = bookDao_.addBook("author3", "title10", "callNo10");
    book[10] = bookDao_.addBook("author4", "title11", "callNo11");
    book[11] = bookDao_.addBook("author4", "title12", "callNo12");
    book[12] = bookDao_.addBook("author5", "title13", "callNo13");
    book[13] = bookDao_.addBook("author5", "title14", "callNo14");
    book[14] = bookDao_.addBook("author5", "title15", "callNo15");

    member[0] = memberDao_.addMember("fName0", "lName0", "0001", "email0");
    member[1] = memberDao_.addMember("fName1", "lName1", "0002", "email1");
    member[2] = memberDao_.addMember("fName2", "lName2", "0003", "email2");
    member[3] = memberDao_.addMember("fName3", "lName3", "0004", "email3");
    member[4] = memberDao_.addMember("fName4", "lName4", "0005", "email4");
    member[5] = memberDao_.addMember("fName5", "lName5", "0006", "email5");

    Calendar cal = Calendar.getInstance();
    Date now = cal.getTime();

    // create a member with overdue loans
    for (int i = 0; i < 2; i++) {
      ILoan loan = loanDao_.createLoan(member[1], book[i]);
      loanDao_.commitLoan(loan);
    }
    cal.setTime(now);
    cal.add(Calendar.DATE, ILoan.LOAN_PERIOD + 1);
    Date checkDate = cal.getTime();
    loanDao_.updateOverDueStatus(checkDate);

    // create a member with maxed out unpaid fines
    member[2].addFine(10.0f);

    // create a member with maxed out loans
    for (int i = 2; i < 7; i++) {
      ILoan loan = loanDao_.createLoan(member[3], book[i]);
      loanDao_.commitLoan(loan);
    }

    // a member with a fine, but not over the limit
    member[4].addFine(5.0f);

    // a member with a couple of loans but not over the limit
    for (int i = 7; i < 9; i++) {
      ILoan loan = loanDao_.createLoan(member[5], book[i]);
      loanDao_.commitLoan(loan);
    }
    // Note - there are 9 total loans.
  }
 @Test
 public void testCardSwipedDoesNotExist() {
   // Test to see that passing in an ID for a non-existent member does not
   // lead to a change in state. State should remain INITIALIZED.
   controlClass_.initialise();
   controlClass_.cardSwiped(10); // Member ID = 10, but doesn't exist.
   assertTrue(memberDao_.getMemberByID(10) == null);
   assertEquals(EBorrowState.INITIALIZED, controlClass_.getState());
 }
 @Test
 public void testCardSwipedRestricted3() {
   // We will test swipe card with a member who exists but is restricted.
   // This test will be with a member who has reached the fine limit.
   // The state should still then become BORROWING_RESTRICTED.
   controlClass_.initialise();
   controlClass_.cardSwiped(3); // Member ID = 3.
   assertTrue(memberDao_.getMemberByID(3).hasReachedFineLimit());
   assertEquals(EBorrowState.BORROWING_RESTRICTED, controlClass_.getState());
 }
 @Test
 public void testCardSwipedRestricted() {
   // We will test swipe card with a member who exists but is restricted.
   // This test will be with a member who has overdue loans.
   // The state should still then become BORROWING_RESTRICTED.
   controlClass_.initialise();
   controlClass_.cardSwiped(2); // Member ID = 2.
   assertTrue(memberDao_.getMemberByID(2).hasOverDueLoans());
   assertEquals(EBorrowState.BORROWING_RESTRICTED, controlClass_.getState());
 }
 @Test
 public void testCardSwipedUnrestricted3() {
   // We will test swipe card with a member who exists and is not restricted.
   // This test will be with a member who has loans, but not overdue.
   // The state should still then become SCANNING_BOOKS.
   controlClass_.initialise();
   controlClass_.cardSwiped(6); // Member ID = 6.
   assertTrue(loanDao_.findLoansByBorrower(memberDao_.getMemberByID(6)).size() > 0);
   assertEquals(EBorrowState.SCANNING_BOOKS, controlClass_.getState());
 }
 @Test
 public void testCardSwipedUnrestricted2() {
   // We will test swipe card with a member who exists and is not restricted.
   // This test will be with a member who has fines payable.
   // The state should still then become SCANNING_BOOKS.
   controlClass_.initialise();
   controlClass_.cardSwiped(5); // Member ID = 5.
   assertTrue(memberDao_.getMemberByID(5).hasFinesPayable());
   assertEquals(EBorrowState.SCANNING_BOOKS, controlClass_.getState());
 }
Ejemplo n.º 7
0
  @Override
  public void cardSwiped(int memberID) {
    System.out.println("cardSwiped: got " + memberID);
    if (!state.equals(EBorrowState.INITIALIZED)) {
      throw new RuntimeException(
          String.format("BorrowUC_CTL : cardSwiped : illegal operation in state: %s", state));
    }
    borrower = memberDAO.getMemberByID(memberID);
    if (borrower == null) {
      ui.displayErrorMessage(String.format("Member ID %d not found", memberID));
      return;
    }
    boolean overdue = borrower.hasOverDueLoans();
    boolean atLoanLimit = borrower.hasReachedLoanLimit();
    boolean hasFines = borrower.hasFinesPayable();
    boolean overFineLimit = borrower.hasReachedFineLimit();
    boolean borrowing_restricted = (overdue || atLoanLimit || overFineLimit);

    if (borrowing_restricted) {
      setState(EBorrowState.BORROWING_RESTRICTED);
    } else {
      setState(EBorrowState.SCANNING_BOOKS);
    }

    // display member details
    int mID = borrower.getID();
    String mName = borrower.getFirstName() + " " + borrower.getLastName();
    String mContact = borrower.getContactPhone();
    ui.displayMemberDetails(mID, mName, mContact);

    if (hasFines) {
      float amountOwing = borrower.getFineAmount();
      ui.displayOutstandingFineMessage(amountOwing);
    }

    if (overdue) {
      ui.displayOverDueMessage();
    }

    if (atLoanLimit) {
      ui.displayAtLoanLimitMessage();
    }

    if (overFineLimit) {
      System.out.println("State: " + state);
      float amountOwing = borrower.getFineAmount();
      ui.displayOverFineLimitMessage(amountOwing);
    }

    // display existing loans
    String loanString = buildLoanListDisplay(borrower.getLoans());
    ui.displayExistingLoan(loanString);
  }