title: How can I mock the HttpUrlConnection.getResponseCode() method using EasyMock
body: <p>I am trying to write test case for below code snippet. But mock is not working as expected.</p>
  <pre><code>Map&lt;String, String&gt; request = new HAshMap&lt;String, String&gt;();
  URL url = new URL(&quot;sampleurl&quot;);
  HttpUrlConnection connection = (HttpUrlConnection) url.openConnection();
  
  if(connection != null){
  connection.setDOutput(true);
  
  OutputStreamReader out = new OutputStreamReader(connection.getOutputStream());
  out.write(new Gson().toJson(request);
  out.close();
  
  int responseCode = connection.getResponseCode();
  }
  </code></pre>
  <p>I have tried the below test code snippet for mocking but Mock is not working properly, where I am doing wrong</p>
  <pre><code> URL url = PowerMock.createNiceMock(URL.class);
   HttpsUrlConnection httpConn = PowerMock.createNiceMock(HttpsUrlConnection.class);
  
   EasyMock.expect(url.openConnection()).andReturn(httpConn);
   EasyMock.expect(httpConn.getResponseCode()).andReturn(500);
  </code></pre>