Hi,
I started using mockConstruction and it works well, but i'm wondering if there is an easier way to do what i'm doing. I atteched a whole test - but it comes down to this code:
Car car1 = mock(Car.class);
Car car2 = mock(Car.class);
MockedConstruction<Car> carMockedConstruction = Mockito.mockConstruction(Car.class, context -> {
Car car = context.arguments().get(0).equals("1") ? car1 : car2;
return Mockito.withSettings().defaultAnswer(i -> i.getMethod().invoke(car, i.getArguments()));
});
So basically, based on constructor argument, I want to return different mock, this part is fine, but is there a cleaner way to do "Mockito.withSettings().defaultAnswer(i -> i.getMethod().invoke(car, i.getArguments()));
});"
It works, but it doesnt' seem very natural.
Thank you for the great library !