Browse Source

test_TestAddMessage plus Anpassen der anderen Tests auf den Zeitstempel

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
fe796888c3
  1. 2
      src/main/java/ChatGUI.java
  2. 23
      src/test/java/ChatGUITest.java

2
src/main/java/ChatGUI.java

@ -145,7 +145,7 @@ public class ChatGUI implements ActionListener {
} }
// add-message method with time stamp // add-message method with time stamp
private void addMessage(String message) {
void addMessage(String message) {
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
outputTextArea.append("[" + timeStamp + "] " + message + "\n"); outputTextArea.append("[" + timeStamp + "] " + message + "\n");
outputTextArea.setCaretPosition(outputTextArea.getDocument().getLength()); outputTextArea.setCaretPosition(outputTextArea.getDocument().getLength());

23
src/test/java/ChatGUITest.java

@ -1,8 +1,11 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -59,9 +62,11 @@ public class ChatGUITest {
chatGUI.inputTextField.setText("Testnachricht"); chatGUI.inputTextField.setText("Testnachricht");
chatGUI.sendButton.doClick(); chatGUI.sendButton.doClick();
String expectedOutput = "Testnachricht\n";
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedOutput = "[" + timeStamp + "] Testnachricht\n";
assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); assertEquals(expectedOutput, chatGUI.outputTextArea.getText());
} }
@Test @Test
public void testInputTextFieldActionPerformed() { public void testInputTextFieldActionPerformed() {
@ -69,12 +74,24 @@ public class ChatGUITest {
chatGUI.actionPerformed(new ActionEvent(chatGUI.inputTextField, ActionEvent.ACTION_PERFORMED, "")); chatGUI.actionPerformed(new ActionEvent(chatGUI.inputTextField, ActionEvent.ACTION_PERFORMED, ""));
String expectedOutput = "Testnachricht\n";
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedOutput = "[" + timeStamp + "] Testnachricht\n";
assertEquals(expectedOutput, chatGUI.outputTextArea.getText()); assertEquals(expectedOutput, chatGUI.outputTextArea.getText());
assertEquals("", chatGUI.inputTextField.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));
}
} }
Loading…
Cancel
Save