Class MockUtil


  • public final class MockUtil
    extends Object
    Utility class for registering service and DAO related mock functionality
    Author:
    bas.rutten
    • Method Detail

      • captureSave

        public static <ID,​X extends AbstractEntity<ID>> X captureSave​(BaseDao<ID,​X> dao,
                                                                            Class<X> clazz)
        Capture a call of the "save" method on a DAO
        Parameters:
        dao - the DAO
        clazz - the class of the entity being saved
        Returns:
      • captureSaveList

        public static <ID,​X extends AbstractEntity<ID>> List<X> captureSaveList​(BaseDao<ID,​X> dao)
        Captures the call to the "save" method (that saves a list of entities) on a DAO
        Parameters:
        dao - the DAO that is being called
        Returns:
      • captureSaves

        public static <ID,​X extends AbstractEntity<ID>> List<X> captureSaves​(BaseDao<ID,​X> dao,
                                                                                   Class<X> clazz,
                                                                                   int times)
        Capture multipe calls to the "save" method on a DAO
        Parameters:
        dao - the DAO
        times - the desired number of method calls
      • captureServiceSave

        public static <ID,​X extends AbstractEntity<ID>> X captureServiceSave​(BaseService<ID,​X> service,
                                                                                   Class<X> clazz)
        Capture the call of the "save" method on a service
        Parameters:
        service - the service
        Returns:
      • captureServiceSaveList

        public static <ID,​X extends AbstractEntity<ID>> List<X> captureServiceSaveList​(BaseService<ID,​X> service)
        Capture the call to the "save" service method that accepts a list of entities
        Parameters:
        service - the service
      • captureServiceSaves

        public static <ID,​X extends AbstractEntity<ID>> List<X> captureServiceSaves​(BaseService<ID,​X> service,
                                                                                          Class<X> clazz,
                                                                                          int times)
        Capture multiple calls to the "save" method of a service
        Parameters:
        service - the service
        times - the number of times the method is supposed to be called
        Returns:
      • injectMessageService

        public static void injectMessageService​(Object target,
                                                String basename)
        Util method to initialize the messageservice and inject it into the target object when @Inject can not be used.
        Parameters:
        target - Object with the field messageService of type MessageService
        basename - the base name of the message bundle to use
      • injectUI

        public static void injectUI​(Object object,
                                    Object ui)
        Injects a mocked Vaadin UI into an object
        Parameters:
        field - the object into which to inject the field
        ui - the user interface
      • mockFetchById

        public static <ID,​X extends AbstractEntity<ID>> void mockFetchById​(BaseDao<ID,​X> dao,
                                                                                 ID id,
                                                                                 X entity)
        Mocks the "fetchById" method of a DAO by returning the provided entity
      • mockMessageService

        public static void mockMessageService​(MessageService messageService)
        Set up the message service to simply return the first argument passed to it - this allows for easily checking if the message service is called with the correct parameter
        Parameters:
        messageService -
      • mockSave

        public static <ID,​X extends AbstractEntity<ID>> void mockSave​(BaseDao<ID,​X> dao,
                                                                            Class<X> clazz)
        Mocks a DAO save operation, making sure that the argument that is passed to the method is returned from the method as well
        Parameters:
        dao - the DAO that must be called
        clazz - the class of the entity
      • mockSaveList

        public static <ID,​X extends AbstractEntity<ID>> void mockSaveList​(BaseDao<ID,​X> dao)
        Mock the saving of a list on a DAO
        Parameters:
        dao - the DAO
      • mockServiceSave

        public static <ID,​U extends AbstractEntity<ID>> void mockServiceSave​(BaseService<ID,​U> service,
                                                                                   Class<U> clazz)
        Mocks a service save operation, making sure that the argument that is passed to the method is returned from the method as well
        Parameters:
        service - the service
      • mockServiceSaveList

        public static <ID,​X extends AbstractEntity<ID>> void mockServiceSaveList​(BaseService<ID,​X> service)
        Mock the saving of a list on a DAO
        Parameters:
        dao - the DAO
      • registerMocks

        public static void registerMocks​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory factory,
                                         Object subject)
        Registers all fields that are annotated with "@Mock" as beans in the Spring context
        Parameters:
        factory -
        subject -
      • registerMocks

        public static void registerMocks​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory factory,
                                         Object subject,
                                         Class<?> clazz)
        Registers all fields that are annotated with "@Mock" as beans in the Spring context
        Parameters:
        factory -
        subject -
        clazz -