I have a logger service that has a ScopeStorage and a LoggerServiceDAO dependency and in my unit test I need to override these to use mock objects I have created. I am using Wirebox AOP to trigger the logging events so I can not just create a mock object and pass it into the constructor of the CustomerContact object
Here is the mocks I am creating:
scopeStorageMock = mockBox.createMock('system.ScopeStorage').$('get', 111);
loggerServiceDAOMock = mockBox.createMock('system.services.daos.loggerServiceDAO').$('insertLog');
Inside my Wirebox binder I have the following mappings:
map('CustomerContact').to('models.Customer.CustomerContactBean');
map('LoggerServiceDAO').to('system.Services.DAOs.LoggerServiceDAO');
map('ScopeStorage').to('system.ScopeStorage');
map('CustomerContactLogger').to('models.customer.loggers.CustomerContactLogger');
mapAspect("CustomerAspect").to('models.CustomerAspect');
bindAspect(classes=match().mappings("CustomerContact"), methods=match().methods(['create','delete', 'update']), aspects="CustomerContactLogger");
Is there a way in my unit test to tell Wirebox that when it gets an instance of the CustomerAspect object to use the two mock objects I created with Mockbox?
I found the solution although it seems somewhat hacky but it works. Basically what I do is I tell Wirebox to unmap the existing
CustomerContactLoggerand then create aCustomerContactLoggerMockand inject all the Mocked properties. After that I create a new mapping of theCustomerContactLoggerand set the value equal to the mocked object.