Package com.ocs.dynamo.test
Class MockUtil
- java.lang.Object
-
- com.ocs.dynamo.test.MockUtil
-
public final class MockUtil extends Object
Utility class for registering service and DAO related mock functionality- Author:
- bas.rutten
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <ID,X extends AbstractEntity<ID>>
XcaptureSave(BaseDao<ID,X> dao, Class<X> clazz)Capture a call of the "save" method on a DAOstatic <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 DAOstatic <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 DAOstatic <ID,X extends AbstractEntity<ID>>
XcaptureServiceSave(BaseService<ID,X> service, Class<X> clazz)Capture the call of the "save" method on a servicestatic <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 entitiesstatic <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 servicestatic voidinjectMessageService(Object target, String basename)Util method to initialize the messageservice and inject it into the target object when @Inject can not be used.static voidinjectUI(Object object, Object ui)Injects a mocked Vaadin UI into an objectstatic <ID,X extends AbstractEntity<ID>>
voidmockFetchById(BaseDao<ID,X> dao, ID id, X entity)Mocks the "fetchById" method of a DAO by returning the provided entitystatic voidmockMessageService(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 parameterstatic <ID,X extends AbstractEntity<ID>>
voidmockSave(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 wellstatic <ID,X extends AbstractEntity<ID>>
voidmockSaveList(BaseDao<ID,X> dao)Mock the saving of a list on a DAOstatic <ID,U extends AbstractEntity<ID>>
voidmockServiceSave(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 wellstatic <ID,X extends AbstractEntity<ID>>
voidmockServiceSaveList(BaseService<ID,X> service)Mock the saving of a list on a DAOstatic voidregisterMocks(org.springframework.beans.factory.config.ConfigurableListableBeanFactory factory, Object subject)Registers all fields that are annotated with "@Mock" as beans in the Spring contextstatic voidregisterMocks(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
-
-
-
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 DAOclazz- 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 DAOtimes- 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 servicetimes- 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 MessageServicebasename- 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 fieldui- 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 calledclazz- 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-
-
-