Erweiterung der Tests
Anpassungen beim Hinzufügen von Transaktionen
This commit is contained in:
@@ -147,9 +147,15 @@ public class AccountviewController {
|
|||||||
*/
|
*/
|
||||||
private void showTransactions(List<Transaction> transactions) {
|
private void showTransactions(List<Transaction> transactions) {
|
||||||
transactionListView.getItems().setAll(transactions);
|
transactionListView.getItems().setAll(transactions);
|
||||||
updateAccountInfo(); // Balance neu anzeigen, falls sich was geändert hat
|
updateAccountInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirmation of transaction delete
|
||||||
|
*
|
||||||
|
* @param transaction transaction to be deleted
|
||||||
|
* @return confirmation
|
||||||
|
*/
|
||||||
private boolean showDeleteConfirmation(Transaction transaction) {
|
private boolean showDeleteConfirmation(Transaction transaction) {
|
||||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
alert.setTitle("Transaktion löschen");
|
alert.setTitle("Transaktion löschen");
|
||||||
@@ -165,7 +171,16 @@ public class AccountviewController {
|
|||||||
return result.isPresent() && result.get() == yesButton;
|
return result.isPresent() && result.get() == yesButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateTransactionInput(ComboBox<String> typeComboBox, TextField amountField, TextField descriptionField, TextField senderReceiverField) {
|
/**
|
||||||
|
* 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 type = typeComboBox.getValue();
|
||||||
String amountStr = amountField.getText().trim();
|
String amountStr = amountField.getText().trim();
|
||||||
String desc = descriptionField.getText().trim();
|
String desc = descriptionField.getText().trim();
|
||||||
@@ -179,9 +194,13 @@ public class AccountviewController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.equals("Transfer")) {
|
if (type.equals("Überweisung")) {
|
||||||
String partner = senderReceiverField.getText().trim();
|
String sender = senderField.getText().trim();
|
||||||
if (partner.isEmpty()) return false;
|
String reciever = recieverField.getText().trim();
|
||||||
|
|
||||||
|
return (sender.equals(currentAccount) || reciever.equals(currentAccount)) &&
|
||||||
|
!sender.equals(reciever) &&
|
||||||
|
!sender.isEmpty() && !reciever.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -193,14 +212,17 @@ public class AccountviewController {
|
|||||||
dialog.setHeaderText("Bitte geben Sie die Daten der neuen Transaktion ein.");
|
dialog.setHeaderText("Bitte geben Sie die Daten der neuen Transaktion ein.");
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
ButtonType okButton = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
|
ButtonType okButton = new ButtonType("Hinzufügen", ButtonBar.ButtonData.OK_DONE);
|
||||||
ButtonType cancelButton = new ButtonType("Abbrechen", ButtonBar.ButtonData.CANCEL_CLOSE);
|
ButtonType cancelButton = new ButtonType("Abbrechen", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||||
dialog.getDialogPane().getButtonTypes().addAll(okButton, cancelButton);
|
dialog.getDialogPane().getButtonTypes().addAll(okButton, cancelButton);
|
||||||
|
|
||||||
// UI-Elemente
|
// UI-Elemente
|
||||||
|
Label dateLabel = new Label("Datum:");
|
||||||
|
TextField dateField = new TextField();
|
||||||
|
|
||||||
Label typeLabel = new Label("Typ:");
|
Label typeLabel = new Label("Typ:");
|
||||||
ComboBox<String> typeComboBox = new ComboBox<>();
|
ComboBox<String> typeComboBox = new ComboBox<>();
|
||||||
typeComboBox.getItems().addAll("Payment", "Transfer");
|
typeComboBox.getItems().addAll("Ein-/Auszahlung", "Überweisung");
|
||||||
typeComboBox.getSelectionModel().selectFirst(); // Default Payment
|
typeComboBox.getSelectionModel().selectFirst(); // Default Payment
|
||||||
|
|
||||||
Label amountLabel = new Label("Betrag:");
|
Label amountLabel = new Label("Betrag:");
|
||||||
@@ -209,8 +231,10 @@ public class AccountviewController {
|
|||||||
Label descriptionLabel = new Label("Beschreibung:");
|
Label descriptionLabel = new Label("Beschreibung:");
|
||||||
TextField descriptionField = new TextField();
|
TextField descriptionField = new TextField();
|
||||||
|
|
||||||
Label senderReceiverLabel = new Label("Partner-Konto (nur bei Transfer):");
|
Label senderLabel = new Label("Sender:");
|
||||||
TextField senderReceiverField = new TextField();
|
TextField senderField = new TextField();
|
||||||
|
Label recieverLabel = new Label("Empfänger:");
|
||||||
|
TextField recieverField = new TextField();
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
GridPane grid = new GridPane();
|
GridPane grid = new GridPane();
|
||||||
@@ -220,14 +244,20 @@ public class AccountviewController {
|
|||||||
grid.add(typeLabel, 0, 0);
|
grid.add(typeLabel, 0, 0);
|
||||||
grid.add(typeComboBox, 1, 0);
|
grid.add(typeComboBox, 1, 0);
|
||||||
|
|
||||||
grid.add(amountLabel, 0, 1);
|
grid.add(dateLabel, 0, 1);
|
||||||
grid.add(amountField, 1, 1);
|
grid.add(dateField, 1, 1);
|
||||||
|
|
||||||
grid.add(descriptionLabel, 0, 2);
|
grid.add(amountLabel, 0, 2);
|
||||||
grid.add(descriptionField, 1, 2);
|
grid.add(amountField, 1, 2);
|
||||||
|
|
||||||
grid.add(senderReceiverLabel, 0, 3);
|
grid.add(descriptionLabel, 0, 3);
|
||||||
grid.add(senderReceiverField, 1, 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);
|
dialog.getDialogPane().setContent(grid);
|
||||||
|
|
||||||
@@ -235,13 +265,13 @@ public class AccountviewController {
|
|||||||
Node okBtnNode = dialog.getDialogPane().lookupButton(okButton);
|
Node okBtnNode = dialog.getDialogPane().lookupButton(okButton);
|
||||||
okBtnNode.addEventFilter(ActionEvent.ACTION, event -> {
|
okBtnNode.addEventFilter(ActionEvent.ACTION, event -> {
|
||||||
// Validierung
|
// Validierung
|
||||||
if (!validateTransactionInput(typeComboBox, amountField, descriptionField, senderReceiverField)) {
|
if (!validateTransactionInput(typeComboBox, amountField, descriptionField, senderField, recieverField)) {
|
||||||
event.consume(); // Verhindere schließen des Dialogs
|
event.consume(); // Verhindere schließen des Dialogs
|
||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
alert.setTitle("Ungültige Eingabe");
|
alert.setTitle("Ungültige Eingabe");
|
||||||
alert.setHeaderText("Bitte alle Felder korrekt ausfüllen.");
|
alert.setHeaderText("Bitte alle Felder korrekt ausfüllen.");
|
||||||
alert.setContentText("Betrag muss eine Zahl sein, Beschreibung darf nicht leer sein.\n" +
|
alert.setContentText("- der Betrag muss eine Zahl sein \n- die Beschreibung darf nicht leer sein.\n " +
|
||||||
"Für Transfer muss ein gültiges Partner-Konto angegeben werden.");
|
"- bei einer Überweisung dürfen Sender & Empfänger nicht leer und nicht gleich sein");
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -252,23 +282,23 @@ public class AccountviewController {
|
|||||||
String type = typeComboBox.getValue();
|
String type = typeComboBox.getValue();
|
||||||
double amount = Double.parseDouble(amountField.getText());
|
double amount = Double.parseDouble(amountField.getText());
|
||||||
String description = descriptionField.getText().trim();
|
String description = descriptionField.getText().trim();
|
||||||
String date = LocalDate.now().toString();
|
String date = dateField.getText().trim();
|
||||||
|
if (dateField.getText().trim().isEmpty())
|
||||||
|
date = LocalDate.now().toString();
|
||||||
|
|
||||||
if (type.equals("Payment")) {
|
if (type.equals("Ein-/Auszahlung")) {
|
||||||
return new bank.Payment(date, amount, description);
|
return new bank.Payment(date, amount, description);
|
||||||
} else {
|
} else {
|
||||||
String partnerAccount = senderReceiverField.getText().trim();
|
String recieverAccount = recieverField.getText().trim();
|
||||||
if (partnerAccount.isEmpty()) return null;
|
String senderAccount = senderField.getText().trim();
|
||||||
|
|
||||||
if (!partnerAccount.equals(currentAccount)) {
|
if (recieverAccount.isEmpty() && senderAccount.isEmpty() || recieverAccount.equals(senderAccount))
|
||||||
// OutgoingTransfer: currentAccount -> partnerAccount
|
return null;
|
||||||
return new bank.OutgoingTransfer(date, amount, description, currentAccount, partnerAccount);
|
else if (senderAccount.equals(currentAccount))
|
||||||
} else {
|
return new bank.OutgoingTransfer(date, amount, description, currentAccount, recieverAccount);
|
||||||
// IncomingTransfer: partnerAccount -> currentAccount
|
else if (recieverAccount.equals(currentAccount))
|
||||||
return new bank.IncomingTransfer(date, amount, description, partnerAccount, currentAccount);
|
return new bank.IncomingTransfer(date, amount, description, recieverAccount, currentAccount);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// Sollte nie hier landen, da oben schon abgefangen, aber falls doch:
|
// Sollte nie hier landen, da oben schon abgefangen, aber falls doch:
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ import bank.PrivateBank;
|
|||||||
|
|
||||||
import bank.exceptions.AccountAlreadyExistsException;
|
import bank.exceptions.AccountAlreadyExistsException;
|
||||||
import bank.exceptions.IOException;
|
import bank.exceptions.IOException;
|
||||||
|
|
||||||
import javafx.fxml.*;
|
import javafx.fxml.*;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.input.MouseButton;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package ui;
|
package ui;
|
||||||
|
|
||||||
import bank.PrivateBank;
|
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.application.Application;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@@ -9,6 +13,7 @@ import javafx.stage.Stage;
|
|||||||
public class main extends Application {
|
public class main extends Application {
|
||||||
/**
|
/**
|
||||||
* Starting point
|
* Starting point
|
||||||
|
*
|
||||||
* @param primaryStage
|
* @param primaryStage
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -24,9 +29,19 @@ public class main extends Application {
|
|||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PrivateBank privateBank = new PrivateBank("Bank1", 0, 0, "accountdata");
|
private static PrivateBank privateBank = new PrivateBank(
|
||||||
|
"Bank1",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"accountdata");
|
||||||
|
|
||||||
public static PrivateBank getPrivateBank() {
|
public static PrivateBank getPrivateBank() {
|
||||||
|
try {
|
||||||
|
privateBank.readAccounts();
|
||||||
|
} catch (IOException | AccountAlreadyExistsException | TransactionAlreadyExistException |
|
||||||
|
TransactionAttributeException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
return privateBank;
|
return privateBank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,16 +467,16 @@ 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")
|
@DisplayName("Delete existing account")
|
||||||
@Order(20)
|
@Order(20)
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user