How to test the creation of an obj and method call in a servlet?

0

I am trying to create a web application using TDD, however, I am having a question about how to test the Servlet that processes the requests and calls the proper logic, I do not know how to do assert .

@Test
public void deveCriarInstaciarUmObjetoActionPelaURI() throws ServletException, IOException {
    Dispatcher dispatcher = new Dispatcher();

    HttpServletRequest request = Mockito.mock( HttpServletRequest.class );
    HttpServletResponse response = Mockito.mock( HttpServletResponse.class);

    Mockito.when( request.getContextPath() ).thenReturn( "/app" );
    Mockito.when( request.getRequestURI() ).thenReturn(  "/app/controle/acao" );

    dispatcher.service(request , response);

}

I would need to test if a Control object was created and called the action method, but I do not know how to do this test, any suggestions?

    
asked by anonymous 11.06.2014 / 15:49

1 answer

1

According to Documentation :

- Create a mock of your object to be tested Controle.class , for example:

@Mock  
Controle controle;

-In your test start and verify that acao method was called:

public void deveCriarInstaciarUmObjetoActionPelaURI(){
   MockitoAnnotations.initMocks(this);
   ...
   verify(controle).acao();
   ...
}

Is this what you are looking for? Anything is just a return.

Hugs

    
11.06.2014 / 16:29