Browse Source

refactoring:testEmojiPickerActionListenerFunctionality

remotes/origin/client-handler
Valentin Spiroski 11 months ago
parent
commit
e8da8454c8
  1. 23
      src/test/java/TestEmojiPicker.java

23
src/test/java/TestEmojiPicker.java

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