title: Micronaut Test mocked bean failing to inject values
body: <p>I'm trying to test a class that depends on a bean to work, which I'd like to mock. This bean requires a string value, which is received from my <code>application.yml</code> file using <code>@ConfigurationProperties</code> and that is likely the problem since other beans mocked in the same test class work just fine. Running the application normally also works just fine, so the error seems to be related to the <code>@MockBean</code> in some way.</p>
  
  <p>I have this configuration class which gets the value from the <code>application.yml</code>:</p>
  
  <pre><code>@Data
  @ConfigurationProperties("some_api")
  public class SomeApiDaoConfig {
      private String url;
  }
  </code></pre>
  
  <p>Also, the value is set in the integrationTest <code>application.yml</code> file:</p>
  
  <pre><code>some_api:
    url: http://localhost:8082
  </code></pre>
  
  <p>And also this factory, which creates the bean:</p>
  
  <pre><code>@Factory
  public class SomeApiDaoFactory {
  
    @Singleton
    public SomeApiDao someApiDao(SomeApiDaoConfig someApiDaoConfig) {
      return new SomeApiDao(someApiDaoConfig.getUrl());
    }
  }
  
  </code></pre>
  
  <p>The test class is basically:</p>
  
  <pre><code>@MicronautTest(packages = {"&lt;&lt;path to someApiDao&gt;&gt;"})
  public class ServiceTest {
    @Inject private BlockingStub blockingStub;
    @Inject private AnotherDao anotherDao;
    @Inject private SomeApiDao someApiDao;
  
  @BeforeEach
    void setUp() {
      MockitoAnnotations.initMocks(this);
    }
  
  ... (tests)
  
  @MockBean(AnotherDao.class)
    AnotherDao anotherDao() {
      return mock(AnotherDao.class);
    }
  
  @MockBean(SomeApiDao.class)
    SomeApiDao someApiDao() {
      return mock(SomeApiDao.class);
    }
  </code></pre>
  
  <p>When I run the tests, however, this error pops up while it tries to initialize the SomeApiDao bean:</p>
  
  <pre><code>Failed to inject value for parameter [url] of class: &lt;path to test&gt;.$ServiceTest$SomeApiDao3Definition$Intercepted
  
  Message: No bean of type [java.lang.String] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
  Path Taken: new GrpcEmbeddedServer(ApplicationContext applicationContext,ApplicationConfiguration applicationConfiguration,GrpcServerConfiguration grpcServerConfiguration,[ServerBuilder serverBuilder],ApplicationEventPublisher eventPublisher,ComputeInstanceMetadataResolver computeInstanceMetadataResolver,List metadataContributors) --&gt; ServerBuilder.serverBuilder(GrpcServerConfiguration configuration,[List serviceList],List interceptors,List serverTransportFilters) --&gt; new Service([SomeApiDao someApiDao]) --&gt; new $ServiceTest$SomeApiDao3Definition$Intercepted([String url],BeanContext beanContext,Qualifier qualifier,Interceptor[] interceptors)
  io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [url] of class: &lt;path to test&gt;.$ServiceTest$SomeApiDao3Definition$Intercepted
  </code></pre>