title: Null pointer exception in method that calls another method Mockito
body: <p>I am new to Mockito and Powermockito. I have a class to test which interacts with the database in order find and also delete data from the database through different public methods. The application is typical Java EE application and the The class under test belongs to Service package in Businesslogic. The method which I want to test looks like below :</p>
  
  <pre><code>    public List&lt;QuestionDtoWrapper&gt; searchInQuestions(final Integer ID, final Integer catID,
                  final String searchString, final String language) {
              final List&lt;QuestionDtoWrapper&gt; result = new ArrayList&lt;&gt;();
  
  //In line below I get null pointer exception although I have stubbed this method            
  final List&lt;QuestionDtoInt&gt; questions = facade.findQuestionsByCatTemplate(ID, catID,
                      searchString, language);
              for (final QuestionDtoInt question : questions) {
                  result.add(new QuestionDtoWrapper(question));
              }
              Collections.sort(result, new QuestionComparator(new Locale("de")));
  
              return result;
          }
  </code></pre>
  
  <p>This is how I tried to test the method in my Junit Test:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  @PrepareForTest(QuesService.class)
  
  public class QuesServiceTest {  
          @Mock
          QuesFacade mockFbFacade;
  
          @Mock
          List&lt;QuesDtoInt&gt; questions;
  
          @Spy
          QuesService myService = new QuesService();
  
          @Before
           public void setUp() throws Exception {
           MockitoAnnotations.initMocks(this);
          }   
  
          @Test
              public void testSearchInQuestions() throws ParseException {
                  PowerMockito.doReturn(questions).when(mockFbFacade).findQuestionsByCatTemplate(anyInt(), anyInt(), anyString(), anyString());
                  List&lt;QuestionDtoWrapper&gt; res = null ;
                  res = myService.searchInQuestions(anyInt(), anyInt(), anyString(), anyString());
                  assertNotNull(res);
              } 
  </code></pre>
  
  <p>I am getting Null pointer exception in Line where the method calls another method. See my comment in source code. Could someone please let me know:</p>
  
  <p>1) Am I using mockito for the correct subject ? Should I use real Test data ? But what about the database connections n all ? I tried that approach and ended up using Mockito only.</p>
  
  <p>2) Why am I getting Null pointer exception although I have stubbed that method with Powermockito ?</p>
  
  <p>3) please provide your valuable suggestions to test the given method correctly.</p>
  
  <p>Note:- I am not allowed to do any refactoring in the code.</p>