无法模拟ApplicationContext

时间:2019-06-21 13:03:04

标签: junit mocking

我无法嘲笑ApplicationContext。

private CommonAppContextProvider commonAppContextProvider;

ApplicationContext applicationContext = mock(ApplicationContext.class);
    when(commonAppContextProvider.getApplicationContext()).thenReturn(applicationContext);
        when(applicationContext.getBean("queueTemplate")).thenReturn(jmsTemplate);

我要测试的代码

JmsTemplate jmsTemplate = (JmsTemplate) CommonAppContextProvider.getApplicationContext()
                .getBean("queueTemplate");

0 个答案:

没有答案