package org.realityforge.arez;

import javax.annotation.Nonnull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public abstract class AbstractArezTest
{
  @BeforeMethod
  protected void beforeTest()
    throws Exception
  {
    final ArezConfig.DynamicProvider provider = getConfigProvider();
    provider.setEnableNames( true );
    provider.setVerboseErrorMessages( true );
    provider.setCheckInvariants( true );
    provider.setPurgeReactionsWhenRunawayDetected( false );
    provider.setEnforceTransactionType( true );
    getProxyLogger().setLogger( new TestLogger() );
  }

  @AfterMethod
  protected void afterTest()
    throws Exception
  {
    final ArezConfig.DynamicProvider provider = getConfigProvider();
    provider.setEnableNames( false );
    provider.setVerboseErrorMessages( false );
    provider.setCheckInvariants( false );
    provider.setPurgeReactionsWhenRunawayDetected( true );
    provider.setEnforceTransactionType( false );
    getProxyLogger().setLogger( null );
  }

  @Nonnull
  final TestLogger getTestLogger()
  {
    return (TestLogger) getProxyLogger().getLogger();
  }

  @Nonnull
  private ArezLogger.ProxyLogger getProxyLogger()
  {
    return (ArezLogger.ProxyLogger) ArezLogger.getLogger();
  }

  @Nonnull
  final ArezConfig.DynamicProvider getConfigProvider()
  {
    return (ArezConfig.DynamicProvider) ArezConfig.getProvider();
  }
}

@@ -40,28 +40,120 @@
 java
-x.annotation.Nonnull
+.lang.reflect.Field;%0Aimport javax.annotation.Nonnull;%0Aimport javax.annotation.Nullable;%0Aimport org.testng.Assert
 ;%0Aim
@@ -1504,11 +1504,873 @@
 r();%0A  %7D
+%0A%0A  @Nonnull%0A  protected final Field getField( @Nonnull final Class%3C?%3E type, @Nonnull final String fieldName )%0A    throws NoSuchFieldException%0A  %7B%0A    Class clazz = type;%0A    while ( null != clazz && Object.class != clazz )%0A    %7B%0A      try%0A      %7B%0A        final Field field = clazz.getDeclaredField( fieldName );%0A        field.setAccessible( true );%0A        return field;%0A      %7D%0A      catch ( final Throwable t )%0A      %7B%0A        clazz = clazz.getSuperclass();%0A      %7D%0A    %7D%0A%0A    Assert.fail();%0A    throw new IllegalStateException();%0A  %7D%0A%0A  protected final void setField( @Nonnull final Object object,%0A                                 @Nonnull final String fieldName,%0A                                 @Nullable final Object value )%0A    throws NoSuchFieldException, IllegalAccessException%0A  %7B%0A    getField( object.getClass(), fieldName ).set( object, value );%0A  %7D
 %0A%7D%0A

Add helpers that allow setting of private fields