Last active
August 29, 2015 14:12
-
-
Save Vaysman/3baeb8e5c0226b3bfffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.luxoft.bankapp.model; | |
import com.luxoft.bankapp.model.exception.OverDraftLimitExceededException; | |
import org.junit.Before; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
// test only CheckingAccount specific functionality | |
// do not test AbstractAccount functionality | |
public class CheckingAccountTest { | |
private CheckingAccount sut; | |
// if you need to create same object for all your tests | |
// use @Before annotation for this purpose | |
// this method will be executed before every test | |
@Before | |
public void createCheckingAccountWithBalance0AndOverdraft100() { | |
sut = new CheckingAccount(0, 100); | |
} | |
@Test | |
public void testSetOverdraftInConstructor() { | |
sut = new CheckingAccount(0, 1.0f); | |
assertEquals(1.0f, sut.getOverdraft(), 0); | |
} | |
@Test | |
public void testSetBalanceAndOverdraftInConstructor() { | |
sut = new CheckingAccount(1.0f, 2.0f); | |
assertEquals(1.0f, sut.getBalance(), 0); | |
assertEquals(2.0f, sut.getOverdraft(), 0); | |
} | |
@Test(expected = IllegalArgumentException.class) | |
public void testNegativeOverdraftThrowException() { | |
sut = new CheckingAccount(0, -1.0f); | |
} | |
@Test | |
public void testWithdrawDecreaseBalance() { | |
sut.deposit(10); | |
sut.withdraw(5); | |
assertEquals(5.0f, sut.getBalance(), 0.00001f); | |
} | |
@Test | |
public void testWithdrawMoreThanBalanceDecreaseBalance() { | |
sut.withdraw(5); | |
assertEquals(-5.0f, sut.getBalance(), 0.00001f); | |
} | |
@Test(expected = OverDraftLimitExceededException.class) | |
public void testWithdrawMoreThanBalancePlusOverdraftThrowsException() { | |
sut = new CheckingAccount(0, 0); | |
sut.withdraw(1.0f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment