
net.serenitybdd.screenplay.ErrorTally Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of serenity-screenplay Show documentation
Show all versions of serenity-screenplay Show documentation
Support for the User Journey pattern in Serenity
package net.serenitybdd.screenplay;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import net.serenitybdd.core.Serenity;
import java.util.List;
public class ErrorTally {
private final EventBusInterface eventBusInterface;
private final List errors;
public ErrorTally(EventBusInterface eventBusInterface) {
this.eventBusInterface = eventBusInterface;
this.errors = Lists.newArrayList();
}
public void recordError(Consequence consequence, Throwable cause) {
errors.add(new FailedConsequence(consequence, cause));
eventBusInterface.reportStepFailureFor(consequence, cause);
}
public void reportAnyErrors() {
if (errors.isEmpty()) {
return;
}
if (Serenity.shouldThrowErrorsImmediately()) {
throwSummaryExceptionFrom(errorCausesIn(errors));
}
}
private void throwSummaryExceptionFrom(List errorCauses) {
String overallErrorMessage = Joiner.on(System.lineSeparator()).join(errorMessagesIn(errorCauses));
throw new AssertionError(overallErrorMessage);
}
private List errorCausesIn(List failedConsequences) {
List causes = Lists.newArrayList();
for(FailedConsequence consequence : failedConsequences) {
causes.add(consequence.getCause());
}
return causes;
}
private List errorMessagesIn(List errorCauses) {
List errorMessages = Lists.newArrayList();
for(Throwable cause : errorCauses) {
errorMessages.add(cause.getMessage());
}
return errorMessages;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy