package arez.integration.observable_component;

import arez.Arez;
import arez.Disposable;
import arez.annotations.ArezComponent;
import arez.annotations.Feature;
import arez.component.ComponentObservable;
import arez.integration.AbstractArezIntegrationTest;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nonnull;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class ObservableComponentIntegrationTest
  extends AbstractArezIntegrationTest
{
  @Test
  public void disposeNotifiesComponentObservable()
    throws Throwable
  {
    final Model model = Model.create();
    final AtomicInteger callCount = new AtomicInteger();
    Arez.context().autorun( () -> {
      observeADependency();
      ComponentObservable.observe( model );
      callCount.incrementAndGet();
    } );
    assertEquals( callCount.get(), 1 );

    Disposable.dispose( model );

    assertEquals( callCount.get(), 2 );
  }

  @Test
  public void disposeNoNotifiesWhenNotComponentObservable()
    throws Throwable
  {
    final Model2 model = Model2.create();
    final AtomicInteger callCount = new AtomicInteger();
    Arez.context().autorun( () -> {
      observeADependency();
      ComponentObservable.observe( model );
      callCount.incrementAndGet();
    } );
    assertEquals( callCount.get(), 1 );

    Disposable.dispose( model );

    assertEquals( callCount.get(), 1 );
  }

  @ArezComponent( allowEmpty = true, observable = Feature.ENABLE )
  static abstract class Model
  {
    @Nonnull
    static Model create()
    {
      return new ObservableComponentIntegrationTest_Arez_Model();
    }
  }

  @ArezComponent( allowEmpty = true, observable = Feature.DISABLE )
  static abstract class Model2
  {
    @Nonnull
    static Model2 create()
    {
      return new ObservableComponentIntegrationTest_Arez_Model2();
    }
  }
}

@@ -954,904 +954,213 @@
 %0A  @
-Test%0A  public void disposeNoNotifiesWhenNotComponentObservable()%0A    throws Throwable%0A  %7B%0A    final Model2 model = Model2.create();%0A    final AtomicInteger callCount = new AtomicInteger();%0A    Arez.context().autorun( () -%3E %7B%0A      observeADependency();%0A      ComponentObservable.observe( model );%0A      callCount.incrementAndGet();%0A    %7D );%0A    assertEquals( callCount.get(), 1 );%0A%0A    Disposable.dispose( model );%0A%0A    assertEquals( callCount.get(), 1 );%0A  %7D%0A%0A  @ArezComponent( allowEmpty = true, observable = Feature.ENABLE )%0A  static abstract class Model%0A  %7B%0A    @Nonnull%0A    static Model create()%0A    %7B%0A      return new ObservableComponentIntegrationTest_Arez_Model();%0A    %7D%0A  %7D%0A%0A  @ArezComponent( allowEmpty = true, observable = Feature.DISABLE )%0A  static abstract class Model2%0A  %7B%0A    @Nonnull%0A    static Model2 create()%0A    %7B%0A      return new ObservableComponentIntegrationTest_Arez_Model2
+ArezComponent( allowEmpty = true, observable = Feature.ENABLE )%0A  static abstract class Model%0A  %7B%0A    @Nonnull%0A    static Model create()%0A    %7B%0A      return new ObservableComponentIntegrationTest_Arez_Model
 ();%0A

Remove test that no longer makes any sense