Browse Source

Merge branch 'test/client/add-test-cases'

main
Alena Bandarovich 11 months ago
parent
commit
f06563324f
  1. 38
      src/test/java/ChatGUITest.java

38
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());
}
}
Loading…
Cancel
Save