Browse Source

Merge branch 'server' into 'main'

Server

See merge request fdai7332/java-chat!14
remotes/origin/hotfix/client/improve-chat-window-appearence
fdai7599 11 months ago
parent
commit
43ad499f15
  1. 3
      src/main/java/ChatGUI.java
  2. 13
      src/test/java/ChatGUITest.java

3
src/main/java/ChatGUI.java

@ -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();
@ -160,6 +160,7 @@ public class ChatGUI implements ActionListener {
if (e.getSource() == popupButton) {
String message = inputTextField.getText();
inputTextField.setText("");
addMessage(message);
sendPopupMessage(message);
}

13
src/test/java/ChatGUITest.java

@ -18,16 +18,19 @@ public class ChatGUITest {
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));
@ -39,24 +42,28 @@ public class ChatGUITest {
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");
@ -73,33 +80,31 @@ public class ChatGUITest {
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