From fbd24f4ee9a4d4cfb8e37a210e7c4e0aba8d49ee Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Fri, 9 Feb 2024 22:32:39 +0100 Subject: [PATCH] test_testEmojiPickerActionListener --- src/main/java/EmojiPicker.java | 2 +- src/test/java/TestEmojiPicker.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/EmojiPicker.java b/src/main/java/EmojiPicker.java index 85963eb..17a7f7a 100644 --- a/src/main/java/EmojiPicker.java +++ b/src/main/java/EmojiPicker.java @@ -36,7 +36,7 @@ public class EmojiPicker extends JPanel { /** * ActionListener for handling emoji button clicks. */ - private class EmojiActionListener implements ActionListener { + class EmojiActionListener implements ActionListener { private String emoji; // Selected emoji diff --git a/src/test/java/TestEmojiPicker.java b/src/test/java/TestEmojiPicker.java index c2c55c3..5fe2c94 100644 --- a/src/test/java/TestEmojiPicker.java +++ b/src/test/java/TestEmojiPicker.java @@ -50,5 +50,24 @@ public class TestEmojiPicker { } } + @Test + public void testEmojiPickerActionListener() { + + 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; + assertNotNull(button.getActionListeners()); + + assertEquals(1, button.getActionListeners().length); + assertTrue(button.getActionListeners()[0] instanceof EmojiPicker.EmojiActionListener); + } + } } \ No newline at end of file