### Question:
RequestDefaultHeaders implements HttpRequestInterceptor { @Override public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); final String method = request.getMethod(); if (method.equalsIgnoreCase("CONNECT")) { return; } if (this.defaultHeaders != null) { for (final Header defHeader : this.defaultHeaders) { if(!request.containsHeader(defHeader.getName())) { request.addHeader(defHeader); } } } } RequestDefaultHeaders(final Collection<? extends Header> defaultHeaders);  RequestDefaultHeaders(); @Override void process(final HttpRequest request, final EntityDetails entity, final HttpContext context);  }### Answer:
@Test(expected=NullPointerException.class) public void testRequestParameterCheck() throws Exception { final HttpContext context = new BasicHttpContext(); final HttpRequestInterceptor interceptor = new RequestDefaultHeaders(); interceptor.process(null, null, context); }
@Test public void testNoDefaultHeadersForConnectRequest() throws Exception { final HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com"); final List<Header> defheaders = new ArrayList<>(); defheaders.add(new BasicHeader("custom", "stuff")); final HttpContext context = new BasicHttpContext(); final HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders); interceptor.process(request, null, context); final Header header1 = request.getFirstHeader("custom"); Assert.assertNull(header1); }
@Test public void testDefaultHeaders() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", "/"); request.addHeader("custom", "stuff"); final List<Header> defheaders = new ArrayList<>(); defheaders.add(new BasicHeader("custom", "other stuff")); final HttpContext context = new BasicHttpContext(); final HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders); interceptor.process(request, null, context); final Header[] headers = request.getHeaders("custom"); Assert.assertNotNull(headers); Assert.assertEquals(1, headers.length); Assert.assertEquals("stuff", headers[0].getValue()); }