If we have models of different types implementing Collection or Map, we should not construct fields of these models with @Spy annotation but just use setField for it. Otherwise it will cause problems with @InjectMocks in Mockito because injection by type is used and in generated tests both List<A> and List<B> are represented as List listSpy.
One of the possible scenarios to reproduce the bug we fix here is to generate tests for Owner class in spring-petclinic project with 100% fuzzing. Before this fix, several different spies were created but injected not as we expect after that.
Self-check list
[x] I've set the proper labels for my PR (at least, for category and component).
[x] PR title and description are clear and intelligible.
[x] I've added enough comments to my code, particularly in hard-to-understand areas.
[ ] The functionality I've repaired, changed or added is covered with automated tests.
[x] Manual tests have been provided optionally.
[x] The documentation for the functionality I've been working on is up-to-date.
Description
If we have models of different types implementing Collection or Map, we should not construct fields of these models with
@Spy
annotation but just usesetField
for it. Otherwise it will cause problems with@InjectMocks
in Mockito because injection by type is used and in generated tests bothList<A>
andList<B>
are represented asList listSpy
.One of the possible scenarios to reproduce the bug we fix here is to generate tests for
Owner
class inspring-petclinic
project with 100% fuzzing. Before this fix, several different spies were created but injected not as we expect after that.Self-check list