import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.cp.exercise.atm.exception.InsufficientBalanceException;
import com.cp.exercise.atm.exception.InvalidDenominationException;
import com.cp.exercise.atm.exception.InvalidUserAccountExcetion;
public class TestATMClient {
private ATMClient client;
private UserAccount userAccount;
@Before
public void filledUserAccountWithBalance() {
client = ATMClient.instanceOf();
userAccount = new UserAccount("123455632", "pin");
final int tenThousand = Denomination.FIVE_HUNDRED.getNote() * 20;
client.filledUserAccountWithInitialBalance(userAccount, tenThousand);
}
@Test(expected=InvalidUserAccountExcetion.class)
public void shouldThrowAnExceptionIfAccountDoesNotExist() {
final UserAccount invalidUserAccount = new UserAccount("", "");
Assert.assertEquals(10000, client.checkBalance(invalidUserAccount));
}
@Test
public void userShouldAbleSeeTotalAvailableBalance() {
Assert.assertEquals(10000, client.checkBalance(userAccount));
}
@Test
public void userShouldAbleToWithdrawAmountWithCorrectDenomination() {
final Map
Assert.assertEquals(4, denominationToCount.get(Denomination.FIVE_HUNDRED));
Assert.assertEquals(2, denominationToCount.get(Denomination.HUNDRED));
Assert.assertEquals(null, denominationToCount.get(Denomination.FIFTY));
Assert.assertEquals(7800, client.checkBalance(userAccount));
}
@Test(expected=InvalidDenominationException.class)
public void userShouldGetAnErrorMessageIfTheWithdrawelAmountIsNotMultilierOfAvailableDenomination() {
client.withdrawThisMuchAmount(userAccount, 1999);
}
@Test(expected=InsufficientBalanceException.class)
public void userShouldGetAnErrorMessageIfMinimumBalanceFallBelowMinimumDenomination() {
client.withdrawThisMuchAmount(userAccount, 11000);
}
}
No comments:
Post a Comment