Question: Write a java unit test (JUnit4) to test the following class. public class BankAccount { private string m_customerName; private double m_balance; private bool m_frozen =

Write a java unit test (JUnit4) to test the following class.

public class BankAccount { private string m_customerName; private double m_balance; private bool m_frozen = false; private BankAccount() { } public BankAccount(string customerName, double balance) { m_customerName = customerName; m_balance = balance; } public string CustomerName { get { return m_customerName; } } public double Balance { get { return m_balance; } } public void Debit(double amount) { if (m_frozen) { throw new Exception("Account frozen"); } if (amount > m_balance) { throw new ArgumentOutOfRangeException("amount"); } if (amount < 0) { throw new ArgumentOutOfRangeException("amount"); } m_balance += amount; // intentionally incorrect code } public void Credit(double amount) { if (m_frozen) { throw new Exception("Account frozen"); } if (amount < 0) { throw new ArgumentOutOfRangeException("amount"); } m_balance += amount; } private void FreezeAccount() { m_frozen = true; } private void UnfreezeAccount() { m_frozen = false; } public static void Main() { BankAccount ba = new BankAccount("Mr. Bryan Walton", 11.99); ba.Credit(5.77); ba.Debit(11.22); Console.WriteLine("Current balance is ${0}", ba.Balance); } } }

Test only the debit method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!