CECS 277
LAB ASSIGNMENT 8
Assigned date: 12/6
Due date: 12/11

15 points

1. [8 points] Follow the link Introduction to Unit Testing  pdf  word   to perform three test in the document.

Run all the tests with Eclipse.

2. [7 points] Write a unit test to test the following class.

import java.util.*;
public class BankAccount
{
private String customerName;

private double balance;

private boolean frozen = false;

private BankAccount()
{
}

public BankAccount(String Name, double balance)
{
customerName = Name;
this.balance = balance;
}

public String getCustomerName()
{
return customerName;
}

public double getBalance()
{
return balance;
}

public void setDebit(double amount) throws Exception
{
if (frozen)
{
throw new IllegalArgumentException("Cannot divide by 0!");
}

if (amount > balance)
{
throw new Exception("amount");
}

if (amount < 0)
{
throw new Exception("amount");
}

balance += amount; // intentionally incorrect code
}

public void setCredit(double amount) throws Exception
{
if (frozen)
{
throw new Exception("Account frozen");
}

if (amount < 0)
{
throw new Exception("amount");
}

balance += amount;
}

private void FreezeAccount()
{
frozen = true;
}

private void UnfreezeAccount()
{
frozen = false;
}
}

The main method

import java.util.*;
public class BankaccountTest {

public static void main(String[] args) throws Exception
{
// TODO Auto-generated method stub
BankAccount ba = new BankAccount("Mr. Bryan Walton", 3.5);

ba.setCredit(5.00);
ba.setDebit(2.0);
System.out.println("Current balance is " + ba.getBalance());

}

}

Test only the debit method in the BankAccount.