Skip to content

Commit a951998

Browse files
committed
Add test for UpdateTextAreaAction (related to issue #8055)
Also, introduce 3 new dependencies for testing scope only. Testing dynamic behavior with Mockito library enables better test coverage
1 parent 00c8314 commit a951998

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

.classpath

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<classpathentry kind="lib" path="app/test-lib/fest-swing-1.2.jar"/>
1212
<classpathentry kind="lib" path="app/test-lib/fest-util-1.1.2.jar"/>
1313
<classpathentry kind="lib" path="app/test-lib/jcip-annotations-1.0.jar"/>
14+
<classpathentry kind="lib" path="app/test-lib/mockito-core-2.23.0.jar"/>
15+
<classpathentry kind="lib" path="app/test-lib/byte-buddy-1.9.1.jar"/>
16+
<classpathentry kind="lib" path="app/test-lib/objenesis-3.0.jar"/>
1417
<classpathentry kind="lib" path="app/lib/commons-codec-1.7.jar"/>
1518
<classpathentry kind="lib" path="app/lib/commons-exec-1.1.jar"/>
1619
<classpathentry kind="lib" path="app/lib/commons-httpclient-3.1.jar"/>

app/.classpath

+3
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@
5353
<classpathentry kind="lib" path="test-lib/fest-swing-1.2.jar"/>
5454
<classpathentry kind="lib" path="test-lib/fest-util-1.1.2.jar"/>
5555
<classpathentry kind="lib" path="test-lib/jcip-annotations-1.0.jar"/>
56+
<classpathentry kind="lib" path="test-lib/mockito-core-2.23.0.jar"/>
57+
<classpathentry kind="lib" path="test-lib/byte-buddy-1.9.1.jar"/>
58+
<classpathentry kind="lib" path="test-lib/objenesis-3.0.jar"/>
5659
</classpath>

app/test-lib/byte-buddy-1.9.1.jar

3.03 MB
Binary file not shown.

app/test-lib/mockito-core-2.23.0.jar

552 KB
Binary file not shown.

app/test-lib/objenesis-3.0.jar

59.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package processing.app;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.mockito.ArgumentCaptor;
6+
7+
import static org.fest.assertions.Assertions.assertThat;
8+
import static org.mockito.Mockito.*;
9+
10+
public class UpdateTextAreaActionTest {
11+
12+
private static final String TIMESTAMP_REGEX = "\\d\\d:\\d\\d:\\d\\d.\\d\\d\\d";
13+
private TextAreaFIFO textAreaFIFO;
14+
private ArgumentCaptor<String> text;
15+
16+
@Before public void setUp() {
17+
textAreaFIFO = mock(TextAreaFIFO.class);
18+
text = ArgumentCaptor.forClass(String.class);
19+
}
20+
21+
@Test
22+
public void noTimestampAdded() {
23+
// given
24+
AbstractTextMonitor.UpdateTextAreaAction action = new AbstractTextMonitor.UpdateTextAreaAction(
25+
textAreaFIFO, false, false, "line1\nline2\r\nline3");
26+
27+
// when
28+
action.run();
29+
30+
//then
31+
verify(textAreaFIFO, atLeastOnce()).append(text.capture());
32+
assertThat(text.getValue()).startsWith("line1");
33+
}
34+
35+
@Test
36+
public void all3LinesHaveTimestampAdded() {
37+
// given
38+
AbstractTextMonitor.UpdateTextAreaAction action = new AbstractTextMonitor.UpdateTextAreaAction(
39+
textAreaFIFO, true, false, "line1\nline2\r\nline3");
40+
41+
// when
42+
action.run();
43+
44+
//then
45+
verify(textAreaFIFO, atLeastOnce()).append(text.capture());
46+
assertThat(text.getValue()).matches(TIMESTAMP_REGEX + " -> line1\\n"
47+
+ TIMESTAMP_REGEX + " -> line2\\r\\n"
48+
+ TIMESTAMP_REGEX + " -> line3");
49+
}
50+
51+
@Test
52+
public void emptyLinesHaveTimestampToo() {
53+
// given
54+
AbstractTextMonitor.UpdateTextAreaAction action = new AbstractTextMonitor.UpdateTextAreaAction(
55+
textAreaFIFO, true, false, "line_1\n\nline_2");
56+
57+
// when
58+
action.run();
59+
60+
//then
61+
verify(textAreaFIFO, atLeastOnce()).append(text.capture());
62+
assertThat(text.getValue()).matches(TIMESTAMP_REGEX + " -> line_1\\n"
63+
+ TIMESTAMP_REGEX + " -> \\n"
64+
+ TIMESTAMP_REGEX + " -> line_2");
65+
}
66+
67+
}

0 commit comments

Comments
 (0)