Browse Source

Modify test version

remotes/origin/test/client/add-test-cases
Alena Bandarovich 11 months ago
parent
commit
cf70b688b5
  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 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.awt.event.ActionEvent;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.junit.Before;
public class ChatGUITest { public class ChatGUITest {
private ChatGUI chatGUI;
public ChatGUI chatGUI;
@Before
@BeforeEach
public void setUp() { public void setUp() {
chatGUI = new ChatGUI(); chatGUI = new ChatGUI();
} }
@ -23,46 +19,46 @@ public class ChatGUITest {
@Test @Test
public void testSetOutputTextColorRed() { public void testSetOutputTextColorRed() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.red)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.red));
assertEquals(Color.RED, chatGUI.outputTextArea.getForeground());
Assertions.assertEquals(Color.RED, chatGUI.outputTextArea.getForeground());
} }
@Test @Test
public void testSetOutputTextColorBlue() { public void testSetOutputTextColorBlue() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.blue)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.blue));
assertEquals(Color.BLUE, chatGUI.outputTextArea.getForeground());
Assertions.assertEquals(Color.BLUE, chatGUI.outputTextArea.getForeground());
} }
@Test @Test
public void testSetOutputTextColorBlack() { public void testSetOutputTextColorBlack() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.black)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.black));
assertEquals(Color.BLACK, chatGUI.outputTextArea.getForeground());
Assertions.assertEquals(Color.BLACK, chatGUI.outputTextArea.getForeground());
} }
@Test @Test
public void testSetOutputTextColorGreen() { public void testSetOutputTextColorGreen() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.green)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.green));
assertEquals(Color.GREEN, chatGUI.outputTextArea.getForeground());
Assertions.assertEquals(Color.GREEN, chatGUI.outputTextArea.getForeground());
} }
@Test @Test
public void testSetOutputTextFontSizeSmall() { public void testSetOutputTextFontSizeSmall() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.small)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.small));
Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 12); Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 12);
assertEquals(expectedFont, chatGUI.outputTextArea.getFont());
Assertions.assertEquals(expectedFont, chatGUI.outputTextArea.getFont());
} }
@Test @Test
public void testSetOutputTextFontSizeMedium() { public void testSetOutputTextFontSizeMedium() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.medium)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.medium));
Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 16); Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 16);
assertEquals(expectedFont, chatGUI.outputTextArea.getFont());
Assertions.assertEquals(expectedFont, chatGUI.outputTextArea.getFont());
} }
@Test @Test
public void testSetOutputTextFontSizeLarge() { public void testSetOutputTextFontSizeLarge() {
chatGUI.actionPerformed(new TestActionEvent(chatGUI.large)); chatGUI.actionPerformed(new TestActionEvent(chatGUI.large));
Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 20); Font expectedFont = chatGUI.outputTextArea.getFont().deriveFont(Font.PLAIN, 20);
assertEquals(expectedFont, chatGUI.outputTextArea.getFont());
Assertions.assertEquals(expectedFont, chatGUI.outputTextArea.getFont());
} }
@Test @Test
@ -72,7 +68,7 @@ public class ChatGUITest {
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; String expectedOutput = "[" + timeStamp + "] Testnachricht\n";
assertEquals(expectedOutput, chatGUI.outputTextArea.getText());
Assertions.assertEquals(expectedOutput, chatGUI.outputTextArea.getText());
} }
@Test @Test
@ -83,9 +79,9 @@ public class ChatGUITest {
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedOutput = "[" + timeStamp + "] Testnachricht\n"; 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 @Test
@ -97,7 +93,7 @@ public class ChatGUITest {
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedMessage = "[" + timeStamp + "] " + message + "\n"; String expectedMessage = "[" + timeStamp + "] " + message + "\n";
assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage));
Assertions.assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage));
} }
@Test @Test
@ -116,6 +112,6 @@ public class ChatGUITest {
chatGUI.sendButton.doClick(); chatGUI.sendButton.doClick();
assertEquals("", chatGUI.outputTextArea.getText());
Assertions.assertEquals("", chatGUI.outputTextArea.getText());
} }
} }
Loading…
Cancel
Save