@ -27,6 +27,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap ;
import org.springframework.util.MultiValueMap ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException ;
/ * *
/ * *
* Unit tests for { @link DefaultPathContainer } .
* Unit tests for { @link DefaultPathContainer } .
@ -111,15 +112,18 @@ public class DefaultPathContainerTests {
testPath ( "//%20/%20" , "//%20/%20" , Arrays . asList ( "/" , "/" , "%20" , "/" , "%20" ) ) ;
testPath ( "//%20/%20" , "//%20/%20" , Arrays . asList ( "/" , "/" , "%20" , "/" , "%20" ) ) ;
}
}
private void testPath ( String input , String value , List < String > expectedElements ) {
private void testPath ( String input , String separator , String value , List < String > expectedElements ) {
PathContainer path = PathContainer . parsePath ( input , separator ) ;
PathContainer path = PathContainer . parsePath ( input ) ;
assertThat ( path . value ( ) ) . as ( "value: '" + input + "'" ) . isEqualTo ( value ) ;
assertThat ( path . value ( ) ) . as ( "value: '" + input + "'" ) . isEqualTo ( value ) ;
assertThat ( path . elements ( ) . stream ( )
assertThat ( path . elements ( ) . stream ( )
. map ( PathContainer . Element : : value ) . collect ( Collectors . toList ( ) ) ) . as ( "elements: " + input ) . isEqualTo ( expectedElements ) ;
. map ( PathContainer . Element : : value ) . collect ( Collectors . toList ( ) ) ) . as ( "elements: " + input ) . isEqualTo ( expectedElements ) ;
}
}
private void testPath ( String input , String value , List < String > expectedElements ) {
testPath ( input , "/" , value , expectedElements ) ;
}
@Test
@Test
public void subPath ( ) throws Exception {
public void subPath ( ) throws Exception {
// basic
// basic
@ -137,4 +141,14 @@ public class DefaultPathContainerTests {
assertThat ( path . subPath ( 2 ) . value ( ) ) . isEqualTo ( "/b/" ) ;
assertThat ( path . subPath ( 2 ) . value ( ) ) . isEqualTo ( "/b/" ) ;
}
}
@Test
public void pathWithCustomSeparator ( ) throws Exception {
testPath ( "a.b.c" , "." , "a.b.c" , Arrays . asList ( "a" , "." , "b" , "." , "c" ) ) ;
}
@Test
public void emptySeparator ( ) {
assertThatIllegalArgumentException ( ) . isThrownBy ( ( ) - > PathContainer . parsePath ( "path" , "" ) ) ;
}
}
}