Class PropertySupport
- java.lang.Object
-
- org.assertj.core.util.introspection.PropertySupport
-
public class PropertySupport extends Object
Utility methods for properties access.- Author:
- Joel Costigliola, Alex Ruiz, Nicolas François, Florent Biville
-
-
Field Summary
Fields Modifier and Type Field Description private static PropertySupportINSTANCEprivate static StringSEPARATOR
-
Constructor Summary
Constructors Constructor Description PropertySupport()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PropertySupportinstance()Returns the singleton instance of this class.private booleanisNestedProperty(String propertyName)private StringnextPropertyNameFrom(String propertyNameChain)private StringpopPropertyNameFrom(String propertyNameChain)<T> TpropertyValue(String propertyName, Class<T> clazz, Object target)Return the value of a simple property from a target object.<T> TpropertyValueOf(String propertyName, Class<T> clazz, Object target)Returns the value of the given property name given target.static <T> TpropertyValueOf(String propertyName, Object target, Class<T> clazz)Static variant ofpropertyValueOf(String, Class, Object)for syntactic sugar.<T> List<T>propertyValues(String propertyName, Class<T> clazz, Iterable<?> target)List<Object>propertyValues(String fieldOrPropertyName, Iterable<?> target)booleanpublicGetterExistsFor(String fieldName, Object actual)private <T> List<T>simplePropertyValues(String propertyName, Class<T> clazz, Iterable<?> target)
-
-
-
Field Detail
-
SEPARATOR
private static final 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> List<T> propertyValues(String propertyName, Class<T> clazz, Iterable<?> target)
Returns acontaining the values of the given property name, from the elements of the givenList. If the givenIterableIterableis empty ornull, this method will return an emptyList. This method supports nested properties (e.g. "address.street.number").- Type Parameters:
T- the type of the extracted elements.- Parameters:
propertyName- the name of the property. It may be a nested property. It is left to the clients to validate fornullor empty.clazz- type of propertytarget- the givenIterable.- Returns:
- an
Iterablecontaining the values of the given property name, from the elements of the givenIterable. - Throws:
IntrospectionError- if an element in the givenIterabledoes not have a property with a matching name.
-
propertyValueOf
public static <T> T propertyValueOf(String propertyName, Object target, Class<T> clazz)
Static variant ofpropertyValueOf(String, Class, Object)for syntactic sugar.- Type Parameters:
T- the type of the extracted elements.- Parameters:
propertyName- the name of the property. It may be a nested property. It is left to the clients to validate fornullor 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> List<T> simplePropertyValues(String propertyName, Class<T> clazz, Iterable<?> target)
-
isNestedProperty
private boolean isNestedProperty(String propertyName)
-
propertyValue
public <T> T propertyValue(String propertyName, Class<T> clazz, 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)- Type Parameters:
T- the type of the extracted value.- Parameters:
propertyName- the name of the property. It may be a nested property. It is left to the clients to validate fornullor 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(String propertyName, Class<T> clazz, 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").- Type Parameters:
T- the type of the extracted value.- Parameters:
propertyName- the name of the property. It may be a nested property. It is left to the clients to validate fornullor 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.IllegalArgumentException- if propertyName is null.
-
propertyValues
public List<Object> propertyValues(String fieldOrPropertyName, Iterable<?> target)
Returns acontaining the values of the given property name, from the elements of the givenList. If the givenIterableIterableis empty ornull, this method will return an emptyList. This method supports nested properties (e.g. "address.street.number").- Parameters:
fieldOrPropertyName- the name of the property. It may be a nested property. It is left to the clients to validate fornullor empty.target- the givenIterable.- Returns:
- an
Iterablecontaining the values of the given property name, from the elements of the givenIterable. - Throws:
IntrospectionError- if an element in the givenIterabledoes not have a property with a matching name.
-
-