### Question:
StrVar extends AbstractVarType<String> { public static StrVar strVar(String id) { return new StrVar(id); } private  StrVar(String id); private  StrVar(String id, String pattern); static StrVar strVar(String id); static StrVar strVar(String id, String regex); @Override String convert(String value);  }### Answer:
@Test public void whenKeyIsWellSetThenValueIsCorrect() { RestParser parser = parser("/country/{}/cities", strVar("countryId")); RestUrl url = parser.parse("http: assertThat(url, isValid()); assertThat((String) url.variable("countryId"), is("99")); }
@Test public void whenVariableIsEmptyThenUrlIsValid() { RestParser parser = parser("/country/{}/cities", strVar("countryId")); RestUrl url = parser.parse("http: assertThat(url, isValid()); assertThat((String) url.variable("countryId"), is("")); }
@Test public void whenRegexDoesNotMatchThenUrlIsInvalid() { RestParser parser = parser("/users/{}", strVar("userId", "\\d{2}-\\d{3}")); RestUrl url = parser.parse("http: assertThat(url, isInvalid()); }
@Test public void whenRegexMatchThenValueIsCorrect() { RestParser parser = parser("/users/{}/emails", strVar("userId", "\\d{2}-\\d{3}")); RestUrl url = parser.parse("http: assertThat(url, isValid()); assertThat((String) url.variable("userId"), is("34-834")); }