package replicant;

import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class ConvergerTest
  extends AbstractReplicantTest
{
  @Test
  public void construct_withUnnecessaryContext()
  {
    final ReplicantContext context = Replicant.context();
    final IllegalStateException exception =
      expectThrows( IllegalStateException.class, () -> Converger.create( context ) );
    assertEquals( exception.getMessage(),
                  "Replicant-0124: SubscriptioConvergernService passed a context but Replicant.areZonesEnabled() is false" );
  }

  @Test
  public void getReplicantContext()
  {
    final ReplicantContext context = Replicant.context();
    final Converger converger = context.getConverger();
    assertEquals( converger.getReplicantContext(), context );
    assertEquals( getFieldValue( converger, "_context" ), null );
  }

  @Test
  public void getReplicantContext_zonesEnabled()
  {
    ReplicantTestUtil.enableZones();
    ReplicantTestUtil.resetState();

    final ReplicantContext context = Replicant.context();
    final Converger converger = context.getConverger();
    assertEquals( converger.getReplicantContext(), context );
    assertEquals( getFieldValue( converger, "_context" ), context );
  }
}

@@ -13,16 +13,84 @@
 icant;%0A%0A
+import arez.Arez;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A
 import o
@@ -1314,11 +1314,791 @@
 t );%0A  %7D
+%0A%0A  @Test%0A  public void preConvergeAction()%0A  %7B%0A    final Converger c = Replicant.context().getConverger();%0A%0A    // Pause scheduler so Autoruns don't auto-converge%0A    Arez.context().pauseScheduler();%0A%0A    // should do nothing ...%0A    Arez.context().safeAction( c::preConverge );%0A%0A    final AtomicInteger callCount = new AtomicInteger();%0A%0A    Arez.context().safeAction( () -%3E c.setPreConvergeAction( callCount::incrementAndGet ) );%0A%0A    Arez.context().safeAction( c::preConverge );%0A%0A    assertEquals( callCount.get(), 1 );%0A%0A    Arez.context().safeAction( c::preConverge );%0A%0A    assertEquals( callCount.get(), 2 );%0A%0A    Arez.context().safeAction( () -%3E c.setPreConvergeAction( null ) );%0A%0A    Arez.context().safeAction( c::preConverge );%0A%0A    assertEquals( callCount.get(), 2 );%0A  %7D
 %0A%7D%0A

Add preConverge test