|
@ -1,4 +1,3 @@ |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
@ -6,31 +5,29 @@ import org.junit.jupiter.api.BeforeEach; |
|
|
import java.awt.Component; |
|
|
import java.awt.Component; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
import javax.swing.*; |
|
|
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; |
|
|
import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SignUpGUITest { |
|
|
class SignUpGUITest { |
|
|
private SignUpGUI signUpGUI; |
|
|
private SignUpGUI signUpGUI; |
|
|
|
|
|
|
|
|
|
|
|
//Instantiates a new instance of SignUpGUI |
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setUp() { |
|
|
void setUp() { |
|
|
signUpGUI = new SignUpGUI(); |
|
|
signUpGUI = new SignUpGUI(); |
|
|
signUpGUI.setVisible(true); |
|
|
signUpGUI.setVisible(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Disposes of the instance |
|
|
@AfterEach |
|
|
@AfterEach |
|
|
void tearDown() { |
|
|
void tearDown() { |
|
|
signUpGUI.dispose(); |
|
|
signUpGUI.dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Tests text field and button inputs |
|
|
@Test |
|
|
@Test |
|
|
public void testSignUpButtonActionPerformed() { |
|
|
public void testSignUpButtonActionPerformed() { |
|
|
// Set up text fields |
|
|
|
|
|
signUpGUI.getUsernameField().setText("testUser"); |
|
|
signUpGUI.getUsernameField().setText("testUser"); |
|
|
signUpGUI.getPasswordField().setText("password"); |
|
|
signUpGUI.getPasswordField().setText("password"); |
|
|
signUpGUI.getConfirmPasswordField().setText("password"); |
|
|
signUpGUI.getConfirmPasswordField().setText("password"); |
|
@ -38,14 +35,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
signUpGUI.getFirstNameField().setText("John"); |
|
|
signUpGUI.getFirstNameField().setText("John"); |
|
|
signUpGUI.getSurnameField().setText("Doe"); |
|
|
signUpGUI.getSurnameField().setText("Doe"); |
|
|
|
|
|
|
|
|
// Perform action |
|
|
|
|
|
ActionEvent actionEvent = new ActionEvent(signUpGUI.getSignUpButton(), ActionEvent.ACTION_PERFORMED, ""); |
|
|
ActionEvent actionEvent = new ActionEvent(signUpGUI.getSignUpButton(), ActionEvent.ACTION_PERFORMED, ""); |
|
|
signUpGUI.actionPerformed(actionEvent); |
|
|
signUpGUI.actionPerformed(actionEvent); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Tests if passwords are mismatched |
|
|
@Test |
|
|
@Test |
|
|
void testPasswordMismatch() { |
|
|
void testPasswordMismatch() { |
|
|
SignUpGUI signUpGUI = new SignUpGUI(); |
|
|
SignUpGUI signUpGUI = new SignUpGUI(); |
|
@ -56,12 +50,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
signUpGUI.getFirstNameField().setText("John"); |
|
|
signUpGUI.getFirstNameField().setText("John"); |
|
|
signUpGUI.getSurnameField().setText("Doe"); |
|
|
signUpGUI.getSurnameField().setText("Doe"); |
|
|
|
|
|
|
|
|
signUpGUI.getSignUpButton().doClick(); // Simulate button click |
|
|
|
|
|
|
|
|
signUpGUI.getSignUpButton().doClick(); |
|
|
|
|
|
|
|
|
// Make sure an error message dialog is shown |
|
|
|
|
|
assertTrue(isErrorMessageShown(signUpGUI)); |
|
|
assertTrue(isErrorMessageShown(signUpGUI)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Tests if user-name already exists |
|
|
@Test |
|
|
@Test |
|
|
void testExistingUsername() { |
|
|
void testExistingUsername() { |
|
|
SignUpGUI signUpGUI = new SignUpGUI(); |
|
|
SignUpGUI signUpGUI = new SignUpGUI(); |
|
@ -72,22 +66,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
signUpGUI.getFirstNameField().setText("John"); |
|
|
signUpGUI.getFirstNameField().setText("John"); |
|
|
signUpGUI.getSurnameField().setText("Doe"); |
|
|
signUpGUI.getSurnameField().setText("Doe"); |
|
|
|
|
|
|
|
|
signUpGUI.getSignUpButton().doClick(); // Simulate button click |
|
|
|
|
|
|
|
|
signUpGUI.getSignUpButton().doClick(); |
|
|
|
|
|
|
|
|
// Make sure an error message dialog is shown |
|
|
|
|
|
assertTrue(isErrorMessageShown(signUpGUI)); |
|
|
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) { |
|
|
private boolean isErrorMessageShown(JFrame frame) { |
|
|
Component[] components = frame.getComponents(); |
|
|
Component[] components = frame.getComponents(); |
|
|
for (Component component : components) { |
|
|
for (Component component : components) { |
|
|
if (component instanceof JOptionPane) { |
|
|
if (component instanceof JOptionPane) { |
|
|
return false; |
|
|
|
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |