There is an example with @MockitoSpyBean annotation
@SpringBootTest()
class TestExample {
@MockitoSpyBean
VersionRepository versionRepository;
@Autowired
VersionService versionService;
@Test
void findAllVisibleAndReadableVersions() {
when(versionRepository.findAll()).thenReturn(buildVersions());
versionService.findAll(); // inside versionService.findAll() call versionRepository.findAll()
// add assertations here
}
// Return versions instead of versionRepository.findAll() call
private static List<Version> buildVersions() {
return List.of( // build your versions here );
}
}