// Path: url/src/main/java/com/danisola/restify/url/RestParserFactory.java
// public static RestParser parser(String pattern, VarType... types) {
//     checkPattern(pattern);
// 
//     final int numTypes = types.length;
//     ParsedUrl parsedUrl = parseUrl(pattern);
//     StringBuilder sb = new StringBuilder();
// 
//     // Processing path
//     int typesIndex = processMarkers(types, 0, sb, parsedUrl.getPath());
//     Pattern pathPattern = Pattern.compile(sb.toString());
//     VarType[] pathTypes = Arrays.copyOfRange(types, 0, typesIndex);
// 
//     // Processing parameters
//     List<NameValuePair> params = parsedUrl.getParameters();
//     ParamVar[] paramVars = new ParamVar[params.size()];
//     int paramVarCounter = 0;
//     for (int i = 0; i < paramVars.length; i++) {
//         NameValuePair pair = params.get(i);
// 
//         int newTypesIndex = processMarkers(types, typesIndex, sb, pair.getValue());
//         checkState(newTypesIndex > typesIndex, "Parameter '%s' has no variables in its value", pair.getName());
// 
//         VarType[] paramTypes = Arrays.copyOfRange(types, typesIndex, newTypesIndex);
//         Pattern paramValuePattern = Pattern.compile(sb.toString());
//         paramVars[i] = new ParamVar(pair.getName(), paramTypes, paramValuePattern);
//         paramVarCounter += newTypesIndex - typesIndex;
//         typesIndex = newTypesIndex;
//     }
// 
//     final int numVars = pathTypes.length + paramVarCounter;
//     checkState(numVars == numTypes, "The number of variables (%d) and types (%d) do not match", numVars, numTypes);
//     return new RestParser(pathPattern, pathTypes, paramVars, numTypes);
// }
// 
// Path: url/src/test/java/com/danisola/restify/url/matchers/IsInvalid.java
// public static IsInvalid isInvalid() {
//     return new IsInvalid();
// }
// 
// Path: url/src/test/java/com/danisola/restify/url/matchers/IsValid.java
// public static IsValid isValid() {
//     return new IsValid();
// }
// 
// Path: url/src/main/java/com/danisola/restify/url/types/FloatVar.java
// public static FloatVar floatVar(String id) {
//     return new FloatVar(id);
// }
// 
// Path: url/src/main/java/com/danisola/restify/url/types/IntVar.java
// public static IntVar intVar(String id) {
//     return new IntVar(id);
// }
// 
// Path: url/src/main/java/com/danisola/restify/url/types/StrVar.java
// public static StrVar strVar(String id) {
//     return new StrVar(id);
// }


import org.junit.Test;
import java.net.URL;
import static com.danisola.restify.url.RestParserFactory.parser;
import static com.danisola.restify.url.matchers.IsInvalid.isInvalid;
import static com.danisola.restify.url.matchers.IsValid.isValid;
import static com.danisola.restify.url.types.FloatVar.floatVar;
import static com.danisola.restify.url.types.IntVar.intVar;
import static com.danisola.restify.url.types.StrVar.strVar;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertTrue;
        assertThat(url, isValid());
        assertThat((String) url.variable("char"), is("B"));
        assertThat((Integer) url.variable("num"), is(7));
    }

    @Test
    public void whenNoVariablesAreProvidedThenOnlyThePathIsConsidered() {
        RestParser parser = parser("/users");
        RestUrl url = parser.parse("http://www.social-network.com/users");
        assertThat(url, isValid());
        assertTrue(url.isValid());
    }

    @Test
    public void whenThereAreExtraParametersThenSpecifiedOnesAreCorrect() {
        RestParser parser = parser("/users?id={}", strVar("userId"));
        RestUrl url = parser.parse("http://www.mail.com/users?cache_buster=4f0ce72&id=ben");
        assertThat(url, isValid());
        assertThat((String) url.variable("userId"), is("ben"));
    }

    @Test
    public void whenVariablesDoNotMatchTheWholeValueThenUrlIsInvalid() {
        RestParser parser = parser("/friends?within={}", intVar("kms"));
        RestUrl url = parser.parse("http://www.network.com/friends?within=4K");
        assertThat(url, isInvalid());
    }

    @Test
    public void whenWrongUrlIsProvidedThenUrlIsInvalid() {
// Path: url/src/main/java/com/danisola/restify/url/RestParserFactory.java
// public static RestParser parser(String pattern, VarType... types) {
//     checkPattern(pattern);
// 
//     final int numTypes = types.length;
//     ParsedUrl parsedUrl = parseUrl(pattern);
//     StringBuilder sb = new StringBuilder();
// 
//     // Processing path
//     int typesIndex = processMarkers(types, 0, sb, parsedUrl.getPath());
//     Pattern pathPattern = Pattern.compile(sb.toString());
//     VarType[] pathTypes = Arrays.copyOfRange(types, 0, typesIndex);
// 
//     // Processing parameters
//     List<NameValuePair> params = parsedUrl.getParameters();
//     ParamVar[] paramVars = new ParamVar[params.size()];
//     int paramVarCounter = 0;
//     for (int i = 0; i < paramVars.length; i++) {
//         NameValuePair pair = params.get(i);
// 
//         int newTypesIndex = processMarkers(types, typesIndex, sb, pair.getValue());
//         checkState(newTypesIndex > typesIndex, "Parameter '%s' has no variables in its value", pair.getName());
// 
//         VarType[] paramTypes = Arrays.copyOfRange(types, typesIndex, newTypesIndex);
//         Pattern paramValuePattern = Pattern.compile(sb.toString());
//         paramVars[i] = new ParamVar(pair.getName(), paramTypes, paramValuePattern);
//         paramVarCounter += newTypesIndex - typesIndex;
//         typesIndex = newTypesIndex;
//     }
// 
//     final int numVars = pathTypes.length + paramVarCounter;
//     checkState(numVars == numTypes, "The number of variables (%d) and types (%d) do not match", numVars, numTypes);
//     return new RestParser(pathPattern, pathTypes, paramVars, numTypes);
// }
// 
// Path: url/src/test/java/com/danisola/restify/url/matchers/IsInvalid.java
// public static IsInvalid isInvalid() {
//     return new IsInvalid();
// }
// 
// Path: url/src/test/java/com/danisola/restify/url/matchers/IsValid.java
// public static IsValid isValid() {
//     return new IsValid();
// }
// 
// Path: url/src/main/java/com/danisola/restify/url/types/FloatVar.java
// public static FloatVar floatVar(String id) {
//     return new FloatVar(id);
// }
// 
// Path: url/src/main/java/com/danisola/restify/url/types/IntVar.java
// public static IntVar intVar(String id) {
//     return new IntVar(id);
// }
// 
// Path: url/src/main/java/com/danisola/restify/url/types/StrVar.java
// public static StrVar strVar(String id) {
//     return new StrVar(id);
// }


// Path: url/src/test/java/com/danisola/restify/url/RestUrlTest.java
import org.junit.Test;
import java.net.URL;
import static com.danisola.restify.url.RestParserFactory.parser;
import static com.danisola.restify.url.matchers.IsInvalid.isInvalid;
import static com.danisola.restify.url.matchers.IsValid.isValid;
import static com.danisola.restify.url.types.FloatVar.floatVar;
import static com.danisola.restify.url.types.IntVar.intVar;
import static com.danisola.restify.url.types.StrVar.strVar;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertTrue;

        assertThat(url, isValid());
        assertThat((String) url.variable("char"), is("B"));
        assertThat((Integer) url.variable("num"), is(7));
    }

    @Test
    public void whenNoVariablesAreProvidedThenOnlyThePathIsConsidered() {
        RestParser parser = parser("/users");
        RestUrl url = parser.parse("http://www.social-network.com/users");
        assertThat(url, isValid());
        assertTrue(url.isValid());
    }

    @Test
    public void whenThereAreExtraParametersThenSpecifiedOnesAreCorrect() {
        RestParser parser = parser("/users?id={}", strVar("userId"));
        RestUrl url = parser.parse("http://www.mail.com/users?cache_buster=4f0ce72&id=ben");
        assertThat(url, isValid());
        assertThat((String) url.variable("userId"), is("ben"));
    }

    @Test
    public void whenVariablesDoNotMatchTheWholeValueThenUrlIsInvalid() {
        RestParser parser = parser("/friends?within={}", intVar("kms"));
        RestUrl url = parser.parse("http://www.network.com/friends?within=4K");
        assertThat(url, isInvalid());
    }

    @Test
    public void whenWrongUrlIsProvidedThenUrlIsInvalid() {
        RestParser parser = parser("/leagues/{}/teams/{}/players/{}", strVar("leagueId"), strVar("teamId"), intVar("playerId"));