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); + } } } 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()); + } +}