Class PropertySupport
- java.lang.Object
-
- org.assertj.core.util.introspection.PropertySupport
-
public class PropertySupport extends java.lang.Object
Utility methods for properties access.
-
-
Field Summary
Fields Modifier and Type Field Description private static PropertySupport
INSTANCE
private static java.lang.String
SEPARATOR
-
Constructor Summary
Constructors Constructor Description PropertySupport()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PropertySupport
instance()
Returns the singleton instance of this class.private boolean
isNestedProperty(java.lang.String propertyName)
isNestedProperty("address.street"); // true isNestedProperty("address.street.name"); // true isNestedProperty("person"); // false isNestedProperty(".name"); // false isNestedProperty("person."); // false isNestedProperty("person.name."); // false isNestedProperty(".person.name"); // false isNestedProperty("."); // false isNestedProperty(""); // false
private java.lang.String
nextPropertyNameFrom(java.lang.String propertyNameChain)
private java.lang.String
popPropertyNameFrom(java.lang.String propertyNameChain)
<T> T
propertyValue(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Object target)
Return the value of a simple property from a target object.<T> T
propertyValueOf(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Object target)
Returns the value of the given property name given target.static <T> T
propertyValueOf(java.lang.String propertyName, java.lang.Object target, java.lang.Class<T> clazz)
Static variant ofpropertyValueOf(String, Class, Object)
for syntactic sugar.<T> java.util.List<T>
propertyValues(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Iterable<?> target)
Returns a
containing the values of the given property name, from the elements of the givenList
.Iterable
java.util.List<java.lang.Object>
propertyValues(java.lang.String fieldOrPropertyName, java.lang.Iterable<?> objects)
just delegates topropertyValues(String, Class, Iterable)
with Class being Object.classboolean
publicGetterExistsFor(java.lang.String fieldName, java.lang.Object actual)
private <T> java.util.List<T>
simplePropertyValues(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Iterable<?> target)
-
-
-
Field Detail
-
SEPARATOR
private static final java.lang.String SEPARATOR
- See Also:
- Constant Field Values
-
INSTANCE
private static final PropertySupport INSTANCE
-
-
Method Detail
-
instance
public static PropertySupport instance()
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
propertyValues
public <T> java.util.List<T> propertyValues(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Iterable<?> target)
Returns a
containing the values of the given property name, from the elements of the givenList
. If the givenIterable
Iterable
is empty ornull
, this method will return an emptyList
. This method supports nested properties (e.g. "address.street.number").- Parameters:
propertyName
- the name of the property. It may be a nested property. It is left to the clients to validate fornull
or empty.target
- the givenIterable
.- Returns:
- an
Iterable
containing the values of the given property name, from the elements of the givenIterable
. - Throws:
IntrospectionError
- if an element in the givenIterable
does not have a property with a matching name.
-
propertyValueOf
public static <T> T propertyValueOf(java.lang.String propertyName, java.lang.Object target, java.lang.Class<T> clazz)
Static variant ofpropertyValueOf(String, Class, Object)
for syntactic sugar.- Parameters:
propertyName
- the name of the property. It may be a nested property. It is left to the clients to validate fornull
or empty.target
- the given objectclazz
- type of property- Returns:
- a the values of the given property name
- Throws:
IntrospectionError
- if the given target does not have a property with a matching name.
-
simplePropertyValues
private <T> java.util.List<T> simplePropertyValues(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Iterable<?> target)
-
popPropertyNameFrom
private java.lang.String popPropertyNameFrom(java.lang.String propertyNameChain)
-
nextPropertyNameFrom
private java.lang.String nextPropertyNameFrom(java.lang.String propertyNameChain)
-
isNestedProperty
private boolean isNestedProperty(java.lang.String propertyName)
isNestedProperty("address.street"); // true isNestedProperty("address.street.name"); // true isNestedProperty("person"); // false isNestedProperty(".name"); // false isNestedProperty("person."); // false isNestedProperty("person.name."); // false isNestedProperty(".person.name"); // false isNestedProperty("."); // false isNestedProperty(""); // false
-
propertyValue
public <T> T propertyValue(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Object target)
Return the value of a simple property from a target object.This only works for simple property, nested property are not supported ! use
propertyValueOf(String, Class, Object)
- Parameters:
propertyName
- the name of the property. It may be a nested property. It is left to the clients to validate fornull
or empty.target
- the given objectclazz
- type of property- Returns:
- a the values of the given property name
- Throws:
IntrospectionError
- if the given target does not have a property with a matching name.
-
propertyValueOf
public <T> T propertyValueOf(java.lang.String propertyName, java.lang.Class<T> clazz, java.lang.Object target)
Returns the value of the given property name given target. If the given object isnull
, this method will return null.
This method supports nested properties (e.g. "address.street.number").- Parameters:
propertyName
- the name of the property. It may be a nested property. It is left to the clients to validate fornull
or empty.clazz
- the class of property.target
- the given Object to extract property from.- Returns:
- the value of the given property name given target.
- Throws:
IntrospectionError
- if target object does not have a property with a matching name.java.lang.IllegalArgumentException
- if propertyName is null.
-
propertyValues
public java.util.List<java.lang.Object> propertyValues(java.lang.String fieldOrPropertyName, java.lang.Iterable<?> objects)
just delegates topropertyValues(String, Class, Iterable)
with Class being Object.class
-
publicGetterExistsFor
public boolean publicGetterExistsFor(java.lang.String fieldName, java.lang.Object actual)
-
-