我如何为 Listener class 编写 mockito junit
How I can write mockito junit for Listener class
嗨,如何编写 mockitJunit。
请帮助如何为以上内容编写 mockito junit class
这成功了。只需添加对您设置的系统属性的检查。
@RunWith(MockitoJUnitRunner.class)
public class AppStartUpContextListenerTest {
public AppStartUpContextListenerTest() {
}
@Mock
ServletContextEvent mockEvent;
@Mock
ServletContext mockServletContext;
@Mock
Configuration mockConfig;
@Mock
WebApplicationContext mockWebContext;
/**
* Test of contextInitialized method, of class AppStartUpContextListener.
*/
@Test
public void testContextInitialized() {
System.out.println("testContextInitialized");
when(mockEvent.getServletContext()).thenReturn(mockServletContext);
when(mockServletContext.getAttribute(Matchers.anyString())).thenReturn(mockWebContext);
AppStartUpContextListener instance = new AppStartUpContextListener();
instance.contextInitialized(mockEvent);
// TODO review the generated test code and remove the default call to fail.
verify(mockEvent, times(1)).getServletContext();
}
}
嗨,如何编写 mockitJunit。
请帮助如何为以上内容编写 mockito junit class
这成功了。只需添加对您设置的系统属性的检查。
@RunWith(MockitoJUnitRunner.class)
public class AppStartUpContextListenerTest {
public AppStartUpContextListenerTest() {
}
@Mock
ServletContextEvent mockEvent;
@Mock
ServletContext mockServletContext;
@Mock
Configuration mockConfig;
@Mock
WebApplicationContext mockWebContext;
/**
* Test of contextInitialized method, of class AppStartUpContextListener.
*/
@Test
public void testContextInitialized() {
System.out.println("testContextInitialized");
when(mockEvent.getServletContext()).thenReturn(mockServletContext);
when(mockServletContext.getAttribute(Matchers.anyString())).thenReturn(mockWebContext);
AppStartUpContextListener instance = new AppStartUpContextListener();
instance.contextInitialized(mockEvent);
// TODO review the generated test code and remove the default call to fail.
verify(mockEvent, times(1)).getServletContext();
}
}