All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.approvaltests.reporters.MultiReporter Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package org.approvaltests.reporters;

import org.approvaltests.core.ApprovalFailureReporter;
import org.lambda.query.Queryable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class MultiReporter implements ApprovalFailureReporter
{
  private final Collection reporters;
  public MultiReporter(Collection reporters)
  {
    this.reporters = reporters;
  }
  public MultiReporter(ApprovalFailureReporter... reporters)
  {
    this.reporters = Arrays.asList(reporters);
  }
  @Override
  public boolean report(String received, String approved)
  {
    boolean didAnyReporterWork = false;
    ArrayList exceptions = new ArrayList();
    for (ApprovalFailureReporter reporter : reporters)
    {
      try
      {
        didAnyReporterWork |= reporter.report(received, approved);
      }
      catch (Throwable t)
      {
        exceptions.add(t);
      }
    }
    MultipleExceptions.rethrowExceptions(exceptions);
    return didAnyReporterWork;
  }
  public ApprovalFailureReporter[] getReporters()
  {
    return reporters.toArray(new ApprovalFailureReporter[0]);
  }
  @Override
  public String toString()
  {
    return Queryable.as(reporters.stream()).join(", ", r -> r.getClass().getSimpleName());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy