0

After updating to Spring Boot 2.6.8 with Java v11 and using Junit5 I'm not able to Mock anymore MongoTemplate

@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes={RepositoryImpl.class})
class RepositoryImplTest {

    @Autowired
    private RepositoryImpl repositoryImpl;

    @MockBean
    private MongoTemplate db;
    

   ...

}

I get the following error java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class org.springframework.data.mongodb.core.MongoTemplate.

as per dependency I have in pom.xml

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
    </dependency>
fefe
  • 8,755
  • 27
  • 104
  • 180

0 Answers0