I try to write UnitTest for my API controller which use a CrudRepository from micronaut-data-jpa. I use @MockBean to Mock the collaborated repository in my controller. If I run the Test I got the following error:
Message: No such method [findById(java.lang.Object) ] for bean [jens.repositories.ConnectionProfileRepository]
I never used Spock, Micronaut-Data or Micronaut-Test and only tried it from the following source:
https://micronaut-projects.github.io/micronaut-test/latest/guide/index.html
Controller:
ConnectionProfileRepository profileRepository
ProfilesController(ConnectionProfileRepository profileRepository) {
this.profileRepository = profileRepository
}
Language: Groovy Repository
interface ConnectionProfileRepository extends CrudRepository<ConnectionProfile, UUID> { }
Test
@MicronautTest
class ProfilesControllerSpec extends Specification {
@Inject
ConnectionProfileRepository profilesRepositoryMock
@MockBean(ConnectionProfileRepository.class)
ConnectionProfileRepository profileRepository() {
Mock(ConnectionProfileRepository)
}
...
How can I managed with my current setup to achieve a mock for the repository in my controller?