22
33import io .cucumber .core .eventbus .EventBus ;
44import io .cucumber .core .runtime .TimeServiceEventBus ;
5- import io .cucumber .plugin .event .HookTestStep ;
6- import io .cucumber .plugin .event .PickleStepTestStep ;
7- import io .cucumber .plugin .event .Result ;
8- import io .cucumber .plugin .event .TestCase ;
9- import io .cucumber .plugin .event .TestRunFinished ;
10- import io .cucumber .plugin .event .TestStepFinished ;
5+ import io .cucumber .plugin .event .*;
116import org .junit .jupiter .api .BeforeEach ;
127import org .junit .jupiter .api .Test ;
138
149import java .io .ByteArrayOutputStream ;
10+ import java .net .URI ;
1511import java .time .Clock ;
1612import java .time .Duration ;
1713import java .time .Instant ;
14+ import java .util .List ;
1815import java .util .UUID ;
1916
2017import static io .cucumber .core .plugin .Bytes .bytes ;
2421import static org .hamcrest .CoreMatchers .equalTo ;
2522import static org .hamcrest .MatcherAssert .assertThat ;
2623import static org .hamcrest .text .IsEqualCompressingWhiteSpace .equalToCompressingWhiteSpace ;
27- import static org .mockito .Mockito .mock ;
2824
2925class ProgressFormatterTest {
3026
3127 final EventBus bus = new TimeServiceEventBus (Clock .systemUTC (), UUID ::randomUUID );
3228 final ByteArrayOutputStream out = new ByteArrayOutputStream ();
3329 final ProgressFormatter formatter = new ProgressFormatter (out );
30+ private final MockTestCase mocktestCase = new MockTestCase ();
31+ private final MockPickleStepTestStep mockPickleStepTestStep = new MockPickleStepTestStep ();
3432
3533 @ BeforeEach
3634 void setup () {
@@ -47,43 +45,136 @@ void prints_empty_line_for_empty_test_run() {
4745 @ Test
4846 void prints_empty_line_and_green_dot_for_passing_test_run () {
4947 Result result = new Result (PASSED , Duration .ZERO , null );
50- bus .send (new TestStepFinished (Instant .now (), mock ( TestCase . class ), mock ( PickleStepTestStep . class ) , result ));
48+ bus .send (new TestStepFinished (Instant .now (), mocktestCase , mockPickleStepTestStep , result ));
5149 bus .send (new TestRunFinished (Instant .now (), result ));
5250 assertThat (out , bytes (equalToCompressingWhiteSpace (AnsiEscapes .GREEN + "." + AnsiEscapes .RESET + "\n " )));
5351 }
5452
5553 @ Test
5654 void print_green_dot_for_passing_step () {
5755 Result result = new Result (PASSED , Duration .ZERO , null );
58- bus .send (new TestStepFinished (Instant .now (), mock ( TestCase . class ), mock ( PickleStepTestStep . class ) , result ));
56+ bus .send (new TestStepFinished (Instant .now (), mocktestCase , mockPickleStepTestStep , result ));
5957 assertThat (out , bytes (equalTo (AnsiEscapes .GREEN + "." + AnsiEscapes .RESET )));
6058 }
6159
6260 @ Test
6361 void print_yellow_U_for_undefined_step () {
6462 Result result = new Result (UNDEFINED , Duration .ZERO , null );
65- bus .send (new TestStepFinished (Instant .now (), mock ( TestCase . class ), mock ( PickleStepTestStep . class ) , result ));
63+ bus .send (new TestStepFinished (Instant .now (), mocktestCase , mockPickleStepTestStep , result ));
6664 assertThat (out , bytes (equalTo (AnsiEscapes .YELLOW + "U" + AnsiEscapes .RESET )));
6765 }
6866
6967 @ Test
7068 void print_nothing_for_passed_hook () {
7169 Result result = new Result (PASSED , Duration .ZERO , null );
72- bus .send (new TestStepFinished (Instant .now (), mock ( TestCase . class ), mock ( HookTestStep . class ) , result ));
70+ bus .send (new TestStepFinished (Instant .now (), mocktestCase , mockPickleStepTestStep , result ));
7371 }
7472
7573 @ Test
7674 void print_red_F_for_failed_step () {
7775 Result result = new Result (FAILED , Duration .ZERO , null );
78- bus .send (new TestStepFinished (Instant .now (), mock ( TestCase . class ), mock ( PickleStepTestStep . class ) , result ));
76+ bus .send (new TestStepFinished (Instant .now (), mocktestCase , mockPickleStepTestStep , result ));
7977 assertThat (out , bytes (equalTo (AnsiEscapes .RED + "F" + AnsiEscapes .RESET )));
8078 }
8179
8280 @ Test
8381 void print_red_F_for_failed_hook () {
8482 Result result = new Result (FAILED , Duration .ZERO , null );
85- bus .send (new TestStepFinished (Instant .now (), mock ( TestCase . class ), mock ( HookTestStep . class ) , result ));
83+ bus .send (new TestStepFinished (Instant .now (), mocktestCase , mockPickleStepTestStep , result ));
8684 assertThat (out , bytes (equalTo (AnsiEscapes .RED + "F" + AnsiEscapes .RESET )));
8785 }
8886
87+ private class MockTestCase implements TestCase {
88+ @ Override
89+ public Integer getLine () {
90+ return null ;
91+ }
92+
93+ @ Override
94+ public Location getLocation () {
95+ return null ;
96+ }
97+
98+ @ Override
99+ public String getKeyword () {
100+ return null ;
101+ }
102+
103+ @ Override
104+ public String getName () {
105+ return null ;
106+ }
107+
108+ @ Override
109+ public String getScenarioDesignation () {
110+ return null ;
111+ }
112+
113+ @ Override
114+ public List <String > getTags () {
115+ return null ;
116+ }
117+
118+ @ Override
119+ public List <TestStep > getTestSteps () {
120+ return null ;
121+ }
122+
123+ @ Override
124+ public URI getUri () {
125+ return null ;
126+ }
127+
128+ @ Override
129+ public UUID getId () {
130+ return null ;
131+ }
132+ }
133+
134+ private class MockPickleStepTestStep implements PickleStepTestStep {
135+ @ Override
136+ public String getPattern () {
137+ return null ;
138+ }
139+
140+ @ Override
141+ public Step getStep () {
142+ return null ;
143+ }
144+
145+ @ Override
146+ public List <Argument > getDefinitionArgument () {
147+ return null ;
148+ }
149+
150+ @ Override
151+ public StepArgument getStepArgument () {
152+ return null ;
153+ }
154+
155+ @ Override
156+ public int getStepLine () {
157+ return 0 ;
158+ }
159+
160+ @ Override
161+ public URI getUri () {
162+ return null ;
163+ }
164+
165+ @ Override
166+ public String getStepText () {
167+ return null ;
168+ }
169+
170+ @ Override
171+ public String getCodeLocation () {
172+ return null ;
173+ }
174+
175+ @ Override
176+ public UUID getId () {
177+ return null ;
178+ }
179+ }
89180}
0 commit comments