Skip to content

Commit

Permalink
Simplify ProgressFormatterTests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Apr 30, 2022
1 parent 42a33b9 commit 9d742cd
Showing 1 changed file with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.cucumber.plugin.event.Result;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestRunFinished;
import io.cucumber.plugin.event.TestRunStarted;
import io.cucumber.plugin.event.TestStepFinished;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -21,6 +20,7 @@
import static io.cucumber.core.plugin.BytesEqualTo.isBytesEqualTo;
import static io.cucumber.plugin.event.Status.FAILED;
import static io.cucumber.plugin.event.Status.PASSED;
import static io.cucumber.plugin.event.Status.UNDEFINED;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

Expand All @@ -37,46 +37,47 @@ void setup() {

@Test
void prints_empty_line_for_empty_test_run() {
bus.send(new TestRunStarted(Instant.now()));
Result runResult = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestRunFinished(Instant.now(), runResult));
assertThat(out, isBytesEqualTo("\n"));
}

@Test
void print_green_dot_for_passing_scenario() {
bus.send(new TestRunStarted(Instant.now()));
Result stepResult = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), stepResult));
Result hookResult = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), hookResult));
Result runResult = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestRunFinished(Instant.now(), runResult));
void print_green_dot_for_passing_step() {
Result result = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, isBytesEqualTo(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + "\n"));
}
@Test
void print_yellow_U_for_undefined_step() {
Result result = new Result(UNDEFINED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, isBytesEqualTo(AnsiEscapes.YELLOW + "U" + AnsiEscapes.RESET + "\n"));
}

@Test
void print_red_F_for_failed_scenario() {
bus.send(new TestRunStarted(Instant.now()));
Result stepResult = new Result(FAILED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), stepResult));
Result hookResult = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), hookResult));
Result runResult = new Result(FAILED, Duration.ZERO, null);
bus.send(new TestRunFinished(Instant.now(), runResult));
assertThat(out, isBytesEqualTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET + "\n"));
void print_nothing_for_passed_hook() {
Result result = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, isBytesEqualTo("\n"));
}

@Test
void print_red_F_for_failed_step() {
Result result = new Result(FAILED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, isBytesEqualTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET + "\n"));
}
@Test
void print_red_F_for_failed_hook() {
bus.send(new TestRunStarted(Instant.now()));
Result stepResult = new Result(PASSED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), stepResult));
Result hookResult = new Result(FAILED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), hookResult));
Result runResult = new Result(FAILED, Duration.ZERO, null);
bus.send(new TestRunFinished(Instant.now(), runResult));
assertThat(out, isBytesEqualTo(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + AnsiEscapes.RED + "F" + AnsiEscapes.RESET + "\n"));
Result result = new Result(FAILED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, isBytesEqualTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET + "\n"));
}

}

0 comments on commit 9d742cd

Please sign in to comment.