Package reactor.test
Class ValueFormatters
java.lang.Object
reactor.test.ValueFormatters
An utility class to create
ValueFormatters.ToStringConverter Function that convert objects to String.
They can be applied to any Object but will restrict the types they actually
convert by filtering and defaulting to String.valueOf(Object).
Also defines ValueFormatters.Extractor BiFunction that extract multiple elements from
containers and applies a Function (most probably a ValueFormatters.ToStringConverter)
to its elements, reforming a complete String representation. Again, this matches
on at least a given Class and potentially an additional Predicate.
An additional static utility method convertVarArgs(ToStringConverter, Collection, Object...) can
be used to apply such functions and to varargs.
- Author:
- Simon Baslé
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn extractor of data wrapped in aBiFunctionaiming at producing a customizedStringrepresentation of a container type and its contained elements, each element being potentially itself converted toStringusing aValueFormatters.ToStringConverter: it only considers specific container types, seeValueFormatters.Extractor.getTargetClass()it can further filter these container instances usingValueFormatters.Extractor.matches(Object)it can be applied to arbitrary objects, as it will default toString.valueOf(Object)on non-matching containers it can apply aValueFormatters.ToStringConverterto the content, passed as the second parameter of theBiFunctionit reconstructs theStringrepresentation of the container byexplodingit and thenjoiningit with {#code ", "} delimiter, as well as customValueFormatters.Extractor.prefix(Object)andValueFormatters.Extractor.suffix(Object)static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ValueFormatters.ToStringConverterDefaultDurationValueFormatters.ToStringConverterthat removes the PT prefix and switchesto lower case. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ValueFormatters.Extractor<T[]>arrayExtractor(Class<T[]> arrayClass) Default array extractor that use the[CONVERTED1, CONVERTED2]representation.static <T> ValueFormatters.ToStringConverterstatic <T> ValueFormatters.ToStringConverterforClassMatching(Class<T> tClass, Predicate<T> tPredicate, Function<T, String> tToString) static ValueFormatters.Extractor<Iterable>DefaultIterableextractor that use the[CONVERTED1, CONVERTED2]representation.static ValueFormatters.Extractor<Signal>
-
Field Details
-
DURATION_CONVERTER
DefaultDurationValueFormatters.ToStringConverterthat removes the PT prefix and switchesto lower case.
-
-
Method Details
-
forClass
public static <T> ValueFormatters.ToStringConverter forClass(Class<T> tClass, Function<T, String> tToString) -
forClassMatching
public static <T> ValueFormatters.ToStringConverter forClassMatching(Class<T> tClass, Predicate<T> tPredicate, Function<T, String> tToString) Create a value formatter that is specific to a particularClassand filters based on a providedPredicate. All objects of said class that additionally pass thePredicateare converted toStringusing the provided conversionFunction.- Type Parameters:
T- the generic type of the matching objects- Parameters:
tClass- theClassto converttPredicate- thePredicateto further filter what to convert to stringtToString- theStringconversionFunctionfor objects of that class matching the predicate- Returns:
- the class-specific predicate-filtering formatter
-
filtering
public static ValueFormatters.ToStringConverter filtering(Predicate<Object> predicate, Function<Object, String> anyToString) -
signalExtractor
DefaultSignalextractor that unwraps onlyonNext. TheseSignalinstances have a Signal representation like so:"onNext(CONVERTED)".- Returns:
- the default
Signalextractor
-
iterableExtractor
DefaultIterableextractor that use the[CONVERTED1, CONVERTED2]representation.- Returns:
- the default
Iterableextractor
-
arrayExtractor
Default array extractor that use the[CONVERTED1, CONVERTED2]representation.- Type Parameters:
T- the type of the array- Parameters:
arrayClass- theClassrepresenting the array type- Returns:
- the default array extractor for arrays of T
-