0% found this document useful (0 votes)
30 views

Homework 1

Create JUnit tests for the Bank interface methods in a class called BankTest. Create a simple BankImpl class that implements the Bank interface. Run the tests and verify they succeed, correcting the BankImpl implementation until no tests fail. Write tests for methods before implementing them, like createAccount and findAccount, to drive the implementation.

Uploaded by

Suraj Raveendran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Homework 1

Create JUnit tests for the Bank interface methods in a class called BankTest. Create a simple BankImpl class that implements the Bank interface. Run the tests and verify they succeed, correcting the BankImpl implementation until no tests fail. Write tests for methods before implementing them, like createAccount and findAccount, to drive the implementation.

Uploaded by

Suraj Raveendran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Unit testing with JUnit

1) Create JUnit tests for methods exposed by the interface Bank in single class called BankTest.
2) Create simple implementation called BankImpl of interface Bank.
3) Run the tests and verify if they succeed. If not, correct/complete the implementation until
there are no failed tests.

During implementation first try to write a couple of tests and then implement methods that are
verified by these tests. For example, write a couple of tests for createAccount and findAccount
methods, then run the tests (initially they should fail), then implement methods in BankImpl and
and run the tests again to verify them. If the tests succeed, write tests other methods, implement
methods, run tests to verify them and so on ... until you have completed the implementation of the
interface.

interface Bank {

/**
* Creates new account and returns its id or returns id of existing account
* @param name holder's name
* @param address holder's address
* @return id of newly created or existing account.
*/
Integer createAccount(String name, String address);

/**
* Finds id of an account.
* @param name holder's name
* @param address holder's address
* @return account id or null if there is no account with given parameters
*/
Integer findAccount(String name, String address);

/**
* Depsits given amount of money to account
* @param id
* @param amount
* @throws AccountIdException, if id is not valid (there is no acccount with given id)
*/
void deposit(Integer id, double amount);

/**
* Returns the balance of the account.
* @param id
* @return balance
* @throws AccountIdException, if id is not valid (there is no acccount with given id)
*/
double getBalance(Integer id);
/**
* Withdraws money from account.
* @param id
* @param amount
* @throws AccountIdException, if id is not valid (there is no acccount with given id)
* @throws InsufficientFundsException, when there is no sufficient funds to perform required
operation.
*/
void withdraw(Integer id, double amount);

/**
* Transfers money between accounts.
* @param idSource
* @param idDestination
* @param amount srodki
* @throws AccountIdException, if id is not valid (there is no acccount with given id)
* @throws InsufficientFundsException, when there is no sufficient funds to perform required
operation
*/
void transfer(Integer idSource, Integer idDestination, double amount);

class InsufficientFundsException extends RuntimeException {};


class AccountIdException extends RuntimeException {};
}

erajavaee16

Submission status
Attempt number This is attempt 1 ( 3 attempts allowed ).

Submission status No attempt

Grading status Not graded

Due date Thursday, 27 October 2016, 12:00 AM

Time remaining 5 days 10 hours

Last modified Friday, 21 October 2016, 1:33 PM


Submission comments Comments (0)

You might also like