53 lines
1.6 KiB
Plaintext
53 lines
1.6 KiB
Plaintext
package oving7.abstractaccount;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class DebitAccountTest {
|
|
|
|
private static final double epsilon = 0.0005;
|
|
|
|
private DebitAccount sub;
|
|
|
|
@BeforeEach
|
|
public void setUp() {
|
|
sub = new DebitAccount();
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Check that deposits work as expected")
|
|
public void testDeposit() {
|
|
assertEquals(0.0, sub.getBalance(), epsilon, "The account balance was incorrect");
|
|
|
|
sub.deposit(10_000.0);
|
|
assertEquals(10_000.0, sub.getBalance(), epsilon, "The account balance was incorrect");
|
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
sub.deposit(-10_000.0);
|
|
}, "Negative deposit should have triggered an IllegalArgumentException!");
|
|
|
|
assertEquals(10_000.0, sub.getBalance(), epsilon, "The account balance was incorrect");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Check that withdrawals work as expected")
|
|
public void testWithdraw() {
|
|
sub.deposit(20_000.0);
|
|
sub.withdraw(5000.0);
|
|
assertEquals(15_000.0, sub.getBalance(), epsilon, "The account balance was incorrect");
|
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
sub.withdraw(-10_000.0);
|
|
}, "Negative withdrawal should have triggered an IllegalArgumentException!");
|
|
|
|
assertEquals(15_000.0, sub.getBalance(), epsilon, "The account balance was incorrect");
|
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
sub.withdraw(20_000.0);
|
|
}, "Withdrawal exceeding the balance should have triggered an IllegalArgumentException");
|
|
}
|
|
}
|