I want a method with varargs arguments but it isn't working because the method stills be called. I've already tryed the follow without success:
ArgumentMatchers.any()
new String[] {}
new String[0]
But in all these cases, the method still be called.
There is my classes:
@Service
public class ProjetoServiceImpl extends DefaultServiceImpl<Projeto,ProjetoRepository> implements ProjetoService {
@Override
public List<Projeto> buscaAtestadosComFiltro(String[] filtros) {
List<Projeto> projetos = buscarTodos(); // I want to mock this line
projetos = filtraResultado(projetos, filtros);
return projetos;
}
}
////////////////////////////////////////////////////
public class ProjetoServiceImplTest {
private ProjetoServiceImpl projImpl;
@MockBean
private ProjetoService projetoServiceMock;
@Test
public void testaBuscaAtestadosComFiltro() {
Projeto projeto1 = new Projeto();
List<Projeto> projetos = new ArrayList<Projeto>();
projetos.add(projeto1);
when(projetoServiceMock.buscarTodos(ArgumentMatchers.<String>any())).thenReturn(projetos);
String[] filtros = new String[] {"java"};
projImpl = new ProjetoServiceImpl();
List<Projeto> result = projImpl.buscaAtestadosComFiltro(filtros);
assertNotNull(result);
}
}