package router.client.location;

import javax.annotation.Nonnull;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class LocationPatternTest
{
  @DataProvider( name = "pathToRegex" )
  public static Object[][] pathToRegexData()
  {
    return new Object[][]{
      { "X", "^X$" },
      { "/abc/1!", "^\\/abc\\/1!$" },
      { "/+$#-?()[]{}.*\\", "^\\/\\+\\$#\\-\\?\\(\\)\\[\\]\\{\\}\\.\\*\\\\$" },
      };
  }

  @Test( dataProvider = "pathToRegex" )
  public void pathToPattern( @Nonnull final String path, @Nonnull final String expected )
    throws Exception
  {
    assertEquals( LocationPattern.pathToPattern( path ), expected );
  }

  @Test
  public void toKey()
  {
    final String[] parameterKeys = { "a", null, "c" };
    final LocationPattern pattern = new LocationPattern( new TestRegExp(), parameterKeys );
    assertEquals( pattern.toKey( 0 ), "a" );
    assertEquals( pattern.toKey( 1 ), "p1" );
    assertEquals( pattern.toKey( 2 ), "c" );
    assertEquals( pattern.toKey( 3 ), "p3" );
  }
}

@@ -41,27 +41,103 @@
 java
-x.annotation.Nonnul
+.util.Map;%0Aimport javax.annotation.Nonnull;%0Aimport org.realityforge.guiceyloops.shared.ValueUti
 l;%0Ai
@@ -707,24 +707,24 @@
 ception%0A  %7B%0A
-
     assertEq
@@ -781,24 +781,1337 @@
 ted );%0A  %7D%0A%0A
+  @Test%0A  public void match()%0A  %7B%0A    final String location = ValueUtil.randomString();%0A    final String%5B%5D results = %7B location, %22a%22, %22b%22, %22c%22 %7D;%0A    final String%5B%5D parameterKeys = %7B %22param0%22, null, %22param2%22, %22param3%22 %7D;%0A    final LocationPattern pattern = new LocationPattern( new TestRegExp( results ), parameterKeys );%0A    final Map%3CString, Object%3E matchData = pattern.match( location );%0A    assertNotNull( matchData );%0A    assertEquals( matchData.size(), 3 );%0A    assertEquals( matchData.get( %22param0%22 ), %22a%22 );%0A    assertEquals( matchData.get( %22p1%22 ), %22b%22 );%0A    assertEquals( matchData.get( %22param2%22 ), %22c%22 );%0A  %7D%0A%0A  @Test%0A  public void match_withNoGroupsInMatch()%0A  %7B%0A    final String location = ValueUtil.randomString();%0A    final String%5B%5D results = %7B location %7D;%0A    final String%5B%5D parameterKeys = %7B%7D;%0A    final LocationPattern pattern = new LocationPattern( new TestRegExp( results ), parameterKeys );%0A    final Map%3CString, Object%3E matchData = pattern.match( location );%0A    assertNotNull( matchData );%0A    assertEquals( matchData.size(), 0 );%0A  %7D%0A%0A  @Test%0A  public void match_noMatch()%0A  %7B%0A    final LocationPattern pattern = new LocationPattern( new TestRegExp(), new String%5B%5D%7B%7D );%0A    final Map%3CString, Object%3E matchData = pattern.match( ValueUtil.randomString() );%0A    assertNull( matchData );%0A  %7D%0A%0A
   @Test%0A  pu

Add some further tests around location pattern