Skip to content

Commit

Permalink
[vividus] Skip reporting of status for @BeforeStories/@AfterStories (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski authored and ikalinin1 committed Jan 31, 2022
1 parent 88e9a10 commit e3b3562
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
20 changes: 15 additions & 5 deletions vividus/src/main/java/org/vividus/StatusStoryReporter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,19 @@
import java.util.concurrent.atomic.AtomicReference;

import org.jbehave.core.model.Scenario;
import org.vividus.context.ReportControlContext;
import org.vividus.context.RunContext;
import org.vividus.softassert.exception.VerificationError;

public class StatusStoryReporter extends ChainedStoryReporter implements IRunStatusProvider
public class StatusStoryReporter extends AbstractReportControlStoryReporter implements IRunStatusProvider
{
private final AtomicReference<Optional<Status>> status = new AtomicReference<>(Optional.empty());

public StatusStoryReporter(ReportControlContext reportControlContext, RunContext runContext)
{
super(reportControlContext, runContext);
}

@Override
public Optional<Status> getRunStatus()
{
Expand All @@ -42,7 +49,7 @@ public void scenarioExcluded(Scenario scenario, String filter)
@Override
public void successful(String step)
{
changeStatus(Status.PASSED);
perform(() -> changeStatus(Status.PASSED));
super.successful(step);
}

Expand Down Expand Up @@ -70,8 +77,11 @@ public void notPerformed(String step)
@Override
public void failed(String step, Throwable throwable)
{
Throwable cause = JBehaveFailureUnwrapper.unwrapCause(throwable);
changeStatus(getStatus(cause));
perform(() ->
{
Throwable cause = JBehaveFailureUnwrapper.unwrapCause(throwable);
changeStatus(getStatus(cause));
});
super.failed(step, throwable);
}

Expand Down
28 changes: 22 additions & 6 deletions vividus/src/test/java/org/vividus/StatusStoryReporterTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.List;
Expand All @@ -31,6 +32,8 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.vividus.context.ReportControlContext;
import org.vividus.context.RunContext;
import org.vividus.softassert.exception.VerificationError;
import org.vividus.softassert.issue.KnownIssueIdentifier;
import org.vividus.softassert.issue.KnownIssueType;
Expand All @@ -40,11 +43,10 @@
@ExtendWith(MockitoExtension.class)
class StatusStoryReporterTests
{
@Mock
private StoryReporter nextStoryReporter;

@InjectMocks
private StatusStoryReporter statusStoryReporter;
@Mock private StoryReporter nextStoryReporter;
@Mock private ReportControlContext reportControlContext;
@Mock private RunContext runContext;
@InjectMocks private StatusStoryReporter statusStoryReporter;

@BeforeEach
void beforeEach()
Expand Down Expand Up @@ -87,6 +89,7 @@ void testNotPerformed()
@Test
void testBroken()
{
mockEnabledReporting();
IOException throwable = new IOException();
statusStoryReporter.failed(null, throwable);
assertEquals(Optional.of(Status.BROKEN), statusStoryReporter.getRunStatus());
Expand All @@ -96,6 +99,7 @@ void testBroken()
@Test
void testFailedAssertionError()
{
mockEnabledReporting();
UUIDExceptionWrapper throwable = new UUIDExceptionWrapper(new AssertionError());
statusStoryReporter.failed(null, throwable);
assertEquals(Optional.of(Status.FAILED), statusStoryReporter.getRunStatus());
Expand All @@ -105,6 +109,7 @@ void testFailedAssertionError()
@Test
void testFailedVerificationError()
{
mockEnabledReporting();
VerificationError verificationError = new VerificationError(null, List.of(new SoftAssertionError(null)));
UUIDExceptionWrapper throwable = new UUIDExceptionWrapper(verificationError);
statusStoryReporter.failed(null, throwable);
Expand All @@ -115,6 +120,7 @@ void testFailedVerificationError()
@Test
void testKnownIssuesOnly()
{
mockEnabledReporting();
SoftAssertionError softAssertionError = new SoftAssertionError(null);
softAssertionError.setKnownIssue(createKnownIssue(false));
VerificationError verificationError = new VerificationError(null, List.of(softAssertionError));
Expand All @@ -127,6 +133,7 @@ void testKnownIssuesOnly()
@Test
void testFailedWithPotentiallyKnownIssue()
{
mockEnabledReporting();
SoftAssertionError softAssertionError = new SoftAssertionError(null);
softAssertionError.setKnownIssue(createKnownIssue(true));
VerificationError verificationError = new VerificationError(null, List.of(softAssertionError));
Expand All @@ -139,6 +146,7 @@ void testFailedWithPotentiallyKnownIssue()
@Test
void testSuccessful()
{
mockEnabledReporting();
statusStoryReporter.successful(null);
assertEquals(Optional.of(Status.PASSED), statusStoryReporter.getRunStatus());
verify(nextStoryReporter).successful(null);
Expand All @@ -147,6 +155,7 @@ void testSuccessful()
@Test
void testStatusPriorities()
{
mockEnabledReporting();
statusStoryReporter.successful(null);
statusStoryReporter.failed(null, null);
statusStoryReporter.successful(null);
Expand All @@ -157,6 +166,7 @@ void testStatusPriorities()
@Test
void shouldSwitchKnownIssuesOnlyToPending()
{
mockEnabledReporting();
SoftAssertionError softAssertionError = new SoftAssertionError(null);
softAssertionError.setKnownIssue(createKnownIssue(false));
VerificationError verificationError = new VerificationError(null, List.of(softAssertionError));
Expand All @@ -173,4 +183,10 @@ private KnownIssue createKnownIssue(boolean potentiallyKnown)
identifier.setType(KnownIssueType.AUTOMATION);
return new KnownIssue(null, identifier, potentiallyKnown);
}

private void mockEnabledReporting()
{
when(reportControlContext.isReportingEnabled()).thenReturn(true);
when(runContext.isRunCompleted()).thenReturn(false);
}
}

0 comments on commit e3b3562

Please # to comment.