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

arez.testng.ObserverErrorCollector Maven / Gradle / Ivy

The newest version!
package arez.testng;

import arez.Observer;
import arez.ObserverError;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public final class ObserverErrorCollector
{
  @Nonnull
  private final List _observerErrors = new ArrayList<>();
  private final boolean _printExceptionStackTrace;

  public ObserverErrorCollector()
  {
    this( false );
  }

  public ObserverErrorCollector( final boolean printExceptionStackTrace )
  {
    _printExceptionStackTrace = printExceptionStackTrace;
  }

  public void clear()
  {
    _observerErrors.clear();
  }

  @Nonnull
  public List getObserverErrors()
  {
    return _observerErrors;
  }

  void onObserverError( @Nonnull final Observer observer,
                        @Nonnull final ObserverError error,
                        @Nullable final Throwable throwable )
  {
    _observerErrors.add( "Observer: " + observer.getName() + " Error: " + error + " " + throwable );
    if ( _printExceptionStackTrace && null != throwable )
    {
      throwable.printStackTrace();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy