Class DefaultClassInstantiator

  • All Implemented Interfaces:
    IClassInstantiator

    public class DefaultClassInstantiator
    extends java.lang.Object
    implements IClassInstantiator
    Default class instantiator that is pretty limited. It just hope that the mocked class has a public empty constructor.
    Author:
    Henri Tremblay
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object[] getArgsForTypes​(java.lang.Class<?>[] methodTypes)
      Get some default instances of provided classes
      java.lang.reflect.Constructor<?> getConstructorToUse​(java.lang.Class<?> clazz)
      Return the constructor considered the best to use with this class.
      java.lang.Object newInstance​(java.lang.Class<?> c)
      Try to instantiate a class without using a special constructor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultClassInstantiator

        public DefaultClassInstantiator()
    • Method Detail

      • newInstance

        public java.lang.Object newInstance​(java.lang.Class<?> c)
                                     throws java.lang.InstantiationException
        Try to instantiate a class without using a special constructor. See documentation for the algorithm.
        Specified by:
        newInstance in interface IClassInstantiator
        Parameters:
        c - Class to instantiate
        Returns:
        new instance of clazz
        Throws:
        java.lang.InstantiationException - when an error occured during instantiation
      • getConstructorToUse

        public java.lang.reflect.Constructor<?> getConstructorToUse​(java.lang.Class<?> clazz)
        Return the constructor considered the best to use with this class. Algorithm is: No args constructor and then first constructor defined in the class
        Parameters:
        clazz - Class in which constructor is searched
        Returns:
        Constructor to use
      • getArgsForTypes

        public java.lang.Object[] getArgsForTypes​(java.lang.Class<?>[] methodTypes)
                                           throws java.lang.InstantiationException
        Get some default instances of provided classes
        Parameters:
        methodTypes - Classes to instantiate
        Returns:
        Instances of methodTypes in order
        Throws:
        java.lang.InstantiationException - Thrown if the class instantiation fails