Fix root path test and add more test cases

This commit is contained in:
Rossen Stoyanchev 2017-06-15 16:14:12 -04:00
parent 67e482aaf8
commit 4a21fb27fc
3 changed files with 10 additions and 3 deletions

View File

@ -190,13 +190,13 @@ class DefaultPathSegmentContainer implements PathSegmentContainer {
} }
static PathSegmentContainer subPath(PathSegmentContainer container, int fromIndex, int toIndex) { static PathSegmentContainer subPath(PathSegmentContainer container, int fromIndex, int toIndex) {
if (fromIndex == toIndex) {
return EMPTY_PATH;
}
List<PathSegment> segments = container.pathSegments(); List<PathSegment> segments = container.pathSegments();
if (fromIndex == 0 && toIndex == segments.size()) { if (fromIndex == 0 && toIndex == segments.size()) {
return container; return container;
} }
if (fromIndex == toIndex) {
return EMPTY_PATH;
}
Assert.isTrue(fromIndex < toIndex, "fromIndex: " + fromIndex + " should be < toIndex " + toIndex); Assert.isTrue(fromIndex < toIndex, "fromIndex: " + fromIndex + " should be < toIndex " + toIndex);
Assert.isTrue(fromIndex >= 0 && fromIndex < segments.size(), "Invalid fromIndex: " + fromIndex); Assert.isTrue(fromIndex >= 0 && fromIndex < segments.size(), "Invalid fromIndex: " + fromIndex);

View File

@ -130,6 +130,10 @@ public class DefaultPathSegmentContainerTests {
assertEquals("/b/c", PathSegmentContainer.subPath(path, 1).value()); assertEquals("/b/c", PathSegmentContainer.subPath(path, 1).value());
assertEquals("/c", PathSegmentContainer.subPath(path, 2).value()); assertEquals("/c", PathSegmentContainer.subPath(path, 2).value());
// root path
path = PathSegmentContainer.parse("/", UTF_8);
assertEquals("/", PathSegmentContainer.subPath(path, 0).value());
// trailing slash // trailing slash
path = PathSegmentContainer.parse("/a/b/", UTF_8); path = PathSegmentContainer.parse("/a/b/", UTF_8);
assertEquals("/b/", PathSegmentContainer.subPath(path, 1).value()); assertEquals("/b/", PathSegmentContainer.subPath(path, 1).value());

View File

@ -39,6 +39,9 @@ public class DefaultRequestPathTests {
// context path only // context path only
testRequestPath("/a/b", "/a/b", "", false, true, false); testRequestPath("/a/b", "/a/b", "", false, true, false);
// root path
testRequestPath("/", "", "/", false, true, false);
// empty path // empty path
testRequestPath("", "", "", true, false, false); testRequestPath("", "", "", true, false, false);
testRequestPath("", "/", "", true, false, false); testRequestPath("", "/", "", true, false, false);