From 33a294efef0812d9d870c11f135ecc6db809c94c Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 20:08:17 +0100 Subject: [PATCH] refactoring: added / removed some comments in LoginGUITest and fixed some indentations --- src/test/java/SignUpGUITest.java | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/test/java/SignUpGUITest.java b/src/test/java/SignUpGUITest.java index 9d4dc38..4cb8018 100644 --- a/src/test/java/SignUpGUITest.java +++ b/src/test/java/SignUpGUITest.java @@ -1,4 +1,3 @@ -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -6,31 +5,29 @@ 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.*; import static org.junit.jupiter.api.Assertions.assertTrue; - class SignUpGUITest { private SignUpGUI signUpGUI; + //Instantiates a new instance of SignUpGUI @BeforeEach void setUp() { signUpGUI = new SignUpGUI(); signUpGUI.setVisible(true); } + //Disposes of the instance @AfterEach void tearDown() { signUpGUI.dispose(); } + //Tests text field and button inputs @Test public void testSignUpButtonActionPerformed() { - // Set up text fields signUpGUI.getUsernameField().setText("testUser"); signUpGUI.getPasswordField().setText("password"); signUpGUI.getConfirmPasswordField().setText("password"); @@ -38,14 +35,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue; signUpGUI.getFirstNameField().setText("John"); signUpGUI.getSurnameField().setText("Doe"); - // Perform action ActionEvent actionEvent = new ActionEvent(signUpGUI.getSignUpButton(), ActionEvent.ACTION_PERFORMED, ""); signUpGUI.actionPerformed(actionEvent); - } - - + //Tests if passwords are mismatched @Test void testPasswordMismatch() { SignUpGUI signUpGUI = new SignUpGUI(); @@ -56,12 +50,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; signUpGUI.getFirstNameField().setText("John"); signUpGUI.getSurnameField().setText("Doe"); - signUpGUI.getSignUpButton().doClick(); // Simulate button click + signUpGUI.getSignUpButton().doClick(); - // Make sure an error message dialog is shown assertTrue(isErrorMessageShown(signUpGUI)); } + //Tests if user-name already exists @Test void testExistingUsername() { SignUpGUI signUpGUI = new SignUpGUI(); @@ -72,22 +66,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue; signUpGUI.getFirstNameField().setText("John"); signUpGUI.getSurnameField().setText("Doe"); - signUpGUI.getSignUpButton().doClick(); // Simulate button click + signUpGUI.getSignUpButton().doClick(); - // Make sure an error message dialog is shown assertTrue(isErrorMessageShown(signUpGUI)); } - // Helper method to check if an error message dialog is shown + // 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 false; + } } return true; } - }