title: org.powermock.reflect.exceptions.MethodNotFoundException: - when mocking java sql classes
body: <p>I am trying to write unit test for a servlet containing a call to a Postgres database. I am mocking the <code>Connection</code>, <code>Statement</code> and <code>ResultSet</code> classes. However, any method calls on the mocks of those calls give me a <code>MethodNotFoundException</code>. There are some references where it mentions some functionality was broken with Java 8 and PowerMock 1.5.x but I am on PowerMock 1.6.6. Any help is highly appreciated.</p>
  
  <p>Here's the code:
  public class CitiesServlet extends HttpServlet {</p>
  
  <pre><code>private static final Logger log = LoggerFactory.getLogger(CitiesServlet.class);
  
  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
      log.debug("doGet called on servlet=" + this.getClass());
      PrintWriter writer = ServletUtils.setResponseParametersAndGetPrinter(resp);
      CitiesWrapperModel citiesWrapperModel = new CitiesWrapperModel();
      String message = ServletHelper.getInstance().openDBConnection("PgBundle");
      if (!message.startsWith("Servus")) {
          writer.println("&lt;h1&gt;Database connection failed to open " + message + "&lt;/h1&gt;");
          return;
      }
      CitiesData citiesData = new CitiesData();
      citiesData.setCities(getCities());
      citiesWrapperModel.setData(citiesData);
      ServletUtils.writeResultsAndCloseStream(writer, citiesWrapperModel);
  }
  
  public List&lt;String&gt; getCities() {
      List&lt;String&gt; cities = new ArrayList&lt;&gt;();
  
      String query = "SELECT * FROM cities";
      try {
          Connection connection =  ServletHelper.getInstance().getConnection();
          Statement st = connection.createStatement();
          ResultSet rs = st.executeQuery(query);
          while (rs.next()) {
              String cityName = rs.getString("cityName");
              cities.add(cityName);
          }
          st.close();
          rs.close();
      } catch (SQLException sqe) {
          log.warn("SQL exception when accessing users table, sql message= " + sqe.getMessage());
      }
      return cities;
  }}
  </code></pre>
  
  <p>Test class:</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({ServletHelper.class, Statement.class, ResultSet.class, Connection.class})
  public class CitiesServletITTest {
  
  private HttpServletRequest testRequest;
  private HttpServletResponse testResponse;
  private ServletHelper mockServletHelper;
  private Connection mockConnection;
  private CitiesServlet citiesServlet;
  
  @Before
  public void setUp(){
      citiesServlet = new CitiesServlet();
      testRequest = new TestHttpServletRequest();
      testResponse = new TestHttpServletResponse();
      mockServletHelper = mock(ServletHelper.class);
      mockConnection = mock(Connection.class);
  
  }
  
  @Test
  public void canGetCitiesData() throws ServletException, IOException, SQLException {
      PowerMockito.mockStatic(ServletHelper.class);
      PowerMockito.when(ServletHelper.getInstance()).thenReturn(mockServletHelper);
      when(mockServletHelper.openDBConnection(Mockito.anyString())).thenReturn("Servus");
      when(mockServletHelper.getConnection()).thenReturn(mockConnection);
  
  
      ResultSet resultSet = Mockito.mock(ResultSet.class);
      Mockito.when(resultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
      Mockito.when(resultSet.getString("cityName")).thenReturn("Philadelphia").thenReturn("Boston").thenReturn("New York");
  
      Statement statement = Mockito.mock(Statement.class);
      Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet);
  
      Mockito.when(mockConnection.createStatement()).thenReturn(statement);
  
      citiesServlet.doGet(testRequest, testResponse);
  }
  </code></pre>
  
  <p>}</p>