Skip to content

Commit

Permalink
fix: improved coverage for #2762
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Kronegg committed Jun 6, 2023
1 parent f1ae18d commit 069b3ad
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ProgressFormatterTest {
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ProgressFormatter formatter = new ProgressFormatter(out);
private final MockTestCase mocktestCase = new MockTestCase();
private final MockPickleStepTestStep mockPickleStepTestStep = new MockPickleStepTestStep();
private final StubTestCase mocktestCase = new StubTestCase();
private final StubPickleStepTestStep stubPickleStepTestStep = new StubPickleStepTestStep();

@BeforeEach
void setup() {
Expand All @@ -45,46 +45,60 @@ void prints_empty_line_for_empty_test_run() {
@Test
void prints_empty_line_and_green_dot_for_passing_test_run() {
Result result = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, bytes(equalToCompressingWhiteSpace(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + "\n")));
}

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

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

@Test
void print_nothing_for_passed_hook() {
Result result = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mocktestCase, mockPickleStepTestStep, result));
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
}

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

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

private class MockTestCase implements TestCase {
@Test
void print_red_F_for_failed_hook_monochrome() {
// Given
Result result = new Result(FAILED, Duration.ZERO, null);
formatter.setMonochrome(true);

// When
bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));

// Then
assertThat(out, bytes(equalTo("F" )));
formatter.setMonochrome(false);
}

private class StubTestCase implements TestCase {
@Override
public Integer getLine() {
return null;
Expand Down Expand Up @@ -131,7 +145,7 @@ public UUID getId() {
}
}

private class MockPickleStepTestStep implements PickleStepTestStep {
private class StubPickleStepTestStep implements PickleStepTestStep {
@Override
public String getPattern() {
return null;
Expand Down

0 comments on commit 069b3ad

Please sign in to comment.