Skip to content

Commit a1eca55

Browse files
Julien KroneggU117293
Julien Kronegg
authored and
U117293
committed
fix: improved coverage for #2762
1 parent 09e5052 commit a1eca55

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

cucumber-core/src/test/java/io/cucumber/core/plugin/ProgressFormatterTest.java

+24-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class ProgressFormatterTest {
2727
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
2828
final ByteArrayOutputStream out = new ByteArrayOutputStream();
2929
final ProgressFormatter formatter = new ProgressFormatter(out);
30-
private final MockTestCase mocktestCase = new MockTestCase();
31-
private final MockPickleStepTestStep mockPickleStepTestStep = new MockPickleStepTestStep();
30+
private final StubTestCase mocktestCase = new StubTestCase();
31+
private final StubPickleStepTestStep stubPickleStepTestStep = new StubPickleStepTestStep();
3232

3333
@BeforeEach
3434
void setup() {
@@ -45,46 +45,60 @@ void prints_empty_line_for_empty_test_run() {
4545
@Test
4646
void prints_empty_line_and_green_dot_for_passing_test_run() {
4747
Result result = new Result(PASSED, Duration.ZERO, null);
48-
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
48+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
4949
bus.send(new TestRunFinished(Instant.now(), result));
5050
assertThat(out, bytes(equalToCompressingWhiteSpace(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + "\n")));
5151
}
5252

5353
@Test
5454
void print_green_dot_for_passing_step() {
5555
Result result = new Result(PASSED, Duration.ZERO, null);
56-
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
56+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
5757
assertThat(out, bytes(equalTo(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET)));
5858
}
5959

6060
@Test
6161
void print_yellow_U_for_undefined_step() {
6262
Result result = new Result(UNDEFINED, Duration.ZERO, null);
63-
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
63+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
6464
assertThat(out, bytes(equalTo(AnsiEscapes.YELLOW + "U" + AnsiEscapes.RESET)));
6565
}
6666

6767
@Test
6868
void print_nothing_for_passed_hook() {
6969
Result result = new Result(PASSED, Duration.ZERO, null);
70-
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
70+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
7171
}
7272

7373
@Test
7474
void print_red_F_for_failed_step() {
7575
Result result = new Result(FAILED, Duration.ZERO, null);
76-
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
76+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
7777
assertThat(out, bytes(equalTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET)));
7878
}
7979

8080
@Test
8181
void print_red_F_for_failed_hook() {
8282
Result result = new Result(FAILED, Duration.ZERO, null);
83-
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
83+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
8484
assertThat(out, bytes(equalTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET)));
8585
}
8686

87-
private class MockTestCase implements TestCase {
87+
@Test
88+
void print_red_F_for_failed_hook_monochrome() {
89+
// Given
90+
Result result = new Result(FAILED, Duration.ZERO, null);
91+
formatter.setMonochrome(true);
92+
93+
// When
94+
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
95+
96+
// Then
97+
assertThat(out, bytes(equalTo("F" )));
98+
formatter.setMonochrome(false);
99+
}
100+
101+
private class StubTestCase implements TestCase {
88102
@Override
89103
public Integer getLine() {
90104
return null;
@@ -131,7 +145,7 @@ public UUID getId() {
131145
}
132146
}
133147

134-
private class MockPickleStepTestStep implements PickleStepTestStep {
148+
private class StubPickleStepTestStep implements PickleStepTestStep {
135149
@Override
136150
public String getPattern() {
137151
return null;

0 commit comments

Comments
 (0)