DATAREST-93 - Further refactorings and refinements regarding the search resource mapping.
This commit is contained in:
@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
|
||||
public class Path {
|
||||
|
||||
private static final String SLASH = "/";
|
||||
private static final String MATCH_PATTERN = "/?%s";
|
||||
|
||||
private final String path;
|
||||
|
||||
@@ -48,6 +49,10 @@ public class Path {
|
||||
this.path = cleanUp ? cleanUp(path) : path;
|
||||
}
|
||||
|
||||
public boolean matches(String reference) {
|
||||
return this.path.matches(String.format(MATCH_PATTERN, reference));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the given {@link String} to the current {@link Path}.
|
||||
*
|
||||
|
||||
@@ -19,9 +19,10 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Path}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PathUnitTests {
|
||||
@@ -46,4 +47,19 @@ public class PathUnitTests {
|
||||
Path builder = new Path("foo/ ").slash("/ b a r").slash(" //foobar/// ");
|
||||
assertThat(builder.toString(), is("/foo/bar/foobar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWithLeadingSlash() {
|
||||
assertThat(new Path("/foobar").matches("/foobar"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWithoutLeadingSlash() {
|
||||
assertThat(new Path("/foobar").matches("foobar"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotMatchIfDifferent() {
|
||||
assertThat(new Path("/foobar").matches("barfoo"), is(false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user