package arez.integration.repository;

import arez.Arez;
import arez.ArezContext;
import arez.Flags;
import arez.Procedure;
import arez.annotations.ArezComponent;
import arez.annotations.InjectMode;
import arez.annotations.Observable;
import arez.annotations.Repository;
import arez.integration.AbstractArezIntegrationTest;
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import javax.annotation.Nonnull;
import javax.inject.Singleton;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class RepositoryInjectIntegrationTest
  extends AbstractArezIntegrationTest
{
  @ArezComponent
  @Repository( inject = InjectMode.PROVIDE )
  static abstract class TestComponent
  {
    private String _value;

    TestComponent( final String value )
    {
      _value = value;
    }

    @Observable
    String getValue()
    {
      return _value;
    }

    void setValue( final String value )
    {
      _value = value;
    }
  }

  @Module
  interface TestComponentDaggerModule
  {
    @Nonnull
    @Singleton
    @Provides
    static RepositoryInjectIntegrationTest_TestComponentRepository repository( final Arez_RepositoryInjectIntegrationTest_TestComponentRepository repository )
    {
      return repository;
    }
  }

  @Singleton
  @Component( modules = TestComponentDaggerModule.class )
  interface TestDaggerComponent
  {
    RepositoryInjectIntegrationTest_TestComponentRepository repository();
  }

  @Test
  public void useDaggerComponentToGetAccessToRepository()
    throws Throwable
  {
    final TestDaggerComponent daggerComponent = DaggerRepositoryInjectIntegrationTest_TestDaggerComponent.create();
    daggerComponent.repository();
    daggerComponent.repository();
    final RepositoryInjectIntegrationTest_TestComponentRepository repository = daggerComponent.repository();
    final TestComponent component1 = repository.create( "ABCDEF" );
    final TestComponent component2 = repository.create( "CDEFGH" );
    final TestComponent component3 = repository.create( "EFGHIJ" );

    final ArezContext context = Arez.context();

    final Procedure executable3 = () -> assertEquals( repository.findAll().size(), 3 );
    context.action( executable3, Flags.READ_ONLY );
    final Procedure executable2 = () -> assertEquals( repository.findAll().contains( component1 ), true );
    context.action( executable2, Flags.READ_ONLY );
    final Procedure executable1 = () -> assertEquals( repository.findAll().contains( component2 ), true );
    context.action( executable1, Flags.READ_ONLY );
    final Procedure executable = () -> assertEquals( repository.findAll().contains( component3 ), true );
    context.action( executable, Flags.READ_ONLY );
  }
}

@@ -2263,38 +2263,36 @@
 2 = () -%3E assert
-Equals
+True
 ( repository.fin
@@ -2320,22 +2320,16 @@
 onent1 )
-, true
  );%0A    
@@ -2414,38 +2414,36 @@
 1 = () -%3E assert
-Equals
+True
 ( repository.fin
@@ -2471,22 +2471,16 @@
 onent2 )
-, true
  );%0A    
@@ -2564,38 +2564,36 @@
 e = () -%3E assert
-Equals
+True
 ( repository.fin
@@ -2625,14 +2625,8 @@
 t3 )
-, true
  );%0A

Simplify assertion