79711681

Date: 2025-07-23 10:04:21
Score: 0.5
Natty:
Report link

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 );
    }

}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @MockitoSpyBean
  • Low reputation (0.5):
Posted by: Antony Glim