title: SpringBootTest with @EmbeddedKafka, @KafkaListener not invoked when using @MockBean
body: <p>I'm seeing an issue when using <code>@MockBean</code> whereby the class under test contains a <code>@KafkaListener</code> annotation and isn't invoked.</p>
  <p>I've tried the following:</p>
  <ul>
  <li><code>@SpyBean</code></li>
  <li>A TestConfiguration class with the bean containing <code>@KafkaListener</code> with a mock</li>
  <li>Removing the base class which brings in a bunch of producer configs to publish to embedded broker</li>
  </ul>
  <p>Something that did actually work was changing the dependency to var and replacing it in a <code>@BeforeEach</code> in the Test class</p>
  <p>Test class:</p>
  <pre><code>@SpringBootTest
  @ContextConfiguration(
      initializers = [ITKafkaPropertiesContextInitializer::class]
  )
  @EmbeddedKafka(
      controlledShutdown = true,
      ports = [9093],
      topics = [
          &quot;embedded-test-topic-1&quot;,
          &quot;embedded-test-topic-2&quot;
      ],
      partitions = 1,
      brokerProperties = [
          &quot;PLAINTEXT://localhost:9093&quot;
      ]
  )
  class ConsumerITTest : AbstractKafkaTest() {
  
      @Autowired
      lateinit var kafkaTemplate: KafkaTemplate&lt;String, Message&gt;
  
  
      @Value(&quot;\${spring.kafka.event-topic}&quot;)
      lateinit var kafkaTopic: String
  
      @MockBean
      lateinit var delegator: MessageDelegator
  
      @Test
      fun `should receive message and invoke delegator`() {
          val event = JsonReader.read(&quot;src/test/resources/messages/create.json&quot;, Message::class.java)
  
          eventKafkaTemplate.send(
              ProducerRecord(producerRecord)
          )
  
          await().atMost(Duration.FIVE_SECONDS).untilAsserted {
            ...
          }
  
      }
  
  }
  </code></pre>
  <p>Without the <code>@MockBean</code> everything works as expected, with <code>@MockBean</code> I can't even reach the breakpoint because the <code>@KafkaListener</code> function is never called.</p>
  <pre><code>@Component
  class Consumer(
      val delegator: Delegator
  ) {
      private val logger = KotlinLogging.logger {}
  
      @KafkaListener(
          topics = [&quot;#{'\${spring.kafka.topic}'}&quot;],
          groupId = &quot;#{'\${spring.kafka.consumer.group-id}'}&quot;,
          containerFactory = &quot;eventContainerFactory&quot;
      )
      fun onMessage(
          @Payload data: ConsumerRecord&lt;String, Message&gt;?,
          @Headers headers: Map&lt;String?, ByteArray?&gt;,
      ) {
        ... //Breakpoint here never reached when using @MockBean
  </code></pre>
  <p>Just to confirm, this all works totally fine until I use these annotations to replace with a bean in the context with a mock</p>