示例#1
0
  @Test // Test customer statement generation
  public void statementTest() {

    Account checkingAccount = new Checking();
    Account savingsAccount = new Savings();

    Customer henry = new Customer("Henry");

    henry.openAccount(checkingAccount);
    henry.openAccount(savingsAccount);

    henry.deposit(100.0, checkingAccount);
    henry.deposit(4000.0, savingsAccount);
    henry.withdraw(200.0, savingsAccount);

    assertEquals(
        "Statement for Henry\n"
            + "\n"
            + "Checking Account\n"
            + "  deposit $100.00\n"
            + "Total $100.00\n"
            + "\n"
            + "Savings Account\n"
            + "  deposit $4,000.00\n"
            + "  withdrawal $200.00\n"
            + "Total $3,800.00\n"
            + "\n"
            + "Total In All Accounts $3,900.00",
        henry.getStatement());
  }
  @Test
  public void customerSummary() {
    Bank bank = new Bank();
    Customer john = new Customer("John");
    john.openAccount(new Account(Account.CHECKING));
    bank.addCustomer(john);

    assertEquals("Customer Summary\n - John (1 account)", bank.customerSummary());
  }
示例#3
0
  // Test if totalInterest() works
  @Test
  public void totalInterestTest() {
    Customer jo = new Customer("Jo");
    Account checking = new Checking();
    Account savings = new Savings();

    jo.openAccount(checking, savings);

    jo.deposit(100.0, checking);
    jo.deposit(100.0, savings);

    assertEquals(0.2, jo.totalInterestEarned(), DOUBLE_DELTA);
  }
示例#4
0
  // Test if deposit catches the wrong input
  @Test
  public void failedDepositTest() {
    Customer jo = new Customer("Jo");
    Account checking = new Checking();
    jo.openAccount(checking);

    try {
      jo.deposit(-90.0, checking);
      fail("Missed exception");
    } catch (Exception e) {
      String ex = "Amount must be greater than zero";
      assertEquals(ex, e.getMessage());
    }
  }
示例#5
0
  // Test if withdraw will fail if the amount is negative
  @Test
  public void withdrawNegativeTest() {
    Customer jo = new Customer("Jo");
    Account checking = new Checking();
    jo.openAccount(checking);
    jo.deposit(90.0, checking);

    try {
      jo.withdraw(-8921.0, checking);
      fail("Skipped exception");
    } catch (Exception e) {
      String ex = "Amount must be greater than zero";
      assertEquals(ex, e.getMessage());
    }
  }
示例#6
0
  // Test if withdraw will fail if the amount is more than what is in the account
  @Test
  public void withdrawTooMuchTest() {
    Customer jo = new Customer("Jo");
    Account checking = new Checking();
    jo.openAccount(checking);
    jo.deposit(90.0, checking);

    try {
      jo.withdraw(900.0, checking);
      fail("Missed exception");
    } catch (Exception e) {
      String ex = "Amount must be less than current amount $90.00";
      assertEquals(ex, e.getMessage());
    }
  }
示例#7
0
  // Test if deposit works
  @Test
  public void depositTest() {
    Customer jo = new Customer("Jo");
    Account checking = new Checking();
    jo.openAccount(checking);
    jo.deposit(100.0, checking);

    assertEquals(
        "Statement for Jo\n"
            + "\n"
            + "Checking Account\n"
            + "  deposit $100.00\n"
            + "Total $100.00\n"
            + "\n"
            + "Total In All Accounts $100.00",
        jo.getStatement());
  }