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