From cc3673d38cff9429a916b3f54a776101ecc7ccc3 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 19:37:45 +0100 Subject: [PATCH 1/3] refactoring: TestKlasse --- src/test/java/ChatGUITest.java | 185 +++++++++++++++++---------------- 1 file changed, 95 insertions(+), 90 deletions(-) diff --git a/src/test/java/ChatGUITest.java b/src/test/java/ChatGUITest.java index f38488e..a2a20c9 100644 --- a/src/test/java/ChatGUITest.java +++ b/src/test/java/ChatGUITest.java @@ -12,96 +12,101 @@ import org.junit.Test; public class ChatGUITest { - private ChatGUI chatGUI; - - @Before - public void setUp() { - chatGUI = new ChatGUI(); - } - @Test - public void testSetOutputTextColorRed() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.red)); - assertEquals(Color.RED, chatGUI.outputTextArea.getForeground()); - } - @Test - public void testSetOutputTextColorBlue() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.blue)); - assertEquals(Color.BLUE, chatGUI.outputTextArea.getForeground()); - } - @Test - public void testSetOutputTextColorBlack() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.black)); - assertEquals(Color.BLACK, chatGUI.outputTextArea.getForeground()); - } - - @Test - public void testSetOutputTextColorGreen() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.green)); - assertEquals(Color.GREEN, chatGUI.outputTextArea.getForeground()); - } - @Test - public void testSetOutputTextFontSizeSmall() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.small)); - Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 12); - assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); - } - @Test - public void testSetOutputTextFontSizeMedium() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.medium)); - Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 16); - assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); - } - @Test - public void testSetOutputTextFontSizeLarge() { - chatGUI.actionPerformed(new TestActionEvent(chatGUI.large)); - Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 20); - assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); - } - @Test - public void testSendButtonActionPerformed() { - chatGUI.inputTextField.setText("Testnachricht"); - chatGUI.sendButton.doClick(); - - String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); - String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; - assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); - } - - @Test - public void testInputTextFieldActionPerformed() { - - chatGUI.inputTextField.setText("Testnachricht"); - chatGUI.actionPerformed(new ActionEvent(chatGUI.inputTextField, ActionEvent.ACTION_PERFORMED, "")); - - - String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); - String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; - assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); - - assertEquals("", chatGUI.inputTextField.getText()); - } - @Test - public void testAddMessage() { - - String message = "Testnachricht"; - chatGUI.addMessage(message); - - - String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); - String expectedMessage = "[" + timeStamp + "] " + message + "\n"; - - assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage)); - } - @Test - public void testSendPopupMessage() { - ChatGUI chatGUI = new ChatGUI(); - - - String testMessage = "Test Popup-Nachricht"; - - - chatGUI.sendPopupMessage(testMessage); - } + private ChatGUI chatGUI; + + @Before + public void setUp() { + chatGUI = new ChatGUI(); + } + + @Test + public void testSetOutputTextColorRed() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.red)); + assertEquals(Color.RED, chatGUI.outputTextArea.getForeground()); + } + + @Test + public void testSetOutputTextColorBlue() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.blue)); + assertEquals(Color.BLUE, chatGUI.outputTextArea.getForeground()); + } + + @Test + public void testSetOutputTextColorBlack() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.black)); + assertEquals(Color.BLACK, chatGUI.outputTextArea.getForeground()); + } + + @Test + public void testSetOutputTextColorGreen() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.green)); + assertEquals(Color.GREEN, chatGUI.outputTextArea.getForeground()); + } + + @Test + public void testSetOutputTextFontSizeSmall() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.small)); + Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 12); + assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); + } + + @Test + public void testSetOutputTextFontSizeMedium() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.medium)); + Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 16); + assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); + } + + @Test + public void testSetOutputTextFontSizeLarge() { + chatGUI.actionPerformed(new TestActionEvent(chatGUI.large)); + Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 20); + assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); + } + + @Test + public void testSendButtonActionPerformed() { + chatGUI.inputTextField.setText("Testnachricht"); + chatGUI.sendButton.doClick(); + + String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); + String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; + assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); + } + + @Test + public void testInputTextFieldActionPerformed() { + + chatGUI.inputTextField.setText("Testnachricht"); + chatGUI.actionPerformed(new ActionEvent(chatGUI.inputTextField, ActionEvent.ACTION_PERFORMED, "")); + + String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); + String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; + assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); + + assertEquals("", chatGUI.inputTextField.getText()); + } + + @Test + public void testAddMessage() { + + String message = "Testnachricht"; + chatGUI.addMessage(message); + + String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); + String expectedMessage = "[" + timeStamp + "] " + message + "\n"; + + assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage)); + } + + @Test + public void testSendPopupMessage() { + ChatGUI chatGUI = new ChatGUI(); + + String testMessage = "Test Popup-Nachricht"; + + chatGUI.sendPopupMessage(testMessage); + } } From 7f8b445989e0567b4b032a7991a2ec34215f8c48 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 19:42:38 +0100 Subject: [PATCH 2/3] Logik von Pop-Up Button verbessert --- src/main/java/ChatGUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 6ad34f1..08d12d6 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -160,6 +160,7 @@ public class ChatGUI implements ActionListener { if (e.getSource() == popupButton) { String message = inputTextField.getText(); inputTextField.setText(""); + addMessage(message); sendPopupMessage(message); } From 8e190b313e7681e40a4511071e43dbd248ff9971 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 19:45:36 +0100 Subject: [PATCH 3/3] =?UTF-8?q?refactoring:=20pr=C3=A4zisere=20Kommentare?= =?UTF-8?q?=20und=20Einr=C3=BCckungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 08d12d6..d8453fc 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -58,7 +58,7 @@ public class ChatGUI implements ActionListener { JMenu options = new JMenu("options"); JMenu colors = new JMenu("font-colors"); JMenu size = new JMenu("font-size"); - + // Create Pop-Up Button popupButton = new JButton("Popup-Nachricht senden"); popupButton.addActionListener(this); @@ -114,7 +114,7 @@ public class ChatGUI implements ActionListener { gui.setVisible(true); } - // main methode zum Testen, müsste bei Implementation entfernt werden + // main methode zum Testen, müsste bei Implementation in die Client-Klasse entfernt werden public static void main(String[] args) { new ChatGUI();