DATACMNS-1199 - Added PropertyPath.nested(…).
This allows to obtain a nested property path based on a currently available one.
This commit is contained in:
@@ -195,6 +195,21 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
|||||||
return isCollection;
|
return isCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link PropertyPath} for the path nested under the current property.
|
||||||
|
*
|
||||||
|
* @param path must not be {@literal null} or empty.
|
||||||
|
* @return will never be {@literal null}.
|
||||||
|
*/
|
||||||
|
public PropertyPath nested(String path) {
|
||||||
|
|
||||||
|
Assert.hasText(path, "Path must not be null or empty!");
|
||||||
|
|
||||||
|
String lookup = toDotPath().concat(".").concat(path);
|
||||||
|
|
||||||
|
return PropertyPath.from(lookup, owningType);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see java.lang.Iterable#iterator()
|
* @see java.lang.Iterable#iterator()
|
||||||
|
|||||||
@@ -355,6 +355,20 @@ public class PropertyPathUnitTests {
|
|||||||
assertThat(from("user.name", Bar.class).getLeafType()).isEqualTo(String.class);
|
assertThat(from("user.name", Bar.class).getLeafType()).isEqualTo(String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATACMNS-1199
|
||||||
|
public void createsNestedPropertyPath() {
|
||||||
|
assertThat(from("user", Bar.class).nested("name")).isEqualTo(from("user.name", Bar.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATACMNS-1199
|
||||||
|
public void rejectsNonExistantNestedPath() {
|
||||||
|
|
||||||
|
assertThatExceptionOfType(PropertyReferenceException.class) //
|
||||||
|
.isThrownBy(() -> from("user", Bar.class).nested("nonexistant")) //
|
||||||
|
.withMessageContaining("nonexistant") //
|
||||||
|
.withMessageContaining("Bar.user");
|
||||||
|
}
|
||||||
|
|
||||||
private class Foo {
|
private class Foo {
|
||||||
|
|
||||||
String userName;
|
String userName;
|
||||||
|
|||||||
Reference in New Issue
Block a user