mercredi 5 août 2015

PowerMock Private method returning null with mocked value

So I have code something like this

Class JobSearchService() {
private SearchSetUpImpl searchSetUp;
...

SearchIndex si = generateIndexes(id);
Job jobs = si.readJobs(keyWord); // <-- si is null , null pointer exception....
...
}

private Job generateIndexes(Id id) {
...
}

I wanted to use powerMock to return the jobs but it always return null for si.

In my test I have

PowerMockito.when(JSS, PowerMockito.method(JobSearchService.class,
"generateIndexes", WorkId.class))
.withArguments(id)
.thenReturn(si);

How do I write the next procedure to skip or to return a proper Job without hitting null value? I have also mocked si SearchIndex si = Mockito.mock(SearchIndex.class);

Aucun commentaire:

Enregistrer un commentaire