@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());
 }
예제 #6
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);
  }