From d8fb768b3d08da5be16d58c241ab0ed5a28dbbf9 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 18:00:39 +0100 Subject: [PATCH] test_Error message for mismatched passwords --- src/test/java/SignUpGUITest.java | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/test/java/SignUpGUITest.java b/src/test/java/SignUpGUITest.java index c13bc02..146ba81 100644 --- a/src/test/java/SignUpGUITest.java +++ b/src/test/java/SignUpGUITest.java @@ -3,9 +3,15 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; - +import java.awt.Component; import java.awt.event.ActionEvent; +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class SignUpGUITest { @@ -37,7 +43,34 @@ import java.awt.event.ActionEvent; signUpGUI.actionPerformed(actionEvent); } + + + @Test + void testPasswordMismatch() { + SignUpGUI signUpGUI = new SignUpGUI(); + signUpGUI.getUsernameField().setText("testuser"); + signUpGUI.getPasswordField().setText("password"); + signUpGUI.getConfirmPasswordField().setText("differentpassword"); + signUpGUI.getBirthdayField().setText("1990-01-01"); + signUpGUI.getFirstNameField().setText("John"); + signUpGUI.getSurnameField().setText("Doe"); + + signUpGUI.getSignUpButton().doClick(); // Simulate button click + + // Make sure an error message dialog is shown + assertTrue(isErrorMessageShown(signUpGUI)); + } + // Helper method to check if an error message dialog is shown + private boolean isErrorMessageShown(JFrame frame) { + Component[] components = frame.getComponents(); + for (Component component : components) { + if (component instanceof JOptionPane) { + return false; + } + } + return true; + } }