From c17abd8dbc1cfb226bcad12633afea00a47abaa3 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 20:31:50 +0100 Subject: [PATCH 1/2] Logik verbessert --- src/main/java/ChatGUI.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index d8453fc..2c9f5bb 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -136,7 +136,9 @@ public class ChatGUI implements ActionListener { if (e.getSource() == inputTextField || e.getSource() == sendButton) { String inputText = inputTextField.getText(); inputTextField.setText(""); + if (!inputText.isEmpty()) { addMessage(inputText); + } } if (e.getSource() == red) { outputTextArea.setForeground(Color.RED); @@ -161,7 +163,9 @@ public class ChatGUI implements ActionListener { String message = inputTextField.getText(); inputTextField.setText(""); addMessage(message); + if(!message.isEmpty()) { sendPopupMessage(message); + } } } From 3023256ad96e6065746726ea1380cc38ead151f8 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 20:35:52 +0100 Subject: [PATCH 2/2] =?UTF-8?q?test=5FtestNoInputEntered=20hinzugef=C3=BCg?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/ChatGUITest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/java/ChatGUITest.java b/src/test/java/ChatGUITest.java index a2a20c9..1ef4f3f 100644 --- a/src/test/java/ChatGUITest.java +++ b/src/test/java/ChatGUITest.java @@ -107,6 +107,14 @@ public class ChatGUITest { chatGUI.sendPopupMessage(testMessage); } -} + @Test + public void testNoInputEntered() { + + chatGUI.inputTextField.setText(""); + chatGUI.sendButton.doClick(); + + assertEquals("", chatGUI.outputTextArea.getText()); + } +}