From a3bbb2dd809e7244af07a1e2001cee741bc2f805 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 12:25:10 +0100 Subject: [PATCH] test_Login button in LoginGUI --- src/main/java/LoginGUI.java | 21 +++++++++++++++++++++ src/test/java/LoginGUITest.java | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/test/java/LoginGUITest.java diff --git a/src/main/java/LoginGUI.java b/src/main/java/LoginGUI.java index 6a442b7..6d49398 100644 --- a/src/main/java/LoginGUI.java +++ b/src/main/java/LoginGUI.java @@ -14,7 +14,28 @@ public class LoginGUI extends JFrame implements ActionListener { private JButton loginButton; private JCheckBox stayLoggedInCheckbox; private JButton signUpButton; + + public JTextField getUsernameField() { + return usernameField; + } + + public JPasswordField getPasswordField() { + return passwordField; + } + + public JButton getLoginButton() { + return loginButton; + } + public JCheckBox getStayLoggedInCheckbox() { + return stayLoggedInCheckbox; + } + + public JButton getSignUpButton() { + return signUpButton; + } + + public LoginGUI() { setTitle("Login"); setSize(300, 220); diff --git a/src/test/java/LoginGUITest.java b/src/test/java/LoginGUITest.java new file mode 100644 index 0000000..ca931d2 --- /dev/null +++ b/src/test/java/LoginGUITest.java @@ -0,0 +1,21 @@ +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import java.awt.event.ActionEvent; + +class LoginGUITest { + + @Test + public void testActionPerformed_LoginButton() { + LoginGUI loginGUI = new LoginGUI(); + loginGUI.getUsernameField().setText("testUser"); + loginGUI.getPasswordField().setText("testPassword"); + loginGUI.getStayLoggedInCheckbox().setSelected(true); + + // Simulate action performed event on login button + loginGUI.actionPerformed(new ActionEvent(loginGUI.getLoginButton(), ActionEvent.ACTION_PERFORMED, null)); + + // Verify if login was successful + assertFalse(loginGUI.isVisible()); + } + +}