1
@Mock
RequestUtils requestUtils;
@Before
public void init() throws IOException, ClassNotFoundException {
MockitoAnnotations.initMocks(this);
HtmlPage paginaPesquisa = requestUtils.executarPOST(anyObject(),anyObject());
when(paginaPesquisa).thenReturn(this.getPaginaEstatica(URL_PESQUISA, PAGINA_RESULTADOS_PESQUISA_NOME, "ISO-8859-1" ));
when(requestUtils.getPaginaResultados(anyObject())).thenReturn(this.getPaginaEstatica(URL_PESQUISA,PAGINA_RESULTADOS_PESQUISA_IDADE, "ISO-8859-1"));
when(paginaPesquisa.getWebClient().getPage(anyObject().toString())).thenReturn(this.getPaginaEstatica(URL_PAGINA_INICIAL,PAGINA_INICIAL,"ISO-8859-1"));
}
The problem is that in this last when:
when(paginaPesquisa.getWebClient().getPage(anyObject().toString()))
Gives a NullPointerException
because there is no way to recover the webClient
.
I searched Mockito’s functions for this case but found nothing... What to do?
I think that you need to put a
thenReturn(paginaPesquisa.getWebClient())
before thatwhen
.– igventurelli
What do you mean? I tried and it didn’t work.
– laaf
I misspelled. That was the idea:
when(paginaPesquisa.getWebClient()).thenReturn(valorMockado)
– igventurelli
I’ve tried, but the paginaPesquisa already this stoned before, so gives a Nullpointerexception no when()...
– laaf