Hi guys. How do I properly substitute beans in the...
# spring
d
Hi guys. How do I properly substitute beans in the testing environment? The default implementation is defined like that
Copy code
@Service
open class DefaultPasswordGenerator : PasswordGenerator {
  override fun generatePassword(): String = KeyGenerators.string().generateKey()
}
In the test module I want to override it (this class is written on Groovy)
Copy code
@Configuration
class TestBeanConfiguration {
  @Bean
  @Primary
  def mockPasswordGenerator() {
    return Mockito.mock(PasswordGenerator)
  }
}
If I use
@Autowired
in a test, it injects the mock, but for application controllers it continues using default bean