Browse Source

test_Login button in LoginGUI

remotes/origin/server
Richard Schmidt 11 months ago
parent
commit
a3bbb2dd80
  1. 21
      src/main/java/LoginGUI.java
  2. 21
      src/test/java/LoginGUITest.java

21
src/main/java/LoginGUI.java

@ -14,7 +14,28 @@ public class LoginGUI extends JFrame implements ActionListener {
private JButton loginButton; private JButton loginButton;
private JCheckBox stayLoggedInCheckbox; private JCheckBox stayLoggedInCheckbox;
private JButton signUpButton; 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() { public LoginGUI() {
setTitle("Login"); setTitle("Login");
setSize(300, 220); setSize(300, 220);

21
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());
}
}
Loading…
Cancel
Save