需要但未调用:kafkaproducer.send(< any>,< any>);

pu82cl6c  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(249)

以下是我的方法和测试方法:

@BeforeMethod
private void preTestSetup() throws Exception {

yfc = YFCLogCategory.instance(SamsCashActivation.class);
    yfc.setLogAll(true);
    PowerMockito.mockStatic(YFSSystem.class);
    PowerMockito.mockStatic(EarnEventHubProducer.class);
    PowerMockito.mockStatic(Future.class);
    PowerMockito.mockStatic(KafkaProducer.class);
    earnEventHubProducer = PowerMockito.mock(EarnEventHubProducer.class);
    MockitoAnnotations.initMocks(earnEventHubProducer);
    Mockito.when(kafkaProducer.send(Matchers.any(ProducerRecord.class), 
    Matchers.any())).thenReturn(future);

}

@Test
public void testPublishMethodEnabled() throws Exception {

    earnEventHubProducer.publish("payload", "OrderNo");
    Mockito.verify(kafkaProducer, Mockito.times(1)).send(Matchers.any(ProducerRecord.class), Matchers.any());
    Mockito.doNothing().when(kafkaProducer).close();
    earnEventHubProducer.cleanup();
    Mockito.verify(kafkaProducer, Mockito.times(1)).close();
}

当我运行这个命令时,它抛出:wanted但不调用:kafkaproducer.send(,);实际上,这个模拟游戏没有任何互动。
我在earneventhubproducer中有一个发布方法。有人能帮我吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题