package arez.integration.dispose;

import arez.ArezTestUtil;
import arez.Disposable;
import arez.annotations.ArezComponent;
import arez.annotations.ComponentId;
import arez.annotations.Feature;
import arez.integration.AbstractArezIntegrationTest;
import javax.annotation.Nonnull;
import org.realityforge.guiceyloops.shared.ValueUtil;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class DisposedNotEqualIntegrationTest
  extends AbstractArezIntegrationTest
{
  @Test
  public void scenario()
  {
    /*
     * To get equal ids we have to disable a few features and then set requireEquals=ENABLED on component.
     * In the real world this matters as it is more often the case that the entity disappears and then reappears
     * and non-disposed variant should not match disposed variant.
     *
     * This happens in replicant where the same graph is unloaded and then reloaded (i.e. navigate away then back).
     */
    ArezTestUtil.disableNativeComponents();
    ArezTestUtil.disableRegistries();
    ArezTestUtil.resetState();

    final String id = ValueUtil.randomString();
    final Model1 model1 = Model1.create( id );
    final Model1 model2 = Model1.create( id );
    final Model1 model3 = Model1.create( id );

    Disposable.dispose( model3 );

    assertTrue( model1.equals( model2 ) );
    assertFalse( model1.equals( model3 ) );
    assertTrue( model2.equals( model1 ) );
    assertFalse( model2.equals( model3 ) );
    assertFalse( model3.equals( model1 ) );
    assertFalse( model3.equals( model2 ) );

    Disposable.dispose( model2 );

    assertFalse( model1.equals( model2 ) );
    assertFalse( model1.equals( model3 ) );
    assertFalse( model2.equals( model1 ) );
    assertTrue( model2.equals( model3 ) );
    assertFalse( model3.equals( model1 ) );
    assertTrue( model3.equals( model2 ) );
  }

  @ArezComponent( allowEmpty = true, requireEquals = Feature.ENABLE )
  static abstract class Model1
  {
    @Nonnull
    static Model1 create( @Nonnull final String id )
    {
      return new DisposedNotEqualIntegrationTest_Arez_Model1( id );
    }

    private final String _id;

    Model1( final String id )
    {
      _id = id;
    }

    @ComponentId
    final String getId()
    {
      return _id;
    }
  }
}

@@ -1299,20 +1299,22 @@
 sert
-True
+Equals
 ( model1
 .equ
@@ -1309,33 +1309,24 @@
 ( model1
-.equals(
+,
  model2
- )
  );%0A    
@@ -1327,37 +1327,41 @@
 ;%0A    assert
-F
+NotEqu
 als
-e
 ( model1
 .equals( mod
@@ -1348,33 +1348,24 @@
 ( model1
-.equals(
+,
  model3
- )
  );%0A    
@@ -1366,36 +1366,38 @@
 ;%0A    assert
-True
+Equals
 ( model2
 .equals( mod
@@ -1384,33 +1384,24 @@
 ( model2
-.equals(
+,
  model1
- )
  );%0A    
@@ -1402,37 +1402,41 @@
 ;%0A    assert
-F
+NotEqu
 als
-e
 ( model2
 .equals( mod
@@ -1423,33 +1423,24 @@
 ( model2
-.equals(
+,
  model3
- )
  );%0A    
@@ -1441,37 +1441,41 @@
 ;%0A    assert
-F
+NotEqu
 als
-e
 ( model3
 .equals( mod
@@ -1462,33 +1462,24 @@
 ( model3
-.equals(
+,
  model1
- )
  );%0A    
@@ -1480,37 +1480,41 @@
 ;%0A    assert
-F
+NotEqu
 als
-e
 ( model3
 .equals( mod
@@ -1501,33 +1501,24 @@
 ( model3
-.equals(
+,
  model2
- )
  );%0A%0A   
@@ -1555,37 +1555,41 @@
 %0A%0A    assert
-F
+NotEqu
 als
-e
 ( model1
 .equals( mod
@@ -1576,33 +1576,24 @@
 ( model1
-.equals(
+,
  model2
- )
  );%0A    
@@ -1602,21 +1602,25 @@
 sert
-F
+NotEqu
 als
-e
 ( model1
 .equ
@@ -1615,33 +1615,24 @@
 ( model1
-.equals(
+,
  model3
- )
  );%0A    
@@ -1641,21 +1641,25 @@
 sert
-F
+NotEqu
 als
-e
 ( model2
 .equ
@@ -1654,33 +1654,24 @@
 ( model2
-.equals(
+,
  model1
- )
  );%0A    
@@ -1680,20 +1680,22 @@
 sert
-True
+Equals
 ( model2
 .equ
@@ -1694,25 +1694,16 @@
 del2
-.equals(
+,
  model3
- )
  );%0A
@@ -1716,21 +1716,25 @@
 sert
-F
+NotEqu
 als
-e
 ( model3
 .equ
@@ -1733,25 +1733,16 @@
 del3
-.equals(
+,
  model1
- )
  );%0A
@@ -1755,20 +1755,22 @@
 sert
-True
+Equals
 ( model3
 .equ
@@ -1769,25 +1769,16 @@
 del3
-.equals(
+,
  model2
- )
  );%0A

Simplify assertions