Top Description Fields Constructors Methods
org.assertj.core.util.introspection

public Class MethodSupport

extends Object
Class Inheritance
Static Imports
java.lang.String.format, java.util.Objects.requireNonNull, org.assertj.core.util.Preconditions.checkArgument, .Preconditions.checkNotNullOrEmpty

Utility class for reflective method invocation.
Author
Michał Piotrkowski

Field Summary

Modifier and TypeField and Description
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
assertHasReturnType(Class<?> itemClass, Method method)

private static Method
findMethod(String methodName, Class<?> itemClass)

private static Object
invokeMethod(Object item, Method method)

public static Object

Returns:

result of method invocation
methodResultFor
(Object
object on which
instance
,
String
name of method to be invoked
methodName
)

Returns result of given method invocation on provided object.

private static IllegalArgumentException
prepareMethodNotFoundException(String methodName, Class<?> itemClass, Exception cause)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

METHOD_HAS_NO_RETURN_VALUEback to summary
private static final String METHOD_HAS_NO_RETURN_VALUE
METHOD_NOT_FOUNDback to summary
private static final String METHOD_NOT_FOUND

Constructor Detail

MethodSupportback to summary
public MethodSupport()

Method Detail

assertHasReturnTypeback to summary
private static void assertHasReturnType(Class<?> itemClass, Method method)
findMethodback to summary
private static Method findMethod(String methodName, Class<?> itemClass)
invokeMethodback to summary
private static Object invokeMethod(Object item, Method method)
methodResultForback to summary
public static Object methodResultFor(Object instance, String methodName)

Returns result of given method invocation on provided object.

Following requirements have to be met to extract method results:

  • method has to be public,
  • method cannot accept any arguments,
  • method cannot return void.
Parameters
instance:Object

object on which

methodName:String

name of method to be invoked

Returns:Object

result of method invocation

Exceptions
IllegalArgumentException:
if method does not exist or is not public, method returns void or method accepts any argument
prepareMethodNotFoundExceptionback to summary
private static IllegalArgumentException prepareMethodNotFoundException(String methodName, Class<?> itemClass, Exception cause)