Fix unit tests

This commit is contained in:
BoykoAlex
2017-10-26 21:25:09 -04:00
parent 9631f56d0f
commit 4dfca0cebe
2 changed files with 16 additions and 6 deletions

View File

@@ -159,7 +159,17 @@ There are two styles of entries:
@Override
public String[] getSplitPath() {
String paths = requestPathSupplier.get();
return Arrays.stream(paths.split("\\|\\|")).map(s -> s.trim()).toArray(String[]::new);
return Arrays.stream(paths.split("\\|\\|"))
.map(s -> s.trim())
.filter(s -> !s.isEmpty())
.map(s -> {
if (s.charAt(0) != '/') {
return '/' + s;
} else {
return s;
}
})
.toArray(String[]::new);
}
@Override

View File

@@ -38,21 +38,21 @@ public class RequestMappingImp1Test {
@Test
public void testSplitPathSimpleCase() {
RequestMappingImpl1 rm = new RequestMappingImpl1("/superpath/mypath || mypath.json", null);
RequestMappingImpl1 rm = new RequestMappingImpl1("{[/superpath/mypath || mypath.json]}", null);
String[] splitPath = rm.getSplitPath();
assertEquals(2, splitPath.length);
assertEquals("/superpath/mypath", splitPath[0]);
assertEquals("/superpath/mypath.json", splitPath[1]);
assertEquals("/mypath.json", splitPath[1]);
}
@Test
public void testSplitPathMultipleCases() {
RequestMappingImpl1 rm = new RequestMappingImpl1("/superpath/mypath || mypath.json || somethingelse.what", null);
RequestMappingImpl1 rm = new RequestMappingImpl1("{[/superpath/mypath || mypath.json || somethingelse.what]}", null);
String[] splitPath = rm.getSplitPath();
assertEquals(3, splitPath.length);
assertEquals("/superpath/mypath", splitPath[0]);
assertEquals("/superpath/mypath.json", splitPath[1]);
assertEquals("/superpath/somethingelse.what", splitPath[2]);
assertEquals("/mypath.json", splitPath[1]);
assertEquals("/somethingelse.what", splitPath[2]);
}
}