DefaultParametersControl implements ParametersControl { public boolean matches(String uri) { return pattern.matcher(uri).matches(); } DefaultParametersControl(String originalPattern, Map<String, String> parameterPatterns, Converters converters, Evaluator evaluator);  DefaultParametersControl(String originalPattern, Converters converters, Evaluator evaluator); String fillUri(String[] paramNames, Object... paramValues); boolean matches(String uri); void fillIntoRequest(String uri, MutableRequest request); String apply(String[] values);  }
@Test public void worksWithBasicRegexEvaluation() throws SecurityException, NoSuchMethodException { DefaultParametersControl control = new DefaultParametersControl("/clients.*", converters, evaluator); assertThat(control.matches("/clientsWhatever"), is(equalTo(true))); }
@Test public void shouldMatchPatternLazily() throws Exception { DefaultParametersControl wrong = new DefaultParametersControl("/clients/{client.id}/", converters, evaluator); DefaultParametersControl right = new DefaultParametersControl("/clients/{client.id}/subtask/", converters, evaluator); String uri = "/clients/3/subtask/"; assertThat(wrong.matches(uri), is(false)); assertThat(right.matches(uri), is(true)); }
@Test public void shouldMatchMoreThanOneVariable() throws Exception { DefaultParametersControl control = new DefaultParametersControl("/clients/{client.id}/subtask/{task.id}/", converters, evaluator); assertThat(control.matches("/clients/3/subtask/5/"), is(true)); }
@Test public void shouldBeGreedyWhenIPutAnAsteriskOnExpression() throws Exception { DefaultParametersControl control = new DefaultParametersControl("/clients/{pathToFile*}", converters, evaluator); assertThat(control.matches("/clients/my/path/to/file/"), is(true)); }
@Test public void whenNoParameterPatternsAreGivenShouldMatchAnything() throws Exception { ParametersControl control = new DefaultParametersControl("/any/{aParameter}/what", Collections.<String,String>emptyMap(), converters, evaluator); assertTrue(control.matches("/any/ICanPutAnythingInHere/what")); }
@Test public void whenParameterPatternsAreGivenShouldMatchAccordingToGivenPatterns() throws Exception { ParametersControl control = new DefaultParametersControl("/any/{aParameter}/what", new ImmutableMap.Builder<String, String>().put("aParameter", "aaa\\d{3}bbb").build(), converters, evaluator); assertFalse(control.matches("/any/ICantPutAnythingInHere/what")); assertFalse(control.matches("/any/aaa12bbb/what")); assertTrue(control.matches("/any/aaa123bbb/what")); }
@Test public void worksAsRegexWhenUsingParameters() throws SecurityException, NoSuchMethodException { DefaultParametersControl control = new DefaultParametersControl("/clients/{dog.id}", converters, evaluator); assertThat(control.matches("/clients/15"), is(equalTo(true))); }