- 
                Notifications
    You must be signed in to change notification settings 
- Fork 41.6k
Closed
Description
Please forgive me if this kind of issue is not appropriate. I already SO-ed.
Just in cases of issue titles, this issue might have a same issue with #15969. I'm not sure.
I have a tightly coupled abstract service class with generic types.
I have an abstract service class which autowires a specific type of repository.
@NoRepositoryBean
interface SomeRepository<T> { }
abstract class SomeService<T extends SomeRepository<U>, U ...> {
    @Autowired
    private U repositoryInstance;
}Now I'm trying to create an abstract test class for subclasses of the service class.
@SpringBootTest
abstract class SomeServiceTest<T extends SomeService<U>, U extends SomeRepository<V>, V ...> {
    @Autowired
    private T serviceInstance;
    // personally expected
    // to mock the serviceInstance.repositoryInstance, and it doesn't.
    @MockBean
    private U repositoryInstance; // != serviceInstance.repositoryInstance();
}But mocking the bean in a test class of actual service class works.
(Which is I intended that extended modules don't have to do.)
class OtherServiceTest
        extends SomeServiceTest<OtherService, OtherRepository, ...> {
    @TestConfiguration
    OtherServiceTestConfiguration {
        // WORKS!!!
        // == serviceInstance().repositoryInstance();
        @MockBean private OtherRepository repositoryInstance;
    }
}
class AnotherServiceTest
        extends SomeServiceTest<AnotherService, AnotherRepository, ...> {
    // WORKS!!!
    // == serviceInstance().repositoryInstance();
    @MockBean private AnotherRepository repositoryInstance;
}Is there any intrinsic mechanism for mocking the SomeServiceTest#serviceIntance.repositoryInstance?
Metadata
Metadata
Labels
type: bugA general bugA general bug