Class MethodSource

  • All Implemented Interfaces:
    java.io.Serializable, TestSource

    @API(status=STABLE,
         since="1.0")
    public class MethodSource
    extends java.lang.Object
    implements TestSource
    Method based TestSource.

    This class stores the method name along with the names of its parameter types because Method does not implement Serializable.

    Since:
    1.0
    See Also:
    MethodSelector, Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      static MethodSource from​(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)
      Create a new MethodSource using the supplied class and method.
      static MethodSource from​(java.lang.reflect.Method testMethod)
      Create a new MethodSource using the supplied method.
      static MethodSource from​(java.lang.String className, java.lang.String methodName)
      Create a new MethodSource using the supplied class name and method name.
      static MethodSource from​(java.lang.String className, java.lang.String methodName, java.lang.Class<?>... methodParameterTypes)
      Create a new MethodSource using the supplied class name, method name, and method parameter types.
      static MethodSource from​(java.lang.String className, java.lang.String methodName, java.lang.String methodParameterTypes)
      Create a new MethodSource using the supplied class name, method name, and method parameter types.
      java.lang.String getClassName()
      Get the class name of this source.
      java.lang.Class<?> getJavaClass()
      Get the Java class of this source.
      java.lang.reflect.Method getJavaMethod()
      Get the Java method of this source.
      java.lang.String getMethodName()
      Get the method name of this source.
      java.lang.String getMethodParameterTypes()
      Get the method parameter types of this source.
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • from

        public static MethodSource from​(java.lang.String className,
                                        java.lang.String methodName)
        Create a new MethodSource using the supplied class name and method name.
        Parameters:
        className - the class name; must not be null or blank
        methodName - the method name; must not be null or blank
      • from

        public static MethodSource from​(java.lang.String className,
                                        java.lang.String methodName,
                                        java.lang.String methodParameterTypes)
        Create a new MethodSource using the supplied class name, method name, and method parameter types.
        Parameters:
        className - the class name; must not be null or blank
        methodName - the method name; must not be null or blank
        methodParameterTypes - a comma-separated list of fully qualified class names representing the method parameter types
      • from

        @API(status=STABLE,
             since="1.5")
        public static MethodSource from​(java.lang.String className,
                                        java.lang.String methodName,
                                        java.lang.Class<?>... methodParameterTypes)
        Create a new MethodSource using the supplied class name, method name, and method parameter types.
        Parameters:
        className - the class name; must not be null or blank
        methodName - the method name; must not be null or blank
        methodParameterTypes - a varargs array of classes representing the method parameter types
        Since:
        1.5
      • from

        public static MethodSource from​(java.lang.reflect.Method testMethod)
        Create a new MethodSource using the supplied method.
        Parameters:
        testMethod - the Java method; must not be null
        See Also:
        from(Class, Method)
      • from

        @API(status=STABLE,
             since="1.3")
        public static MethodSource from​(java.lang.Class<?> testClass,
                                        java.lang.reflect.Method testMethod)
        Create a new MethodSource using the supplied class and method.

        This method should be used in favor of from(Method) if the test method is inherited from a superclass or present as an interface default method.

        Parameters:
        testClass - the Java class; must not be null
        testMethod - the Java method; must not be null
        Since:
        1.3
      • getClassName

        public java.lang.String getClassName()
        Get the class name of this source.
      • getMethodName

        public final java.lang.String getMethodName()
        Get the method name of this source.
      • getMethodParameterTypes

        public final java.lang.String getMethodParameterTypes()
        Get the method parameter types of this source.
      • getJavaClass

        @API(status=STABLE,
             since="1.7")
        public final java.lang.Class<?> getJavaClass()
        Get the Java class of this source.

        If the Class was not provided, but only the name, this method attempts to lazily load the Class based on its name and throws a PreconditionViolationException if the class cannot be loaded.

        Since:
        1.7
        See Also:
        getClassName()
      • getJavaMethod

        @API(status=STABLE,
             since="1.7")
        public final java.lang.reflect.Method getJavaMethod()
        Get the Java method of this source.

        If the Method was not provided, but only the name, this method attempts to lazily load the Method based on its name and throws a PreconditionViolationException if the method cannot be loaded.

        Since:
        1.7
        See Also:
        getMethodName()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object