package org.realityforge.arez.api2;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.realityforge.guiceyloops.shared.ValueUtil;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class NodeTest
  extends AbstractArezTest
{
  static class TestNode
    extends Node
  {
    TestNode( @Nonnull final ArezContext context,
              @Nullable final String name )
    {
      super( context, name );
    }
  }

  @Test
  public void basicOperation()
    throws Exception
  {
    final ArezContext context = new ArezContext();
    final String name = ValueUtil.randomString();
    final TestNode node = new TestNode( context, name );
    assertEquals( node.getName(), name );
    assertEquals( node.getContext(), context );
    assertEquals( node.toString(), name );
  }

  @Test
  public void basicOperation_namesDisabled()
    throws Exception
  {
    final ArezConfig.DynamicProvider provider = (ArezConfig.DynamicProvider) ArezConfig.getProvider();
    provider.setEnableNames( false );

    final ArezContext context = new ArezContext();
    final TestNode node = new TestNode( context, null );
    assertThrows( node::getName );
    assertEquals( node.getContext(), context );
    assertTrue( node.toString().startsWith( node.getClass().getName() + "@" ), "node.toString() == " + node );
  }
}

@@ -846,24 +846,27 @@
 oid 
-basicOperation_n
+noNameSuppliedWhenN
 ames
@@ -1348,11 +1348,365 @@
 e );%0A  %7D
+%0A%0A  @Test%0A  public void nameSuppliedWhenNamesDisabled()%0A    throws Exception%0A  %7B%0A    final ArezConfig.DynamicProvider provider = (ArezConfig.DynamicProvider) ArezConfig.getProvider();%0A    provider.setEnableNames( false );%0A%0A    final ArezContext context = new ArezContext();%0A    assertThrows( () -%3E new TestNode( context, ValueUtil.randomString() ) );%0A  %7D
 %0A%7D%0A

Test scenario where there is a failed assertion