Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 202f13d2bf | |||
| 1eb50ea3be | |||
| c3166986a3 | |||
| 7a2d7641d4 | |||
| 05ab636670 | |||
| db8ee0c3e6 | |||
| 96f3689792 | |||
| b475ca846b | |||
| aaed0d8af7 | |||
| 83041b4bf1 | |||
| f01bd8e7c3 | |||
| a3aa3af70b | |||
| 9c4877edee | |||
| ed73c8e876 | |||
| 47f9285f37 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,6 +3,7 @@ target/
|
|||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea/modules.xml
|
.idea/modules.xml
|
||||||
.idea/jarRepositories.xml
|
.idea/jarRepositories.xml
|
||||||
@@ -35,4 +36,7 @@ build/
|
|||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
### Accountdata ###
|
||||||
|
/accountdata
|
||||||
28
pom.xml
28
pom.xml
@@ -2,7 +2,7 @@
|
|||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<artifactId>P4</artifactId>
|
<artifactId>P5</artifactId>
|
||||||
<groupId>de.fh_aachen.oos</groupId>
|
<groupId>de.fh_aachen.oos</groupId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
@@ -12,12 +12,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<configuration>
|
|
||||||
<compilerArgs>
|
|
||||||
<arg>--release</arg>
|
|
||||||
<arg>17</arg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
<version>3.13.0</version>
|
<version>3.13.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -25,6 +19,14 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>3.2.5</version>
|
<version>3.2.5</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>javafx-maven-plugin</artifactId>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<version>${javafx.maven.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>ui.main</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@@ -39,6 +41,16 @@
|
|||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<version>2.11.0</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<artifactId>javafx-controls</artifactId>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<version>${javafx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<artifactId>javafx-fxml</artifactId>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<version>${javafx.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -55,6 +67,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.release>17</maven.compiler.release>
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<javafx.version>22</javafx.version>
|
||||||
|
<javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
@@ -97,4 +97,19 @@ public interface Bank {
|
|||||||
* @return the list of all transactions by type
|
* @return the list of all transactions by type
|
||||||
*/
|
*/
|
||||||
List<Transaction> getTransactionsByType(String account, boolean positive);
|
List<Transaction> getTransactionsByType(String account, boolean positive);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delets an existing account
|
||||||
|
* @param account the account to be deleted
|
||||||
|
* @throws AccountDoesNotExistException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
void deleteAccount(String account) throws AccountDoesNotExistException, IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all account names
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> getAllAccounts();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Transaction> getTransactionsByType(String account, boolean positive) {
|
public List<Transaction> getTransactionsByType(String account, boolean positive) {
|
||||||
|
// an der Kopie der Liste Arbeiten oder nur Filtern und nicht entfernen
|
||||||
List<Transaction> transactions = new ArrayList<>(this.accountsToTransactions.get(account));
|
List<Transaction> transactions = new ArrayList<>(this.accountsToTransactions.get(account));
|
||||||
if (positive)
|
if (positive)
|
||||||
transactions.removeIf(transaction -> transaction.calculate() >= 0);
|
transactions.removeIf(transaction -> transaction.calculate() >= 0);
|
||||||
@@ -362,6 +363,47 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
return transactions;
|
return transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delets an existing account
|
||||||
|
*
|
||||||
|
* @param account the account to be deleted
|
||||||
|
* @throws AccountDoesNotExistException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteAccount(String account) throws AccountDoesNotExistException, IOException {
|
||||||
|
if (this.containsAccount(account)) {
|
||||||
|
// delete account
|
||||||
|
this.accountsToTransactions.remove(account);
|
||||||
|
|
||||||
|
// delete corresponding JSON file
|
||||||
|
String filename = directoryName + "/" + account + ".json";
|
||||||
|
File file = new File(filename);
|
||||||
|
if (!file.delete())
|
||||||
|
throw new IOException("Datei des Accounts: " + account + " konnte nicht richtig gelöscht werden.");
|
||||||
|
} else {
|
||||||
|
throw new AccountDoesNotExistException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all account names
|
||||||
|
*
|
||||||
|
* @return List of all accounts
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getAllAccounts() {
|
||||||
|
List<String> accounts = new ArrayList<>();
|
||||||
|
|
||||||
|
this.accountsToTransactions.forEach(
|
||||||
|
(account, transactions) -> {
|
||||||
|
accounts.add(account);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return accounts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import Accounts from existing JSON Files
|
* Import Accounts from existing JSON Files
|
||||||
*
|
*
|
||||||
@@ -394,9 +436,9 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
|
|
||||||
JsonElement accountData = JsonParser.parseString(jsonContent);
|
JsonElement accountData = JsonParser.parseString(jsonContent);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
transactions = readAccountHelper(accountData, accountName);
|
transactions = readAccountHelper(accountData, accountName);
|
||||||
} catch (IOException e){
|
} catch (IOException e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -411,9 +453,9 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
for (JsonElement account : accountData.getAsJsonArray()) {
|
for (JsonElement account : accountData.getAsJsonArray()) {
|
||||||
JsonObject accountObject = account.getAsJsonObject();
|
JsonObject accountObject = account.getAsJsonObject();
|
||||||
Transaction t;
|
Transaction t;
|
||||||
try{
|
try {
|
||||||
t = deserialize(accountObject, null, null);
|
t = deserialize(accountObject, null, null);
|
||||||
} catch (JsonParseException e){
|
} catch (JsonParseException e) {
|
||||||
throw new IOException("Fehler beim Laden des Accounts: " + accountName);
|
throw new IOException("Fehler beim Laden des Accounts: " + accountName);
|
||||||
}
|
}
|
||||||
transactions.add(t);
|
transactions.add(t);
|
||||||
@@ -437,9 +479,9 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
List<Transaction> transactions = this.accountsToTransactions.get(account);
|
List<Transaction> transactions = this.accountsToTransactions.get(account);
|
||||||
|
|
||||||
for (Transaction transaction : transactions)
|
for (Transaction transaction : transactions)
|
||||||
try{
|
try {
|
||||||
accountData.add(serialize(transaction, null, null));
|
accountData.add(serialize(transaction, null, null));
|
||||||
} catch (JsonParseException e){
|
} catch (JsonParseException e) {
|
||||||
throw new IOException("Fehler beim Speichern des Accounts: " + account);
|
throw new IOException("Fehler beim Speichern des Accounts: " + account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,4 +577,6 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
|
|
||||||
return rootObject;
|
return rootObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
333
src/main/java/ui/AccountviewController.java
Normal file
333
src/main/java/ui/AccountviewController.java
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import bank.PrivateBank;
|
||||||
|
import bank.Transaction;
|
||||||
|
import bank.exceptions.AccountDoesNotExistException;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AccountviewController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label accountNameLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label balanceLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<Transaction> transactionListView;
|
||||||
|
|
||||||
|
private PrivateBank privateBank;
|
||||||
|
private String currentAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a second copied instance of a Bank
|
||||||
|
*
|
||||||
|
* @param accountName
|
||||||
|
* @param bank
|
||||||
|
*/
|
||||||
|
public void setAccount(String accountName, PrivateBank bank) {
|
||||||
|
this.currentAccount = accountName;
|
||||||
|
this.privateBank = bank;
|
||||||
|
updateAccountInfo();
|
||||||
|
loadTransactions();
|
||||||
|
|
||||||
|
// Kontextmenü erstellen
|
||||||
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
|
||||||
|
// Kontextmenü-Items definieren
|
||||||
|
MenuItem deleteItem = new MenuItem("Löschen");
|
||||||
|
|
||||||
|
// Kontextmenü-Item Aktion: Transaktion löschen
|
||||||
|
deleteItem.setOnAction(
|
||||||
|
event -> {
|
||||||
|
Transaction selectedTransaction = transactionListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedTransaction != null) {
|
||||||
|
boolean confirmed = showDeleteConfirmation(selectedTransaction);
|
||||||
|
if (confirmed) {
|
||||||
|
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
errorAlert.setTitle("Fehler");
|
||||||
|
try {
|
||||||
|
privateBank.removeTransaction(currentAccount, selectedTransaction);
|
||||||
|
transactionListView.getItems().remove(selectedTransaction);
|
||||||
|
updateAccountInfo();
|
||||||
|
} catch (AccountDoesNotExistException e) {
|
||||||
|
errorAlert.setHeaderText("Account existiert nicht");
|
||||||
|
errorAlert.setContentText("Der Account \"" + currentAccount + "\" existiert nicht.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (bank.exceptions.IOException e) {
|
||||||
|
errorAlert.setHeaderText("Account JSON Fehler");
|
||||||
|
errorAlert.setContentText("Die JSON des Accounts \"" + currentAccount + "\" konnte nicht bearbeitet werden.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorAlert.setHeaderText("Transaktion konnte nicht gelöscht werden.");
|
||||||
|
errorAlert.setContentText("Es ist ein unerwarteter Fehler aufgetreten.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Kontextmenü-Items dem Kontextmenü hinzufügen
|
||||||
|
contextMenu.getItems().add(deleteItem);
|
||||||
|
|
||||||
|
// An ListView binden
|
||||||
|
transactionListView.setContextMenu(contextMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the labels of an account
|
||||||
|
*/
|
||||||
|
private void updateAccountInfo() {
|
||||||
|
double balance = this.privateBank.getAccountBalance(currentAccount);
|
||||||
|
|
||||||
|
accountNameLabel.setText("Account: " + currentAccount);
|
||||||
|
balanceLabel.setText("Balance: " + balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadTransactions() {
|
||||||
|
showTransactions(this.privateBank.getTransactions(currentAccount));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onBackButtonClicked() {
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Mainview.fxml"));
|
||||||
|
Parent root = loader.load();
|
||||||
|
|
||||||
|
Stage stage = (Stage) transactionListView.getScene().getWindow();
|
||||||
|
stage.getScene().setRoot(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onSortAscending() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsSorted(currentAccount, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onSortDescending() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsSorted(currentAccount, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onShowPositive() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsByType(currentAccount, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onShowNegative() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsByType(currentAccount, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onShowAll() {
|
||||||
|
showTransactions(this.privateBank.getTransactions(currentAccount));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Listview of transaction based on a given list
|
||||||
|
*
|
||||||
|
* @param transactions
|
||||||
|
*/
|
||||||
|
private void showTransactions(List<Transaction> transactions) {
|
||||||
|
transactionListView.getItems().setAll(transactions);
|
||||||
|
updateAccountInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirmation of transaction delete
|
||||||
|
*
|
||||||
|
* @param transaction transaction to be deleted
|
||||||
|
* @return confirmation
|
||||||
|
*/
|
||||||
|
private boolean showDeleteConfirmation(Transaction transaction) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Transaktion löschen");
|
||||||
|
alert.setHeaderText("Soll die Transaktion wirklich gelöscht werden?");
|
||||||
|
alert.setContentText("Transaktion:\n" + transaction.toString() + "\n\nDiese Aktion kann nicht rückgängig gemacht werden.");
|
||||||
|
|
||||||
|
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
||||||
|
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
||||||
|
|
||||||
|
alert.getButtonTypes().setAll(yesButton, noButton);
|
||||||
|
|
||||||
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
return result.isPresent() && result.get() == yesButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates user inputs for adding transaction
|
||||||
|
*
|
||||||
|
* @param typeComboBox
|
||||||
|
* @param amountField
|
||||||
|
* @param descriptionField
|
||||||
|
* @param senderReceiverField
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean validateTransactionInput(ComboBox<String> typeComboBox, TextField amountField, TextField descriptionField, TextField senderField, TextField recieverField) {
|
||||||
|
String type = typeComboBox.getValue();
|
||||||
|
String amountStr = amountField.getText().trim();
|
||||||
|
String desc = descriptionField.getText().trim();
|
||||||
|
|
||||||
|
// Basis-Checks
|
||||||
|
if (desc.isEmpty())
|
||||||
|
return false;
|
||||||
|
try {
|
||||||
|
double amount = Double.parseDouble(amountStr);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("Überweisung")) {
|
||||||
|
String sender = senderField.getText().trim();
|
||||||
|
String reciever = recieverField.getText().trim();
|
||||||
|
|
||||||
|
return (sender.equals(currentAccount) || reciever.equals(currentAccount)) &&
|
||||||
|
!sender.equals(reciever) &&
|
||||||
|
!sender.isEmpty() && !reciever.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<Transaction> showNewTransactionDialog() {
|
||||||
|
Dialog<Transaction> dialog = new Dialog<>();
|
||||||
|
dialog.setTitle("Neue Transaktion");
|
||||||
|
dialog.setHeaderText("Bitte geben Sie die Daten der neuen Transaktion ein.");
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
ButtonType okButton = new ButtonType("Hinzufügen", ButtonBar.ButtonData.OK_DONE);
|
||||||
|
ButtonType cancelButton = new ButtonType("Abbrechen", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||||
|
dialog.getDialogPane().getButtonTypes().addAll(okButton, cancelButton);
|
||||||
|
|
||||||
|
// UI-Elemente
|
||||||
|
Label dateLabel = new Label("Datum:");
|
||||||
|
TextField dateField = new TextField();
|
||||||
|
|
||||||
|
Label typeLabel = new Label("Typ:");
|
||||||
|
ComboBox<String> typeComboBox = new ComboBox<>();
|
||||||
|
typeComboBox.getItems().addAll("Ein-/Auszahlung", "Überweisung");
|
||||||
|
typeComboBox.getSelectionModel().selectFirst(); // Default Payment
|
||||||
|
|
||||||
|
Label amountLabel = new Label("Betrag:");
|
||||||
|
TextField amountField = new TextField();
|
||||||
|
|
||||||
|
Label descriptionLabel = new Label("Beschreibung:");
|
||||||
|
TextField descriptionField = new TextField();
|
||||||
|
|
||||||
|
Label senderLabel = new Label("Sender:");
|
||||||
|
TextField senderField = new TextField();
|
||||||
|
Label recieverLabel = new Label("Empfänger:");
|
||||||
|
TextField recieverField = new TextField();
|
||||||
|
|
||||||
|
// Layout
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
grid.add(typeLabel, 0, 0);
|
||||||
|
grid.add(typeComboBox, 1, 0);
|
||||||
|
|
||||||
|
grid.add(dateLabel, 0, 1);
|
||||||
|
grid.add(dateField, 1, 1);
|
||||||
|
|
||||||
|
grid.add(amountLabel, 0, 2);
|
||||||
|
grid.add(amountField, 1, 2);
|
||||||
|
|
||||||
|
grid.add(descriptionLabel, 0, 3);
|
||||||
|
grid.add(descriptionField, 1, 3);
|
||||||
|
|
||||||
|
grid.add(senderLabel, 0, 4);
|
||||||
|
grid.add(senderField, 1, 4);
|
||||||
|
|
||||||
|
grid.add(recieverLabel, 0, 5);
|
||||||
|
grid.add(recieverField, 1, 5);
|
||||||
|
|
||||||
|
dialog.getDialogPane().setContent(grid);
|
||||||
|
|
||||||
|
// OK-Button Validation
|
||||||
|
Node okBtnNode = dialog.getDialogPane().lookupButton(okButton);
|
||||||
|
okBtnNode.addEventFilter(ActionEvent.ACTION, event -> {
|
||||||
|
// Validierung
|
||||||
|
if (!validateTransactionInput(typeComboBox, amountField, descriptionField, senderField, recieverField)) {
|
||||||
|
event.consume(); // Verhindere schließen des Dialogs
|
||||||
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
|
alert.setTitle("Ungültige Eingabe");
|
||||||
|
alert.setHeaderText("Bitte alle Felder korrekt ausfüllen.");
|
||||||
|
alert.setContentText("- der Betrag muss eine Zahl sein \n- die Beschreibung darf nicht leer sein.\n " +
|
||||||
|
"- bei einer Überweisung dürfen Sender & Empfänger nicht leer und nicht gleich sein");
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.setResultConverter(dialogButton -> {
|
||||||
|
if (dialogButton == okButton) {
|
||||||
|
try {
|
||||||
|
String type = typeComboBox.getValue();
|
||||||
|
double amount = Double.parseDouble(amountField.getText());
|
||||||
|
String description = descriptionField.getText().trim();
|
||||||
|
String date = dateField.getText().trim();
|
||||||
|
if (dateField.getText().trim().isEmpty())
|
||||||
|
date = LocalDate.now().toString();
|
||||||
|
|
||||||
|
if (type.equals("Ein-/Auszahlung")) {
|
||||||
|
return new bank.Payment(date, amount, description);
|
||||||
|
} else {
|
||||||
|
String recieverAccount = recieverField.getText().trim();
|
||||||
|
String senderAccount = senderField.getText().trim();
|
||||||
|
|
||||||
|
if (recieverAccount.isEmpty() && senderAccount.isEmpty() || recieverAccount.equals(senderAccount))
|
||||||
|
return null;
|
||||||
|
else if (senderAccount.equals(currentAccount))
|
||||||
|
return new bank.OutgoingTransfer(date, amount, description, currentAccount, recieverAccount);
|
||||||
|
else if (recieverAccount.equals(currentAccount))
|
||||||
|
return new bank.IncomingTransfer(date, amount, description, recieverAccount, currentAccount);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Sollte nie hier landen, da oben schon abgefangen, aber falls doch:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return dialog.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onNewTransactionClicked() {
|
||||||
|
Optional<Transaction> transactionOpt = showNewTransactionDialog();
|
||||||
|
if (transactionOpt.isPresent()) {
|
||||||
|
Transaction transaction = transactionOpt.get();
|
||||||
|
try {
|
||||||
|
privateBank.addTransaction(currentAccount, transaction);
|
||||||
|
loadTransactions(); // Liste neu laden, um neue Transaktion anzuzeigen
|
||||||
|
updateAccountInfo(); // Kontostand aktualisieren
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Fehler beim Hinzufügen anzeigen
|
||||||
|
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
errorAlert.setTitle("Fehler");
|
||||||
|
errorAlert.setHeaderText("Transaktion konnte nicht hinzugefügt werden.");
|
||||||
|
errorAlert.setContentText("Überprüfen Sie Ihre Eingaben oder versuchen Sie es später erneut.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
180
src/main/java/ui/MainviewController.java
Normal file
180
src/main/java/ui/MainviewController.java
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import bank.PrivateBank;
|
||||||
|
|
||||||
|
import bank.exceptions.AccountAlreadyExistsException;
|
||||||
|
import bank.exceptions.IOException;
|
||||||
|
|
||||||
|
import javafx.fxml.*;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.input.MouseButton;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
public class MainviewController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<String> accountListView;
|
||||||
|
|
||||||
|
private PrivateBank privateBank; // Referenz auf Ihr Bankobjekt
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void initialize() {
|
||||||
|
// Bank initialisieren
|
||||||
|
this.privateBank = main.getPrivateBank();
|
||||||
|
|
||||||
|
// Zeige alle vorhandenen Konten an
|
||||||
|
accountListView.getItems().addAll(privateBank.getAllAccounts());
|
||||||
|
|
||||||
|
// Kontextmenü definieren
|
||||||
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
|
||||||
|
// Kontextmenü-Items definieren
|
||||||
|
MenuItem selectItem = new MenuItem("Auswählen");
|
||||||
|
MenuItem deleteItem = new MenuItem("Löschen");
|
||||||
|
|
||||||
|
// Kontextmenü-Item Aktion: Konto auswählen
|
||||||
|
selectItem.setOnAction(
|
||||||
|
event -> {
|
||||||
|
String selectedAccount = accountListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedAccount != null)
|
||||||
|
switchToAccountView(selectedAccount);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Kontextmenü-Item Aktion: Konto löschen
|
||||||
|
deleteItem.setOnAction(
|
||||||
|
event -> {
|
||||||
|
String selectedAccount = accountListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedAccount != null) {
|
||||||
|
boolean confirmed = showDeleteConfirmation(selectedAccount);
|
||||||
|
if (confirmed) {
|
||||||
|
// Account löschen
|
||||||
|
try {
|
||||||
|
privateBank.deleteAccount(selectedAccount);
|
||||||
|
// ListView aktualisieren
|
||||||
|
accountListView.getItems().remove(selectedAccount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Kontextmenü-Items dem Kontextmenü hinzufügen
|
||||||
|
contextMenu.getItems().addAll(selectItem, deleteItem);
|
||||||
|
|
||||||
|
// Kontextmenü an die ListView binden
|
||||||
|
accountListView.setContextMenu(contextMenu);
|
||||||
|
|
||||||
|
// Optional: Double-Click zum Auswählen ohne Kontextmenü
|
||||||
|
accountListView.setOnMouseClicked(
|
||||||
|
event -> {
|
||||||
|
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
||||||
|
String selectedAccount = accountListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedAccount != null) {
|
||||||
|
switchToAccountView(selectedAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param accountName
|
||||||
|
*/
|
||||||
|
private void switchToAccountView(String accountName) {
|
||||||
|
try {
|
||||||
|
// Laden der zweiten FXML
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Accountview.fxml"));
|
||||||
|
Parent root = loader.load();
|
||||||
|
|
||||||
|
// Zugriff auf Controller und Datenübergabe
|
||||||
|
AccountviewController accountController = loader.getController();
|
||||||
|
accountController.setAccount(accountName, privateBank);
|
||||||
|
|
||||||
|
// Scene in derselben Stage wechseln
|
||||||
|
Stage stage = (Stage) accountListView.getScene().getWindow();
|
||||||
|
stage.getScene().setRoot(root);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param accountName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean showDeleteConfirmation(String accountName) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Account löschen");
|
||||||
|
alert.setHeaderText("Soll der Account '" + accountName + "' wirklich gelöscht werden?");
|
||||||
|
alert.setContentText("Diese Aktion kann nicht rückgängig gemacht werden.");
|
||||||
|
|
||||||
|
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
||||||
|
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
||||||
|
|
||||||
|
alert.getButtonTypes().setAll(yesButton, noButton);
|
||||||
|
|
||||||
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
|
||||||
|
return result.isPresent() && result.get() == yesButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onNewAccountClicked() {
|
||||||
|
// Dialog zum Eingeben eines neuen Account-Namens
|
||||||
|
TextInputDialog dialog = new TextInputDialog();
|
||||||
|
dialog.setTitle("Neuen Account erstellen");
|
||||||
|
dialog.setHeaderText("Bitte geben Sie den Namen des neuen Accounts ein:");
|
||||||
|
dialog.setContentText("Account-Name:");
|
||||||
|
|
||||||
|
Optional<String> result = dialog.showAndWait();
|
||||||
|
if (result.isPresent()) {
|
||||||
|
String newAccountName = result.get().trim();
|
||||||
|
if (!newAccountName.isEmpty()) {
|
||||||
|
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
errorAlert.setTitle("Fehler");
|
||||||
|
try {
|
||||||
|
// Account erstellen
|
||||||
|
privateBank.createAccount(newAccountName);
|
||||||
|
privateBank.writeAccount(newAccountName);
|
||||||
|
|
||||||
|
// neuen Account der Listview hinzufügen
|
||||||
|
if (!accountListView.getItems().contains(newAccountName))
|
||||||
|
accountListView.getItems().add(newAccountName);
|
||||||
|
|
||||||
|
} catch (AccountAlreadyExistsException e) {
|
||||||
|
errorAlert.setHeaderText("Account existiert bereits");
|
||||||
|
errorAlert.setContentText("Der Account \"" + newAccountName + "\" wurde bereits angelegt.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (IOException e) {
|
||||||
|
errorAlert.setHeaderText("Account JSON Fehler");
|
||||||
|
errorAlert.setContentText("Die JSON des Accounts \"" + newAccountName + "\" konnte nicht bearbeitet werden.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
errorAlert.setHeaderText("Account konnte nicht erstellt werden.");
|
||||||
|
errorAlert.setContentText("Überprüfen Sie, ob der Name bereits existiert oder ein anderer Fehler vorliegt.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Leeren Namen nicht akzeptieren
|
||||||
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
|
alert.setTitle("Warnung");
|
||||||
|
alert.setHeaderText("Ungültiger Account-Name");
|
||||||
|
alert.setContentText("Bitte geben Sie einen gültigen Namen ein.");
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
48
src/main/java/ui/main.java
Normal file
48
src/main/java/ui/main.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import bank.PrivateBank;
|
||||||
|
import bank.exceptions.AccountAlreadyExistsException;
|
||||||
|
import bank.exceptions.IOException;
|
||||||
|
import bank.exceptions.TransactionAlreadyExistException;
|
||||||
|
import bank.exceptions.TransactionAttributeException;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class main extends Application {
|
||||||
|
/**
|
||||||
|
* Starting point
|
||||||
|
*
|
||||||
|
* @param primaryStage
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Mainview.fxml"));
|
||||||
|
Scene scene = new Scene(loader.load());
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrivateBank privateBank = new PrivateBank(
|
||||||
|
"Bank1",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"accountdata");
|
||||||
|
|
||||||
|
public static PrivateBank getPrivateBank() {
|
||||||
|
try {
|
||||||
|
privateBank.readAccounts();
|
||||||
|
} catch (IOException | AccountAlreadyExistsException | TransactionAlreadyExistException |
|
||||||
|
TransactionAttributeException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
return privateBank;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
src/main/resources/Accountview.fxml
Normal file
39
src/main/resources/Accountview.fxml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<BorderPane fx:id="root" xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="ui.AccountviewController">
|
||||||
|
|
||||||
|
<top>
|
||||||
|
<HBox spacing="10" alignment="CENTER_LEFT">
|
||||||
|
<!-- Back Button -->
|
||||||
|
<Button text="Back" fx:id="backButton" onAction="#onBackButtonClicked"/>
|
||||||
|
|
||||||
|
<Button text="Neue Transaktion" onAction="#onNewTransactionClicked"/>
|
||||||
|
|
||||||
|
<!-- Account Name Label -->
|
||||||
|
<Label fx:id="accountNameLabel" text="Account: "/>
|
||||||
|
|
||||||
|
<!-- Balance Label -->
|
||||||
|
<Label fx:id="balanceLabel" text="Balance: "/>
|
||||||
|
</HBox>
|
||||||
|
</top>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<!-- List of Accounts Transactions -->
|
||||||
|
<ListView fx:id="transactionListView" />
|
||||||
|
</center>
|
||||||
|
|
||||||
|
<bottom>
|
||||||
|
<HBox spacing="10" alignment="CENTER">
|
||||||
|
<!-- Buttons for Sorting -->
|
||||||
|
<Button text="Aufsteigend sortieren" onAction="#onSortAscending"/>
|
||||||
|
<Button text="Absteigend sortieren" onAction="#onSortDescending"/>
|
||||||
|
<Button text="Nur positive" onAction="#onShowPositive"/>
|
||||||
|
<Button text="Nur negative" onAction="#onShowNegative"/>
|
||||||
|
<Button text="Alle anzeigen" onAction="#onShowAll"/>
|
||||||
|
</HBox>
|
||||||
|
</bottom>
|
||||||
|
</BorderPane>
|
||||||
21
src/main/resources/Mainview.fxml
Normal file
21
src/main/resources/Mainview.fxml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<BorderPane fx:id="root" xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="ui.MainviewController">
|
||||||
|
<top>
|
||||||
|
<MenuBar>
|
||||||
|
<Menu text="Datei">
|
||||||
|
<MenuItem text="Neu" onAction="#onNewAccountClicked"/>
|
||||||
|
</Menu>
|
||||||
|
</MenuBar>
|
||||||
|
</top>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<ListView fx:id="accountListView"/>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ public class PrivateBankTest {
|
|||||||
@Test
|
@Test
|
||||||
@Order(16)
|
@Order(16)
|
||||||
public void getTransactionsByTypeTest() {
|
public void getTransactionsByTypeTest() {
|
||||||
List<Transaction> transactionList = List.of(
|
List<Transaction> transactionsPositive = List.of(
|
||||||
new IncomingTransfer(
|
new IncomingTransfer(
|
||||||
"01.01.2000",
|
"01.01.2000",
|
||||||
300,
|
300,
|
||||||
@@ -365,14 +365,30 @@ public class PrivateBankTest {
|
|||||||
"Konto_1"
|
"Konto_1"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
List<Transaction> transactionsNegative = List.of(
|
||||||
|
new Payment(
|
||||||
|
"01.01.2000",
|
||||||
|
-100,
|
||||||
|
"Payment",
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
transactionList,
|
transactionsPositive,
|
||||||
privateBank.getTransactionsByType(
|
privateBank.getTransactionsByType(
|
||||||
"Konto_1",
|
"Konto_1",
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
System.out.println("getTransactionByTypeTest in <Konto_1> is correct.");
|
assertEquals(
|
||||||
|
transactionsNegative,
|
||||||
|
privateBank.getTransactionsByType(
|
||||||
|
"Konto_1",
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -408,9 +424,39 @@ public class PrivateBankTest {
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
List.of(
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
300,
|
||||||
|
"IncomingTransfer from Tom",
|
||||||
|
"Tom",
|
||||||
|
"Konto_6"
|
||||||
|
),
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"IncomingTransfer from Hans",
|
||||||
|
"Hans",
|
||||||
|
"Konto_6"
|
||||||
|
),
|
||||||
|
new OutgoingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"OutgoingTransfer to Hans",
|
||||||
|
"Konto_6",
|
||||||
|
"Hans"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
privateBank.getTransactionsSorted(
|
||||||
|
"Konto_6",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Serialize Accounts")
|
@DisplayName("Serialize existing Accounts")
|
||||||
@Order(18)
|
@Order(18)
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||||
@@ -421,12 +467,87 @@ public class PrivateBankTest {
|
|||||||
System.out.println("SerializeAccountsTest in <" + account + "> is correct.");
|
System.out.println("SerializeAccountsTest in <" + account + "> is correct.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Deserialize Accounts")
|
@DisplayName("Deserialize existing Accounts")
|
||||||
@Order(19)
|
@Order(19)
|
||||||
@Test
|
@Test
|
||||||
public void DeserializeAccountsTest() {
|
public void DeserializeAccountsTest() {
|
||||||
|
// Die eingelesenen Konten sind bereits vorhanden
|
||||||
assertThrows(
|
assertThrows(
|
||||||
AccountAlreadyExistsException.class, () -> privateBank.readAccounts()
|
AccountAlreadyExistsException.class, () -> privateBank.readAccounts()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Delete existing account")
|
||||||
|
@Order(20)
|
||||||
|
@Test
|
||||||
|
public void testDeleteExistingAccount() {
|
||||||
|
assertDoesNotThrow(
|
||||||
|
() -> privateBank.createAccount(
|
||||||
|
"Konto_X",
|
||||||
|
List.of(
|
||||||
|
new OutgoingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"OutgoingTransfer to Hans",
|
||||||
|
"Konto_X",
|
||||||
|
"Hans"
|
||||||
|
),
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"IncomingTransfer from Hans",
|
||||||
|
"Hans",
|
||||||
|
"Konto_X"
|
||||||
|
),
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
300,
|
||||||
|
"IncomingTransfer from Tom",
|
||||||
|
"Tom",
|
||||||
|
"Konto_X"
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertDoesNotThrow(
|
||||||
|
() -> privateBank.writeAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
() -> privateBank.containsAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertDoesNotThrow(
|
||||||
|
() -> privateBank.deleteAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertFalse(
|
||||||
|
() -> privateBank.containsAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Delete non existing account")
|
||||||
|
@Order(21)
|
||||||
|
@Test
|
||||||
|
public void testDeleteNonExistingAccount() {
|
||||||
|
assertThrows(
|
||||||
|
AccountDoesNotExistException.class, () -> privateBank.deleteAccount("Konto_X")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Get all accounts")
|
||||||
|
@Order(22)
|
||||||
|
@Test
|
||||||
|
public void testGetAllAccounts() {
|
||||||
|
List<String> expectedAccounts = List.of(
|
||||||
|
"Konto_1", "Konto_3", "Konto_2", "Konto_5", "Konto_4", "Konto_7", "Konto_6", "Konto_8"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
expectedAccounts,
|
||||||
|
privateBank.getAllAccounts()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user