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\n line2\r \n line3" );
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\n line2\r \n line3" );
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 \n line_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