Browse Source

test_EmojiPickerActionListenerFunctionality

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

1
src/main/java/EmojiPicker.java

@ -52,6 +52,7 @@ public class EmojiPicker extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
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
}
}

8
src/test/java/TestEmojiPicker.java

@ -75,8 +75,8 @@ public class TestEmojiPicker {
@Test
public void testEmojiPickerActionListenerFunctionality() {
// Arrange
JTextField textField = new JTextField();
EmojiPicker emojiPicker = new EmojiPicker(textField);
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
@ -86,8 +86,8 @@ public class TestEmojiPicker {
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
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