My class under test is ClassA
which in one of its private method uses a static factory (lets say CarFactory
) method getCar(XXX xxx)
which returns a Car
.
Part of the CarFactory
logic is to validate that the given xxx parameters meets some criteria.
I tried using Mockito like the following:
@Mock private Car mockForCar;
@Mock private XXX xxxMock;
...
when(CarFactory.getCar(xxxMock)).thenReturn(mockForCar);
But I get an exception regarding that xxxMock isn't valid by the CarFactory
.
Why is the real getCar(xxx)
method gets called and not the stubbed one?
Is there a better way doing this?