Browse Source

test_EmojiPickerActionListenerFunctionality

remotes/origin/client-handler
Valentin Spiroski 11 months ago
parent
commit
08935f3889
  1. 1
      src/main/java/EmojiPicker.java
  2. 32
      src/test/java/TestEmojiPicker.java

1
src/main/java/EmojiPicker.java

@ -52,6 +52,7 @@ public class EmojiPicker extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println("Selected emoji: " + emoji); // Print selected emoji to console System.out.println("Selected emoji: " + emoji); // Print selected emoji to console
System.out.println("textField: " + textField); // Print the value of textField
textField.setText(textField.getText() + emoji); // Append selected emoji to text field textField.setText(textField.getText() + emoji); // Append selected emoji to text field
} }
} }

32
src/test/java/TestEmojiPicker.java

@ -71,23 +71,23 @@ public class TestEmojiPicker {
} }
} }
//Test to verify the functionality of EmojiActionListener for each emoji button
//Test to verify the functionality of EmojiActionListener for each emoji button
@Test @Test
public void testEmojiPickerActionListenerFunctionality() { public void testEmojiPickerActionListenerFunctionality() {
// Arrange
JTextField textField = new JTextField();
EmojiPicker emojiPicker = new EmojiPicker(textField);
Component[] components = emojiPicker.getComponents();
// Act & Assert
for (Component component : components) {
assertTrue(component instanceof JButton);
JButton button = (JButton) component;
EmojiPicker.EmojiActionListener actionListener = (EmojiPicker.EmojiActionListener) button.getActionListeners()[0];
assertNotNull(actionListener);
actionListener.actionPerformed(null);
assertEquals(button.getText(), textField.getText()); // Check if emoji is appended to the text field
}
// Arrange
JTextField textField = new JTextField(); // Initialize JTextField
EmojiPicker emojiPicker = new EmojiPicker(textField); // Pass the initialized JTextField to the EmojiPicker constructor
Component[] components = emojiPicker.getComponents();
// Act & Assert
for (Component component : components) {
assertTrue(component instanceof JButton);
JButton button = (JButton) component;
EmojiPicker.EmojiActionListener actionListener = (EmojiPicker.EmojiActionListener) button.getActionListeners()[0];
assertNotNull(actionListener);
actionListener.actionPerformed(null);
String expectedText = textField.getText() + button.getText(); // Expected text after appending emoji
assertEquals(expectedText, textField.getText(), "Failed for emoji: " + button.getText()); // Check if emoji is appended to the text field
}
} }
} }
Loading…
Cancel
Save