From cf70b688b58623cec36504fd1d15ca802b3718f7 Mon Sep 17 00:00:00 2001 From: Alena Bandarovich Date: Fri, 9 Feb 2024 23:51:39 +0100 Subject: [PATCH] Modify test version --- src/test/java/ChatGUITest.java | 38 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/test/java/ChatGUITest.java b/src/test/java/ChatGUITest.java index 0405000..f30eb9a 100644 --- a/src/test/java/ChatGUITest.java +++ b/src/test/java/ChatGUITest.java @@ -1,21 +1,17 @@ -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.awt.Color; -import java.awt.Font; +import java.awt.*; import java.awt.event.ActionEvent; import java.text.SimpleDateFormat; import java.util.Date; -import org.junit.Before; - public class ChatGUITest { - private ChatGUI chatGUI; + public ChatGUI chatGUI; - @Before + @BeforeEach public void setUp() { chatGUI = new ChatGUI(); } @@ -23,46 +19,46 @@ public class ChatGUITest { @Test public void testSetOutputTextColorRed() { chatGUI.actionPerformed(new TestActionEvent(chatGUI.red)); - assertEquals(Color.RED, chatGUI.outputTextArea.getForeground()); + Assertions.assertEquals(Color.RED, chatGUI.outputTextArea.getForeground()); } @Test public void testSetOutputTextColorBlue() { chatGUI.actionPerformed(new TestActionEvent(chatGUI.blue)); - assertEquals(Color.BLUE, chatGUI.outputTextArea.getForeground()); + Assertions.assertEquals(Color.BLUE, chatGUI.outputTextArea.getForeground()); } @Test public void testSetOutputTextColorBlack() { chatGUI.actionPerformed(new TestActionEvent(chatGUI.black)); - assertEquals(Color.BLACK, chatGUI.outputTextArea.getForeground()); + Assertions.assertEquals(Color.BLACK, chatGUI.outputTextArea.getForeground()); } @Test public void testSetOutputTextColorGreen() { chatGUI.actionPerformed(new TestActionEvent(chatGUI.green)); - assertEquals(Color.GREEN, chatGUI.outputTextArea.getForeground()); + Assertions.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()); + Assertions.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()); + Assertions.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()); + Assertions.assertEquals(expectedFont, chatGUI.outputTextArea.getFont()); } @Test @@ -72,7 +68,7 @@ public class ChatGUITest { String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; - assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); + Assertions.assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); } @Test @@ -83,9 +79,9 @@ public class ChatGUITest { String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; - assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); + Assertions.assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); - assertEquals("", chatGUI.inputTextField.getText()); + Assertions.assertEquals("", chatGUI.inputTextField.getText()); } @Test @@ -97,7 +93,7 @@ public class ChatGUITest { String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String expectedMessage = "[" + timeStamp + "] " + message + "\n"; - assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage)); + Assertions.assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage)); } @Test @@ -116,6 +112,6 @@ public class ChatGUITest { chatGUI.sendButton.doClick(); - assertEquals("", chatGUI.outputTextArea.getText()); + Assertions.assertEquals("", chatGUI.outputTextArea.getText()); } }