I am trying to make a unit test with Mockito and I cannot find any way to mock my constructor's optional autowired field.
Here is my constructor:
@Autowired
public BatchInputManager(
BatchInputContentRepository batchInputContentRepository,
Optional<List<BatchInputExecutor>> batchInputExecutors) {
// ...
}
And here is how I try to mock these fields :
@InjectMocks
BatchInputManager batchInputManager;
@Mock
BatchInputContentRepository batchInputContentRepository;
@Mock
List<BatchInputExecutor> executors;
For the record, the BatchInputExecutor
class is an abstract class and I defined a class that extends it in my test.
When I run my code, the optional that should contains all the extended classes of BatchInputExecutor
is not empty, it is null; and the repository is not null.
How am I supposed to mock the value of the optional field in my constructor ?
> executors; But then you'll need to configure the mocks somehow anyway
– Arthur Klezovich Nov 08 '21 at 11:10