package replicant;

import org.realityforge.guiceyloops.shared.ValueUtil;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class AreaOfInterestEntryTest
  extends AbstractReplicantTest
{
  @Test
  public void basicOperation()
  {
    final ChannelAddress address = new ChannelAddress( G.G1 );
    final Object filterParameter = null;
    final AreaOfInterestAction action = AreaOfInterestAction.ADD;

    final AreaOfInterestEntry entry = new AreaOfInterestEntry( address, action, filterParameter );

    assertEquals( entry.getAddress(), address );
    assertEquals( entry.getAction(), action );
    assertEquals( entry.getCacheKey(), "G:G1" );
    assertEquals( entry.getFilter(), filterParameter );
    assertEquals( entry.match( action, address, filterParameter ), true );
    assertEquals( entry.match( action, address, "OtherFilter" ), false );
    assertEquals( entry.match( AreaOfInterestAction.REMOVE, address, filterParameter ), false );
    assertEquals( entry.match( action, new ChannelAddress( G.G2, ValueUtil.randomInt() ), filterParameter ),
                  false );
  }

  @Test
  public void removeActionIgnoredFilterDuringMatch()
  {
    final ChannelAddress address = new ChannelAddress( G.G1 );
    final AreaOfInterestAction action = AreaOfInterestAction.REMOVE;

    final AreaOfInterestEntry entry = new AreaOfInterestEntry( address, action, null );

    assertEquals( entry.match( action, address, null ), true );
    assertEquals( entry.match( action, address, "OtherFilter" ), true );
    assertEquals( entry.match( AreaOfInterestAction.ADD, address, null ), false );
  }

  public enum G
  {
    G1, G2
  }
}

@@ -665,24 +665,83 @@
 , %22G:G1%22 );%0A
+    assertEquals( entry.toString(), %22AOI%5BChannel=G.G1%5D%22 );%0A
     assertEq
@@ -1171,16 +1171,654 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void toString_WithFilter()%0A  %7B%0A    final AreaOfInterestEntry entry =%0A      new AreaOfInterestEntry( new ChannelAddress( G.G1 ), AreaOfInterestAction.UPDATE, %22XXX%22 );%0A%0A    assertEquals( entry.toString(), %22AOI%5BChannel=G.G1,filter=XXX%5D%22 );%0A  %7D%0A%0A  @Test%0A  public void toString_NamingDisabled()%0A  %7B%0A    ReplicantTestUtil.disableNames();%0A    final AreaOfInterestEntry entry =%0A      new AreaOfInterestEntry( new ChannelAddress( G.G1 ), AreaOfInterestAction.UPDATE, %22XXX%22 );%0A%0A    assertEquals( entry.toString(),%0A                  %22replicant.AreaOfInterestEntry@%22 + Integer.toHexString( System.identityHashCode( entry ) ) );%0A  %7D%0A%0A
   @Test%0A

Add tests to cover toString