0

Quarkus @InjectMock is not working for Kafka consumer test. The mocked service object is being removed during the test and actual service is being called. How to resolve this?

//Kafka consumer test

@QuarkusTest
public class ConsumerTest {

    @InjectMock
    TestService service;

    @Inject
    @Any
    InMemoryConnector connector;

    public void testEvent() {
        Mockito.when(service).test(Mockito.any(Product.class)))
            .thenReturn("1234");
        InMemorySource source = connector.source("request-in");
        source.send(e);
    }   
}

//Kafka consumer 

@Inject
TestService service;

@Incoming("request-in")
@Blocking
@Acknowledgment(Acknowledgment.Strategy.POST_PROCESSING)
public void consume(Event e) {
    service.test(....);
}

//TestServiceImpl implements TestService
public String test(Product product) { ...
}

//service interface [TestService]
public String test(Product product);
Kirby
  • 15,127
  • 10
  • 89
  • 104
vaibhavSO
  • 11
  • 1
  • Kafka has its own mock consumer and producer classes. Do you need Quarkus? – OneCricketeer May 09 '22 at 14:44
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 09 '22 at 19:21

0 Answers0