PrivateBankTest.java De-/Serialize Tests
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
[
|
||||
{
|
||||
"CLASSNAME": "Payment",
|
||||
"INSTANCE": {
|
||||
"incomingInterest": 0.5,
|
||||
"outgoingInterest": 0.25,
|
||||
"date": "10.01.1988",
|
||||
"amount": 1500.0,
|
||||
"description": "Deposit; 1500"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CLASSNAME": "IncomingTransfer",
|
||||
"INSTANCE": {
|
||||
"sender": "Eva",
|
||||
"recipient": "Max",
|
||||
"date": "01.01.2021",
|
||||
"amount": 150.0,
|
||||
"description": "Incoming Transfer; Eva-\u003eMax; 150"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CLASSNAME": "OutgoingTransfer",
|
||||
"INSTANCE": {
|
||||
"sender": "Max",
|
||||
"recipient": "Eva",
|
||||
"date": "03.01.2021",
|
||||
"amount": 50.0,
|
||||
"description": "Outgoing Transfer; Max-\u003eEva; 50"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CLASSNAME": "Payment",
|
||||
"INSTANCE": {
|
||||
"incomingInterest": 0.5,
|
||||
"outgoingInterest": 0.25,
|
||||
"date": "01.01.24",
|
||||
"amount": 10.0,
|
||||
"description": "Verwendungszweck P1"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -26,20 +26,21 @@ public class PrivateBankTest {
|
||||
public static void init() throws AccountAlreadyExistsException, IOException, TransactionAlreadyExistException,
|
||||
AccountDoesNotExistException, TransactionAttributeException {
|
||||
|
||||
final File folder = new File("data/junit5");
|
||||
String path = "accountdata";
|
||||
|
||||
final File folder = new File(path);
|
||||
if (folder.exists()) {
|
||||
final File[] listOfFiles = folder.listFiles();
|
||||
assert listOfFiles != null;
|
||||
for (File file : listOfFiles)
|
||||
file.delete();
|
||||
Files.deleteIfExists(Path.of("data/junit5"));
|
||||
if (file.delete()) System.out.println(file.getName() + " deleted");
|
||||
}
|
||||
|
||||
privateBank = new PrivateBank(
|
||||
"Testbank",
|
||||
0,
|
||||
0,
|
||||
"data/test"
|
||||
path
|
||||
);
|
||||
|
||||
privateBank.createAccount("Konto_1");
|
||||
@@ -65,16 +66,16 @@ public class PrivateBankTest {
|
||||
)
|
||||
);
|
||||
copyPrivateBank = new PrivateBank(privateBank);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@DisplayName("Testing constructor")
|
||||
@Test
|
||||
@Order(0)
|
||||
public void constructorTest() {
|
||||
assertAll("PrivateBank",
|
||||
() -> assertEquals("Testbank", privateBank.getName()),
|
||||
() -> assertEquals("data/test", privateBank.getDirectoryName()),
|
||||
() -> assertEquals("accountdata", privateBank.getDirectoryName()),
|
||||
() -> assertEquals(0, privateBank.getIncomingInterest()),
|
||||
() -> assertEquals(0, privateBank.getOutgoingInterest()));
|
||||
}
|
||||
@@ -411,4 +412,24 @@ public class PrivateBankTest {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@DisplayName("Serialize Accounts")
|
||||
@Order(18)
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||
public void serializeAccountsTest(String account) {
|
||||
assertDoesNotThrow(
|
||||
() -> privateBank.writeAccount(account)
|
||||
);
|
||||
System.out.println("SerializeAccountsTest in <" + account + "> is correct.");
|
||||
}
|
||||
|
||||
@DisplayName("Deserialize Accounts")
|
||||
@Order(19)
|
||||
@Test
|
||||
public void DeserializeAccountsTest() {
|
||||
assertThrows(
|
||||
AccountAlreadyExistsException.class, () -> privateBank.readAccounts()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user