I have a main class Usuario
that extends ( extends
) an abstract class called Sessao
, and uses a function of Sessao
called obterDados()
that takes the session data and returns it in an object SessaoTO
. I need to mock this function to return the mocked object and move on.
I have already tried to mock the Sessao
class as follows:
// Declaração feita na classe
@Mock
Sessao sessao;
...
// Declaração feita na função de teste
SessaoTO sessaoTO = new SessaoTO();
sessaoTO.setCpf("47566611100");
sessaoTO.setNome("Gaus");
sessaoTO.setSigla("user");
when(sessao.obterDados()).thenReturn(sessaoTO);
The problem is that at the time of execution it is giving NullPointer error because this mock is not working. I've already tried using @InjectMocks
, but it did not work.