From e8da8454c8c18ac879e857b7249f24439d0bb283 Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Fri, 9 Feb 2024 22:46:51 +0100 Subject: [PATCH] refactoring:testEmojiPickerActionListenerFunctionality --- src/test/java/TestEmojiPicker.java | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/test/java/TestEmojiPicker.java b/src/test/java/TestEmojiPicker.java index 4843226..1ad2632 100644 --- a/src/test/java/TestEmojiPicker.java +++ b/src/test/java/TestEmojiPicker.java @@ -71,24 +71,23 @@ public class TestEmojiPicker { } } + //Test to verify the functionality of EmojiActionListener for each emoji button @Test public void testEmojiPickerActionListenerFunctionality() { - JTextField textField = new JTextField(); - - EmojiPicker emojiPicker = new EmojiPicker(textField); - - Component[] components = emojiPicker.getComponents(); - for (Component component : components) { - - assertTrue(component instanceof JButton); - JButton button = (JButton) component; + // 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()); - } + assertEquals(button.getText(), textField.getText()); // Check if emoji is appended to the text field + } } }