Class ByteBuddyClassImposteriser

  • All Implemented Interfaces:
    Imposteriser

    public class ByteBuddyClassImposteriser
    extends java.lang.Object
    implements Imposteriser
    This class lets you imposterise abstract and concrete classes without calling the constructors of the mocked class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Imposteriser INSTANCE  
      private static java.lang.String JMOCK_KEY  
      private org.objenesis.Objenesis objenesis  
      private java.util.Map<java.util.Set<java.lang.Class<?>>,​java.lang.Class<?>> types  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canImposterise​(java.lang.Class<?> type)
      Reports if the Imposteriser is able to imposterise a given type.
      private boolean defaultPackage​(java.lang.Class<?> mockedType)  
      <T> T imposterise​(Invokable mockObject, java.lang.Class<T> mockedType, java.lang.Class<?>... ancilliaryTypes)
      Creates an imposter for a given type that forwards Invocations to an Invokable object.
      private java.util.Set<java.lang.Class<?>> mockTypeKey​(java.lang.Class<?> mockedType, java.lang.Class<?>... ancilliaryTypes)  
      private boolean protectedPackageNameSpaces​(java.lang.Class<?> mockedType)  
      private <T> T proxy​(Invokable mockObject, java.lang.Class<T> mockedType, java.lang.Class<?>... ancilliaryTypes)  
      private java.lang.Class<?> proxyClass​(Invokable mockObject, java.lang.Class<?> mockedType, java.lang.Class<?>... ancilliaryTypes)  
      private void setConstructorsAccessible​(java.lang.Class<?> mockedType, boolean accessible)  
      private boolean toStringMethodIsFinal​(java.lang.Class<?> type)  
      • Methods inherited from class java.lang.Object

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

      • objenesis

        private final org.objenesis.Objenesis objenesis
      • types

        private final java.util.Map<java.util.Set<java.lang.Class<?>>,​java.lang.Class<?>> types
    • Constructor Detail

      • ByteBuddyClassImposteriser

        private ByteBuddyClassImposteriser()
    • Method Detail

      • canImposterise

        public boolean canImposterise​(java.lang.Class<?> type)
        Description copied from interface: Imposteriser
        Reports if the Imposteriser is able to imposterise a given type.
        Specified by:
        canImposterise in interface Imposteriser
        Parameters:
        type - The type in question.
        Returns:
        True if this imposteriser can imposterise type, false otherwise.
      • imposterise

        public <T> T imposterise​(Invokable mockObject,
                                 java.lang.Class<T> mockedType,
                                 java.lang.Class<?>... ancilliaryTypes)
        Description copied from interface: Imposteriser
        Creates an imposter for a given type that forwards Invocations to an Invokable object.
        Specified by:
        imposterise in interface Imposteriser
        Type Parameters:
        T - The static type of the imposter that is created.
        Parameters:
        mockObject - The object that is to receive invocations forwarded from the imposter.
        mockedType - The class representing the static type of the imposter.
        ancilliaryTypes - Other types for the imposter. It must be possible to dynamically cast the imposter to these types. These types must all be interfaces because Java only allows single inheritance of classes.
        Returns:
        A new imposter. The imposter must implement the mockedType and all the ancialliaryTypes.
      • toStringMethodIsFinal

        private boolean toStringMethodIsFinal​(java.lang.Class<?> type)
      • setConstructorsAccessible

        private void setConstructorsAccessible​(java.lang.Class<?> mockedType,
                                               boolean accessible)
      • proxy

        private <T> T proxy​(Invokable mockObject,
                            java.lang.Class<T> mockedType,
                            java.lang.Class<?>... ancilliaryTypes)
      • proxyClass

        private java.lang.Class<?> proxyClass​(Invokable mockObject,
                                              java.lang.Class<?> mockedType,
                                              java.lang.Class<?>... ancilliaryTypes)
                                       throws java.lang.ClassNotFoundException,
                                              java.lang.IllegalAccessException,
                                              java.lang.reflect.InvocationTargetException,
                                              java.lang.NoSuchMethodException
        Throws:
        java.lang.ClassNotFoundException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
        java.lang.NoSuchMethodException
      • mockTypeKey

        private java.util.Set<java.lang.Class<?>> mockTypeKey​(java.lang.Class<?> mockedType,
                                                              java.lang.Class<?>... ancilliaryTypes)
      • defaultPackage

        private boolean defaultPackage​(java.lang.Class<?> mockedType)
      • protectedPackageNameSpaces

        private boolean protectedPackageNameSpaces​(java.lang.Class<?> mockedType)