title: Netty HttpHeaders.isKeepAlive(request) throws null exception in unit tests
body: <p>I'm trying to unit test some legacy code in order to make sure a new feature doesn't break old functionality.  Unfortunately this legacy code has some bad design features (circular dependencies, passing lots of variables, poor style, etc).  Also, this legacy code lives in a code base that will be completely thrown away "soon" so spending lots of time to refactor it, clean it up, and upgrade it is not the best use of time.  Finally, we are using an old version of Netty (3.10.5.Final) and can't upgrade.</p>
  
  <p>I've had to mock up a lot of variables and interfaces to get the code to even run unit tests without bombing out.  The last hurdle I'm falling into is that this line of code always throws a null exception:</p>
  
  <pre><code>if (!HttpHeaders.isKeepAlive(request)) {
  </code></pre>
  
  <p>I've tried to populate the HttpHeaders object, make sure my requests and responses have proper headers, and I've even tried to mock the method call:</p>
  
  <pre><code>when(HttpHeaders.isKeepAlive(any())).thenReturn(true);
  </code></pre>
  
  <p>But nothing works.  In fact, when I mock the method call it also throws a null exception.</p>
  
  <p>However, other calls to this object work fine like:</p>
  
  <pre><code>HttpHeaders.addHeader(httpResponse, "keepAlive", true);
  </code></pre>
  
  <p>I'm unfamiliar with exactly how the HttpHeaders object becomes populated, how to mock the .isKeepAlive call, or why this function returns a null exception.  Any ideas or thoughts would be appreciated.</p>
  
  <p>Edit:</p>
  
  <p>Adding requested stack trace</p>
  
  <pre><code>java.lang.NullPointerException
      at org.jboss.netty.handler.codec.http.HttpHeaders.isKeepAlive(HttpHeaders.java:553)
      at com.apifest.BackEndResponseListener.responseReceived(BackEndResponseListener.java:93)
      at com.apifest.BackEndResponseListenerTest.NewTest_OK_LogsSuccessful(BackEndResponseListenerTest.java:117)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
      at org.testng.TestRunner.privateRun(TestRunner.java:756)
      at org.testng.TestRunner.run(TestRunner.java:610)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
      at org.testng.SuiteRunner.run(SuiteRunner.java:289)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1306)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1231)
      at org.testng.TestNG.runSuites(TestNG.java:1146)
      at org.testng.TestNG.run(TestNG.java:1117)
      at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
      at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
  </code></pre>