fertige Tests für Private Bank
This commit is contained in:
@@ -36,32 +36,32 @@ public class PrivateBankTest {
|
||||
}
|
||||
|
||||
privateBank = new PrivateBank(
|
||||
"JUnit 5",
|
||||
"Testbank",
|
||||
0,
|
||||
0,
|
||||
"data/test"
|
||||
);
|
||||
|
||||
privateBank.createAccount("Hagen");
|
||||
privateBank.createAccount("Tim");
|
||||
privateBank.createAccount("Konto_1");
|
||||
privateBank.createAccount("Konto_2");
|
||||
privateBank.addTransaction(
|
||||
"Hagen",
|
||||
"Konto_1",
|
||||
new Payment(
|
||||
"19.01.2011",
|
||||
-789,
|
||||
"01.01.2000",
|
||||
-100,
|
||||
"Payment",
|
||||
0.9,
|
||||
0.25
|
||||
)
|
||||
);
|
||||
privateBank.addTransaction(
|
||||
"Tim",
|
||||
"Konto_2",
|
||||
new IncomingTransfer(
|
||||
"03.03.2000",
|
||||
80,
|
||||
"IncomingTransfer from Adam to Tim; 80",
|
||||
"Adam",
|
||||
"Tim"
|
||||
"01.01.2000",
|
||||
100,
|
||||
"1 -> 2",
|
||||
"Konto_1",
|
||||
"Konto_2"
|
||||
)
|
||||
);
|
||||
copyPrivateBank = new PrivateBank(privateBank);
|
||||
@@ -73,10 +73,10 @@ public class PrivateBankTest {
|
||||
@Order(0)
|
||||
public void constructorTest() {
|
||||
assertAll("PrivateBank",
|
||||
() -> assertEquals("JUnit 5", privateBank.getName()),
|
||||
() -> assertEquals("junit5", privateBank.getDirectoryName()),
|
||||
() -> assertEquals("Testbank", privateBank.getName()),
|
||||
() -> assertEquals("data/test", privateBank.getDirectoryName()),
|
||||
() -> assertEquals(0, privateBank.getIncomingInterest()),
|
||||
() -> assertEquals(0.12, privateBank.getOutgoingInterest()));
|
||||
() -> assertEquals(0, privateBank.getOutgoingInterest()));
|
||||
}
|
||||
|
||||
@DisplayName("Testing copy constructor")
|
||||
@@ -93,7 +93,7 @@ public class PrivateBankTest {
|
||||
@DisplayName("Create a duplicate account")
|
||||
@ParameterizedTest
|
||||
@Order(2)
|
||||
@ValueSource(strings = {"Hagen", "Tim"})
|
||||
@ValueSource(strings = {"Konto_1", "Konto_2"})
|
||||
public void createDuplicateAccountTest(String account) {
|
||||
Exception e = assertThrows(AccountAlreadyExistsException.class,
|
||||
() -> privateBank.createAccount(account));
|
||||
@@ -103,7 +103,7 @@ public class PrivateBankTest {
|
||||
@DisplayName("Create a valid account")
|
||||
@ParameterizedTest
|
||||
@Order(3)
|
||||
@ValueSource(strings = {"Dinesh", "Bob", "Narsha"})
|
||||
@ValueSource(strings = {"Konto_3", "Konto_4", "Konto_5"})
|
||||
public void createValidAccountTest(String account) {
|
||||
assertDoesNotThrow(
|
||||
() -> privateBank.createAccount(account)
|
||||
@@ -113,25 +113,32 @@ public class PrivateBankTest {
|
||||
@DisplayName("Create a valid account with a transactions list")
|
||||
@ParameterizedTest
|
||||
@Order(4)
|
||||
@ValueSource(strings = {"Klaus", "Harsh", "Rastla"})
|
||||
@ValueSource(strings = {"Konto_6", "Konto_7", "Konto_8"})
|
||||
public void createValidAccountWithTransactionsListTest(String account) {
|
||||
assertDoesNotThrow(
|
||||
() -> privateBank.createAccount(
|
||||
account,
|
||||
List.of(
|
||||
new Payment(
|
||||
"23.09.1897",
|
||||
-2500,
|
||||
"01.01.2000",
|
||||
-100,
|
||||
"Payment 02",
|
||||
0.8,
|
||||
0.5
|
||||
),
|
||||
new IncomingTransfer(
|
||||
"01.01.2000",
|
||||
100,
|
||||
"IncomingTransfer from Hans",
|
||||
"Hans",
|
||||
account
|
||||
),
|
||||
new OutgoingTransfer(
|
||||
"30.07.2020",
|
||||
1890,
|
||||
"OutgoingTransfer to Hagen",
|
||||
"01.01.2000",
|
||||
100,
|
||||
"OutgoingTransfer to Hans",
|
||||
account,
|
||||
"Hagen"
|
||||
"Hans"
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -141,18 +148,18 @@ public class PrivateBankTest {
|
||||
@DisplayName("Create a duplicate account with a transactions list")
|
||||
@ParameterizedTest
|
||||
@Order(5)
|
||||
@ValueSource(strings = {"Hagen", "Klaus", "Tim", "Bob", "Dinesh", "Narsha", "Harsh", "Rastla"})
|
||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||
public void createInvalidAccountWithTransactionsListTest(String account) {
|
||||
Exception e = assertThrows(AccountAlreadyExistsException.class,
|
||||
() -> privateBank.createAccount(
|
||||
account,
|
||||
List.of(
|
||||
new Payment(
|
||||
"23.09.1897",
|
||||
-2500,
|
||||
"Payment 02",
|
||||
0.8,
|
||||
0.5
|
||||
"01.01.2000",
|
||||
0,
|
||||
"P",
|
||||
0,
|
||||
0
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -163,15 +170,15 @@ public class PrivateBankTest {
|
||||
@DisplayName("Add a valid transaction to a valid account")
|
||||
@ParameterizedTest
|
||||
@Order(6)
|
||||
@ValueSource(strings = {"Hagen", "Bob", "Narsha", "Dinesh", "Klaus"})
|
||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||
public void addValidTransactionValidAccountTest(String account) {
|
||||
assertDoesNotThrow(
|
||||
() -> privateBank.addTransaction(
|
||||
account,
|
||||
new IncomingTransfer(
|
||||
"30.07.2020",
|
||||
1890,
|
||||
"OutgoingTransfer to Hagen",
|
||||
"01.01.2000",
|
||||
300,
|
||||
"IncomingTransfer from Tom",
|
||||
"Tom",
|
||||
account
|
||||
)
|
||||
@@ -182,17 +189,17 @@ public class PrivateBankTest {
|
||||
@DisplayName("Add a duplicate transaction to a valid account")
|
||||
@ParameterizedTest
|
||||
@Order(7)
|
||||
@ValueSource(strings = {"Klaus", "Harsh", "Rastla"})
|
||||
@ValueSource(strings = {"Konto_6", "Konto_7", "Konto_8"})
|
||||
public void addDuplicateTransactionTest(String account) {
|
||||
Exception e = assertThrows(TransactionAlreadyExistException.class,
|
||||
() -> privateBank.addTransaction(
|
||||
account,
|
||||
new Payment(
|
||||
"23.09.1897",
|
||||
-2500,
|
||||
"01.01.2000",
|
||||
-100,
|
||||
"Payment 02",
|
||||
0.8,
|
||||
0.5
|
||||
privateBank.getIncomingInterest(),
|
||||
privateBank.getOutgoingInterest()
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -202,14 +209,14 @@ public class PrivateBankTest {
|
||||
@DisplayName("Add a valid transaction to an invalid account")
|
||||
@ParameterizedTest
|
||||
@Order(8)
|
||||
@ValueSource(strings = {"Gina", "Bona", "Yang"})
|
||||
@ValueSource(strings = {"Konto_X", "Konto_Y", "Konto_Z"})
|
||||
public void addTransactionInvalidAccountTest(String account) {
|
||||
Exception e = assertThrows(AccountDoesNotExistException.class,
|
||||
() -> privateBank.addTransaction(
|
||||
account,
|
||||
new Payment(
|
||||
"19.01.2011",
|
||||
-789,
|
||||
"01.01.2001",
|
||||
-100,
|
||||
"Payment",
|
||||
0.9,
|
||||
0.25
|
||||
@@ -222,17 +229,17 @@ public class PrivateBankTest {
|
||||
@DisplayName("Remove a valid transaction")
|
||||
@ParameterizedTest
|
||||
@Order(9)
|
||||
@ValueSource(strings = {"Harsh", "Rastla", "Klaus"})
|
||||
@ValueSource(strings = {"Konto_6", "Konto_7", "Konto_8"})
|
||||
public void removeValidTransactionTest(String account) {
|
||||
assertDoesNotThrow(
|
||||
() -> privateBank.removeTransaction(
|
||||
account,
|
||||
new Payment(
|
||||
"23.09.1897",
|
||||
-2500,
|
||||
"01.01.2000",
|
||||
-100,
|
||||
"Payment 02",
|
||||
0.8,
|
||||
0.5
|
||||
privateBank.getIncomingInterest(),
|
||||
privateBank.getOutgoingInterest()
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -241,15 +248,15 @@ public class PrivateBankTest {
|
||||
@DisplayName("Remove an invalid transaction")
|
||||
@ParameterizedTest
|
||||
@Order(10)
|
||||
@ValueSource(strings = {"Harsh", "Rastla", "Klaus"})
|
||||
@ValueSource(strings = {"Konto_6", "Konto_7", "Konto_8"})
|
||||
public void removeInvalidTransactionTest(String account) {
|
||||
Exception e = assertThrows(
|
||||
TransactionDoesNotExistException.class,
|
||||
() -> privateBank.removeTransaction(
|
||||
account,
|
||||
new Payment(
|
||||
"19.01.2011",
|
||||
-789,
|
||||
"01.01.2002",
|
||||
-100,
|
||||
"Payment",
|
||||
0.9,
|
||||
0.25
|
||||
@@ -262,17 +269,17 @@ public class PrivateBankTest {
|
||||
@DisplayName("Contains a transaction is true")
|
||||
@ParameterizedTest
|
||||
@Order(11)
|
||||
@ValueSource(strings = {"Harsh", "Rastla", "Klaus"})
|
||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||
public void containsTransactionTrueTest(String account) {
|
||||
assertTrue(
|
||||
privateBank.containsTransaction(
|
||||
account,
|
||||
new OutgoingTransfer(
|
||||
"30.07.2020",
|
||||
1890,
|
||||
"OutgoingTransfer to Hagen",
|
||||
account,
|
||||
"Hagen"
|
||||
new IncomingTransfer(
|
||||
"01.01.2000",
|
||||
300,
|
||||
"IncomingTransfer from Tom",
|
||||
"Tom",
|
||||
account
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -282,17 +289,17 @@ public class PrivateBankTest {
|
||||
@DisplayName("Contains a transaction is false")
|
||||
@ParameterizedTest
|
||||
@Order(12)
|
||||
@ValueSource(strings = {"Hagen", "Bob", "Narsha", "Dinesh", "Tim"})
|
||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||
public void containsTransactionFalseTest(String account) {
|
||||
assertFalse(
|
||||
privateBank.containsTransaction(
|
||||
account,
|
||||
new OutgoingTransfer(
|
||||
"30.07.2020",
|
||||
1890,
|
||||
"OutgoingTransfer to Hagen",
|
||||
account,
|
||||
"Hagen"
|
||||
new IncomingTransfer(
|
||||
"01.01.2020",
|
||||
0,
|
||||
"IncomingTransfer from Tom",
|
||||
"Tom",
|
||||
account
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -302,7 +309,7 @@ public class PrivateBankTest {
|
||||
@DisplayName("Get account balance")
|
||||
@ParameterizedTest
|
||||
@Order(14)
|
||||
@CsvSource({"Klaus, 0", "Tim, 80", "Hagen, 1006.32"})
|
||||
@CsvSource({"Konto_1, 200", "Konto_4, 300", "Konto_6, 300"})
|
||||
public void getAccountBalanceTest(String account, double balance) {
|
||||
System.out.println(
|
||||
"Expected <" + balance + "> in account <" + account + ">"
|
||||
@@ -318,25 +325,33 @@ public class PrivateBankTest {
|
||||
@Order(15)
|
||||
public void getTransactionTest() {
|
||||
List<Transaction> transactionList = List.of(
|
||||
new Payment(
|
||||
"19.01.2011",
|
||||
-789,
|
||||
"Payment",
|
||||
0,
|
||||
0.12),
|
||||
new IncomingTransfer(
|
||||
"30.07.2020",
|
||||
1890,
|
||||
"OutgoingTransfer to Hagen",
|
||||
"01.01.2000",
|
||||
100,
|
||||
"IncomingTransfer from Hans",
|
||||
"Hans",
|
||||
"Konto_6"
|
||||
),
|
||||
new OutgoingTransfer(
|
||||
"01.01.2000",
|
||||
100,
|
||||
"OutgoingTransfer to Hans",
|
||||
"Konto_6",
|
||||
"Hans"
|
||||
),
|
||||
new IncomingTransfer(
|
||||
"01.01.2000",
|
||||
300,
|
||||
"IncomingTransfer from Tom",
|
||||
"Tom",
|
||||
"Hagen"
|
||||
"Konto_6"
|
||||
)
|
||||
);
|
||||
assertEquals(
|
||||
transactionList,
|
||||
privateBank.getTransactions("Hagen")
|
||||
privateBank.getTransactions("Konto_6")
|
||||
);
|
||||
System.out.println("getTransactionTest in <Hagen> is correct.");
|
||||
System.out.println("getTransactionTest in <Konto_6> is correct.");
|
||||
}
|
||||
|
||||
@DisplayName("Get transactions list by type")
|
||||
@@ -344,22 +359,22 @@ public class PrivateBankTest {
|
||||
@Order(16)
|
||||
public void getTransactionsByTypeTest() {
|
||||
List<Transaction> transactionList = List.of(
|
||||
new OutgoingTransfer(
|
||||
"30.07.2020",
|
||||
1890,
|
||||
"OutgoingTransfer to Hagen",
|
||||
"Klaus",
|
||||
"Hagen"
|
||||
new IncomingTransfer(
|
||||
"01.01.2000",
|
||||
300,
|
||||
"IncomingTransfer from Tom",
|
||||
"Tom",
|
||||
"Konto_1"
|
||||
)
|
||||
);
|
||||
assertEquals(
|
||||
transactionList,
|
||||
privateBank.getTransactionsByType(
|
||||
"Klaus",
|
||||
"Konto_1",
|
||||
false
|
||||
)
|
||||
);
|
||||
System.out.println("getTransactionByTypeTest in <Klaus> is correct.");
|
||||
System.out.println("getTransactionByTypeTest in <Konto_1> is correct.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -368,16 +383,30 @@ public class PrivateBankTest {
|
||||
public void getTransactionsSortedTest() {
|
||||
assertEquals(
|
||||
List.of(
|
||||
new OutgoingTransfer(
|
||||
"01.01.2000",
|
||||
100,
|
||||
"OutgoingTransfer to Hans",
|
||||
"Konto_6",
|
||||
"Hans"
|
||||
),
|
||||
new IncomingTransfer(
|
||||
"03.03.2000",
|
||||
80,
|
||||
"IncomingTransfer from Adam to Tim; 80",
|
||||
"Adam",
|
||||
"Tim"
|
||||
"01.01.2000",
|
||||
100,
|
||||
"IncomingTransfer from Hans",
|
||||
"Hans",
|
||||
"Konto_6"
|
||||
),
|
||||
new IncomingTransfer(
|
||||
"01.01.2000",
|
||||
300,
|
||||
"IncomingTransfer from Tom",
|
||||
"Tom",
|
||||
"Konto_6"
|
||||
)
|
||||
),
|
||||
privateBank.getTransactionsSorted(
|
||||
"Tim",
|
||||
"Konto_6",
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user