title: jmockit of HttpURLConnection throws NullPointerException
body: <p>I am using JMockit to mock HttpURLConnection.  My initial two test cases (fileNotFoundResponse, badMimeType) work find, but my third test case (contentDisposition) generates NPE within the Expectations block and I don't know why.  </p>
  
  <p>Here is the Junit test class:</p>
  
  <pre><code>@RunWith(JMockit.class)
  public class TestHttpGET1 { @Before
      public void setUp() throws Exception {
      }    
  
      @After
      public void tearDown() throws Exception {
      }
  
      public final class MockURL extends MockUp&lt;URL&gt; {
          @Mock
          public void $init(String strURL) {}
          @Mock
          public URLConnection openConnection() throws IOException {
          //System.out.println("&gt;&gt;mockURL.openConnection");
              return mockCon;
          }   
      }
  
      @Mocked HttpURLConnection mockCon;
      @Mocked LoggerFactory mockLoggerFactory;
      @Test
      public void fileNotFoundResponse() {
  //      new MockUp&lt;URL&gt; (){
  //          @Mock
  //          public void $init(String strURL) {}
  //          @Mock
  //          public URLConnection openConnection() throws IOException {
  //              //System.out.println("&gt;&gt;mockURL.openConnection");
  //              return mockCon;
  //          }
  //      };
          new MockURL();
          String contents = "";
          try {
              new NonStrictExpectations() {{
                      LoggerFactory.getLogger(TestHttpGET1.class); result = null;
                  mockCon.getResponseCode(); result = 404;
              }};
              contents = Main.httpGETFile("http://bogus");
          } catch (IOException e) {
              e.printStackTrace();
          }
          assertEquals("Contents should be null", null, contents);    
      }
  
      @Test
      public void badMimeType() {
          new MockURL();
          String contents = "";
          try {
              new NonStrictExpectations() {{
                      mockCon.getResponseCode(); result = 200;
                      mockCon.getHeaderField("Content-Disposition"); result = null;
                      mockCon.getContentType(); result = "bogus-mime-type";
                      mockCon.getContentLength(); result = 1000;
              }};
              contents = Main.httpGETFile("http://bogus.m3u8");
          } catch (IOException e) {
              e.printStackTrace();
      }
          assertEquals("Contents should be null", null, contents);
      }
  
  
      @Test
      public void contentDisposition() {
          new MockURL();
          String contents = "";
          try {
              new Expectations() {{
                      String str = "Hello World";
                      mockCon.getResponseCode(); result = 200;
                      mockCon.getHeaderField("Content-Disposition"); result = "filename=test.m3u8";
                      mockCon.getContentType(); result = "application/x-mpegURL";
                      mockCon.getContentLength(); result = 11;
  System.out.println("getContentLength");
                      mockCon.getInputStream(); result = (InputStream) new ByteArrayInputStream(str.getBytes("UTF8"));
  System.out.println("getInputStream");
              }};
              contents = Main.httpGETFile("http://bogus.m3u8");
          } catch (IOException e) {
              e.printStackTrace();
          }
          assertEquals("Contents should match", "Hello World", contents);
      }
  
  }
  </code></pre>
  
  <p>The NPE is generated on this line:</p>
  
  <pre><code>                    mockCon.getInputStream(); result = (InputStream) new ByteArrayInputStream(str.getBytes("UTF8"));
  </code></pre>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>java.lang.NullPointerException
      at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:237)
      at java.net.URLConnection.getInputStream(URLConnection.java)
      at edu.psu.gv.sweng861.TestHttpGET1$3.&lt;init&gt;(TestHttpGET1.java:97)
      at edu.psu.gv.sweng861.TestHttpGET1.contentDisposition(TestHttpGET1.java:90)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  </code></pre>
  
  <p>I have no idea why the code is executing within java.net.URLClassLoader.getResourceAsStream.</p>
  
  <p>I am using the latest version of JMockit v.1.19.</p>