Mockito doReturn throws a nullPointerException

Viewed 893

I'm trying to mock a non static method of a class. I am testing a method of the same class. But its returning a nullPointerException. Wonder what am I doing wrong here. Any help will be greatly appreciated.

My code:

public class B2P {
    protected Future<List<FeedObject>> evaluate (NodeContext 
        nodeContext) throws Exception {
        Map<BoardQuery, Future<List<FeedObject>>> resultsFuturesMap = 
        getResultsFutureMap(boardsQuery,
        query, generatorParams, resourceContainer);

        return resultsFuturesMap;
    }

    public Map<BoardQuery, Future<List<FeedObject>>> 
      getResultsFutureMap(){
        DoSomething;
    }
}

My test class:

public class testClass {
  public void test() {
    B2P b2p = new B2P();
    B2P mockSpy = Mockito.spy(b2p);

    doReturn(ImmutableMap.of(
    new BoardQuery().setBoardId(102L).setSignatureWeights(
        ImmutableMap.of("s3", 1.0, "s4", 1.0, "s5", 1.0)),
    Future.value(ImmutableList.of(
        new FeedObject().setObjectId(904L).setObjectDetails(new 
            ObjectDetails()
            .setCommonObjectDetails(new CommonObjectDetails())
            .setPinDetails(new 
             PinDetails().setSource(FeedSourceType.FANTASIO))),
        new FeedObject().setObjectId(903L).setObjectDetails(new 
            ObjectDetails()
            .setCommonObjectDetails(new CommonObjectDetails())
            .setPinDetails(new PinDetails().setSource(FeedSourceType.FANTASIO))),
        new FeedObject().setObjectId(902L).setObjectDetails(new ObjectDetails()
            .setCommonObjectDetails(new CommonObjectDetails())
            .setPinDetails(new PinDetails().setSource(FeedSourceType.FANTASIO)))))))
    .when(mockSpy).getResultsFutureMap(any(), any(), any(), any());

  ....
  b2p.evaluate();

} }

Am I mocking this method in the wrong way?

1 Answers
Related