Browse Source

refactoring: TestKlasse

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
cc3673d38c
  1. 185
      src/test/java/ChatGUITest.java

185
src/test/java/ChatGUITest.java

@ -12,96 +12,101 @@ import org.junit.Test;
public class ChatGUITest { 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);
}
} }
Loading…
Cancel
Save