Skip to content

Commit c3c08e5

Browse files
committed
Added tests for AbstractTextMonitor "Show Timestamp" function
1 parent 4b7c7e8 commit c3c08e5

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package processing.app;
2+
3+
import static org.fest.assertions.Assertions.assertThat;
4+
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import cc.arduino.packages.BoardPort;
9+
import processing.app.helpers.PreferencesMap;
10+
11+
public class UpdateTextAreaActionTest {
12+
13+
private static final String TIMESTAMP_REGEX = "\\d\\d:\\d\\d:\\d\\d.\\d\\d\\d";
14+
15+
class DummyTextMonitor extends AbstractTextMonitor {
16+
public DummyTextMonitor(BoardPort boardPort) {
17+
super(boardPort);
18+
}
19+
}
20+
21+
@Before
22+
public void setup() {
23+
PreferencesData.defaults = new PreferencesMap();
24+
PreferencesData.set("editor.font", "Monospaced,plain,12");
25+
PreferencesData.set("gui.scale", "100");
26+
Theme.defaults = new PreferencesMap();
27+
Theme.table.put("console.font", "Monospaced,plain,12");
28+
}
29+
30+
@Test
31+
public void noTimestampAdded() {
32+
DummyTextMonitor textMon = new DummyTextMonitor(new BoardPort());
33+
textMon.addTimeStampBox.setSelected(false);
34+
35+
textMon.updateTextArea("line1\nline2\r\nline3");
36+
assertThat(textMon.textArea.getText()).matches("line1\nline2\r\nline3");
37+
}
38+
39+
@Test
40+
public void all3LinesHaveTimestampAdded() {
41+
DummyTextMonitor textMon = new DummyTextMonitor(new BoardPort());
42+
textMon.addTimeStampBox.setSelected(true);
43+
44+
textMon.updateTextArea("line1\nline2\r\nline3");
45+
assertThat(textMon.textArea.getText())
46+
.matches(TIMESTAMP_REGEX + " -> line1\\n" + //
47+
TIMESTAMP_REGEX + " -> line2\\r\\n" + //
48+
TIMESTAMP_REGEX + " -> line3");
49+
}
50+
51+
@Test
52+
public void emptyLinesHaveTimestampToo() {
53+
DummyTextMonitor textMon = new DummyTextMonitor(new BoardPort());
54+
textMon.addTimeStampBox.setSelected(true);
55+
56+
textMon.updateTextArea("line_1\n\nline_2");
57+
assertThat(textMon.textArea.getText())
58+
.matches(TIMESTAMP_REGEX + " -> line_1\\n" + //
59+
TIMESTAMP_REGEX + " -> \\n" + //
60+
TIMESTAMP_REGEX + " -> line_2");
61+
}
62+
63+
@Test
64+
public void newLinesAreRememberedWhenNewBufferIsUsed() {
65+
DummyTextMonitor textMon = new DummyTextMonitor(new BoardPort());
66+
textMon.addTimeStampBox.setSelected(true);
67+
68+
textMon.updateTextArea("no newline");
69+
assertThat(textMon.textArea.getText())
70+
.matches(TIMESTAMP_REGEX + " -> no newline");
71+
72+
textMon.updateTextArea(" more text");
73+
assertThat(textMon.textArea.getText())
74+
.matches(TIMESTAMP_REGEX + " -> no newline more text");
75+
76+
textMon.updateTextArea("\n");
77+
assertThat(textMon.textArea.getText())
78+
.matches(TIMESTAMP_REGEX + " -> no newline more text\n");
79+
80+
textMon.updateTextArea("\n");
81+
assertThat(textMon.textArea.getText())
82+
.matches(TIMESTAMP_REGEX + " -> no newline more text\n" + //
83+
TIMESTAMP_REGEX + " -> \n");
84+
85+
textMon.updateTextArea("third line");
86+
assertThat(textMon.textArea.getText())
87+
.matches(TIMESTAMP_REGEX + " -> no newline more text\n" + //
88+
TIMESTAMP_REGEX + " -> \n" + //
89+
TIMESTAMP_REGEX + " -> third line");
90+
}
91+
}

0 commit comments

Comments
 (0)