001package arez.testng;
002
003import arez.Arez;
004import arez.ArezContext;
005import arez.ArezTestUtil;
006import arez.Disposable;
007import arez.Function;
008import arez.Observer;
009import arez.Procedure;
010import arez.SafeFunction;
011import arez.SafeProcedure;
012import javax.annotation.Nonnull;
013import org.realityforge.braincheck.BrainCheckTestUtil;
014import org.testng.IHookCallBack;
015import org.testng.IHookable;
016import org.testng.ITestResult;
017import org.testng.annotations.AfterMethod;
018import org.testng.annotations.BeforeMethod;
019
020public interface ArezTestSupport
021  extends IHookable
022{
023  @BeforeMethod
024  default void preTest()
025    throws Exception
026  {
027    BrainCheckTestUtil.resetConfig( false );
028    ArezTestUtil.resetConfig( false );
029  }
030
031  @AfterMethod
032  default void postTest()
033  {
034    ArezTestUtil.resetConfig( true );
035    BrainCheckTestUtil.resetConfig( true );
036  }
037
038  @Override
039  default void run( final IHookCallBack callBack, final ITestResult testResult )
040  {
041    new ArezTestHook().run( callBack, testResult );
042  }
043
044  @Nonnull
045  default ArezContext context()
046  {
047    return Arez.context();
048  }
049
050  @Nonnull
051  default Disposable pauseScheduler()
052  {
053    return context().pauseScheduler();
054  }
055
056  default void observer( @Nonnull final Procedure procedure )
057  {
058    context().observer( procedure, Observer.Flags.AREZ_OR_NO_DEPENDENCIES );
059  }
060
061  default void action( @Nonnull final Procedure action )
062    throws Throwable
063  {
064    context().action( action );
065  }
066
067  default <T> T action( @Nonnull final Function<T> action )
068    throws Throwable
069  {
070    return context().action( action );
071  }
072
073  default void safeAction( @Nonnull final SafeProcedure action )
074  {
075    context().safeAction( action );
076  }
077
078  default <T> T safeAction( @Nonnull final SafeFunction<T> action )
079  {
080    return context().safeAction( action );
081  }
082}