title: InjectMock does not work with RestClient for ApplicationScoped Bean in Quarkus
body: <p>After upgrading from Quarkus 1.11.3.Final to 2.2.3.Final my Unittests are failing with following message:
  <code>Caused by: java.lang.IllegalStateException: Invalid use of io.quarkus.test.junit.mockito.InjectMock - the injected bean does not declare a CDI normal scope but: javax.inject.Singleton. Offending field is cloudEventPublisherMock of test class class ch.zhaw.ba.services.order.MyTest</code></p>
  <p>This is the offending class behind the field, clearly annotated with @ApplicationScoped (not Singleton):</p>
  <pre><code>import io.cloudevents.CloudEvent;
  import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
  
  import javax.enterprise.context.ApplicationScoped;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  @Path(&quot;/&quot;)
  @ApplicationScoped
  @RegisterRestClient
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public interface CloudEventPublisher {
  
      @POST
      void publishOrder(CloudEvent cloudEvent);
  }
  
  </code></pre>
  <p>This is the test I try to run:</p>
  <pre><code>
  @QuarkusTest
  class MyTest {
  
      @InjectMock
      @RestClient
      CloudEventPublisher cloudEventPublisherMock;
  
      @Test
      void mytest() {
          //some stuff
      }
  </code></pre>
  <p>The CDI @ApplicationScope annotation comes from following library: <code>jakarta.enterprise:jakarta.enterprise.cdi-api:jar:2.0.2</code></p>
  <p>Additionally added the pom.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;project xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;
           xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.axa.ch.trap&lt;/groupId&gt;
      &lt;artifactId&gt;trap&lt;/artifactId&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;properties&gt;
          &lt;compiler-plugin.version&gt;3.8.1&lt;/compiler-plugin.version&gt;
          &lt;maven.compiler.parameters&gt;true&lt;/maven.compiler.parameters&gt;
          &lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;quarkus-plugin.version&gt;2.2.3.Final&lt;/quarkus-plugin.version&gt;
          &lt;quarkus.platform.artifact-id&gt;quarkus-universe-bom&lt;/quarkus.platform.artifact-id&gt;
          &lt;quarkus.platform.group-id&gt;io.quarkus&lt;/quarkus.platform.group-id&gt;
          &lt;quarkus.platform.version&gt;2.2.3.Final&lt;/quarkus.platform.version&gt;
          &lt;surefire-plugin.version&gt;3.0.0-M5&lt;/surefire-plugin.version&gt;
          &lt;cloudevents.version&gt;2.0.0&lt;/cloudevents.version&gt;
          &lt;jacoco.version&gt;0.8.6&lt;/jacoco.version&gt;
      &lt;/properties&gt;
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;${quarkus.platform.group-id}&lt;/groupId&gt;
                  &lt;artifactId&gt;${quarkus.platform.artifact-id}&lt;/artifactId&gt;
                  &lt;version&gt;${quarkus.platform.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-mongodb-panache&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-resteasy&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-smallrye-opentracing&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-arc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-resteasy-jackson&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-datatype-jsr310&lt;/artifactId&gt;
              &lt;version&gt;2.8.8&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-rest-client&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-smallrye-openapi&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-micrometer-registry-prometheus&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-smallrye-health&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-hibernate-validator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.cloudevents&lt;/groupId&gt;
              &lt;artifactId&gt;cloudevents-core&lt;/artifactId&gt;
              &lt;version&gt;${cloudevents.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.cloudevents&lt;/groupId&gt;
              &lt;artifactId&gt;cloudevents-api&lt;/artifactId&gt;
              &lt;version&gt;${cloudevents.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.cloudevents&lt;/groupId&gt;
              &lt;artifactId&gt;cloudevents-http-restful-ws&lt;/artifactId&gt;
              &lt;version&gt;${cloudevents.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.axa.ch.trap&lt;/groupId&gt;
              &lt;artifactId&gt;trap-model&lt;/artifactId&gt;
              &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-junit5&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-junit5-mockito&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
              &lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-panache-mock&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;de.flapdoodle.embed&lt;/groupId&gt;
              &lt;artifactId&gt;de.flapdoodle.embed.mongo&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
              &lt;artifactId&gt;org.jacoco.agent&lt;/artifactId&gt;
              &lt;classifier&gt;runtime&lt;/classifier&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;version&gt;${jacoco.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
                  &lt;artifactId&gt;quarkus-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${quarkus-plugin.version}&lt;/version&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;build&lt;/goal&gt;
                              &lt;goal&gt;generate-code&lt;/goal&gt;
                              &lt;goal&gt;generate-code-tests&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${compiler-plugin.version}&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${surefire-plugin.version}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;systemPropertyVariables&gt;
                          &lt;java.util.logging.manager&gt;org.jboss.logmanager.LogManager&lt;/java.util.logging.manager&gt;
                          &lt;maven.home&gt;${maven.home}&lt;/maven.home&gt;
                      &lt;/systemPropertyVariables&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                  &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${jacoco.version}&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;prepare-integration-tests&lt;/id&gt;
                          &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;prepare-agent&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;destFile&gt;${project.build.directory}/jacoco.exec&lt;/destFile&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;instrument&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;instrument&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;restore&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;restore-instrumented-classes&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;report&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;report&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;dataFile&gt;${project.build.directory}/../jacoco.exec&lt;/dataFile&gt;
                              &lt;outputDirectory&gt;${project.build.directory}/jacoco&lt;/outputDirectory&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;native&lt;/id&gt;
              &lt;activation&gt;
                  &lt;property&gt;
                      &lt;name&gt;native&lt;/name&gt;
                  &lt;/property&gt;
              &lt;/activation&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
                          &lt;version&gt;${surefire-plugin.version}&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;integration-test&lt;/goal&gt;
                                      &lt;goal&gt;verify&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;configuration&gt;
                                      &lt;systemPropertyVariables&gt;
                                          &lt;native.image.path&gt;
                                              ${project.build.directory}/${project.build.finalName}-runner
                                          &lt;/native.image.path&gt;
                                          &lt;java.util.logging.manager&gt;org.jboss.logmanager.LogManager
                                          &lt;/java.util.logging.manager&gt;
                                          &lt;maven.home&gt;${maven.home}&lt;/maven.home&gt;
                                      &lt;/systemPropertyVariables&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
              &lt;properties&gt;
                  &lt;quarkus.native.additional-build-args&gt;
                      -J-Djavax.net.ssl.trustStore=./src/main/resources/truststore_invalid.jks,-J-Djavax.net.ssl.trustStorePassword=changeit
                  &lt;/quarkus.native.additional-build-args&gt;
                  &lt;quarkus.package.type&gt;native&lt;/quarkus.package.type&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>