How to mock constructor with mockito?

Viewed 26

I am struggling to create a unit test that successfully mocks this line:

WarehouseId warehouseId = new WarehouseId(currentState.getBuilding().getCode());

The issue is that an object is being created in the parameter. Any iteration of attempting to mock the constructor is met with a null pointer exception. The object in my test case is not being initialized. I know this because I am able to mock the function call successfully:

log.info(currentState.getBuilding().getCode());

I have read PowerMockito and MockConstruction are two options, however I am unable to add powerMockito, and we are using an earlier version of Mockito. Are there any other ways of doing this?

0 Answers
Related