|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
} |