code: @Test public void testProtocolException() throws Exception {
    HttpProcessor httprocessor=Mockito.mock(HttpProcessor.class);
    ConnectionReuseStrategy connReuseStrategy=Mockito.mock(ConnectionReuseStrategy.class);
    HttpResponseFactory responseFactory=Mockito.mock(HttpResponseFactory.class);
    HttpRequestHandlerResolver handlerResolver=Mockito.mock(HttpRequestHandlerResolver.class);
    HttpRequestHandler requestHandler=Mockito.mock(HttpRequestHandler.class);
    HttpParams params=new SyncBasicHttpParams();
    HttpService httpservice=new HttpService(httprocessor,connReuseStrategy,responseFactory,handlerResolver,params);
    HttpContext context=new BasicHttpContext();
    HttpServerConnection conn=Mockito.mock(HttpServerConnection.class);
    HttpRequest request=new BasicHttpRequest("whatever","/");
    Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
    HttpResponse response=new BasicHttpResponse(HttpVersion.HTTP_1_1,200,"OK");
    Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1,200,context)).thenReturn(response);
    HttpResponse error=new BasicHttpResponse(HttpVersion.HTTP_1_0,500,"Oppsie");
    Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_0,500,context)).thenReturn(error);
    Mockito.when(handlerResolver.lookup("/")).thenReturn(requestHandler);
    Mockito.doThrow(new ProtocolException("oh, this world is wrong")).when(requestHandler).handle(request,response,context);
    Mockito.when(connReuseStrategy.keepAlive(error,context)).thenReturn(false);
    httpservice.handleRequest(conn,context);
    Assert.assertSame(conn,context.getAttribute(ExecutionContext.HTTP_CONNECTION));
    Assert.assertSame(request,context.getAttribute(ExecutionContext.HTTP_REQUEST));
    Assert.assertSame(error,context.getAttribute(ExecutionContext.HTTP_RESPONSE));
    Assert.assertEquals(HttpStatus.SC_BAD_REQUEST,error.getStatusLine().getStatusCode());
    Mockito.verify(conn).sendResponseHeader(error);
    Mockito.verify(httprocessor).process(error,context);
    Mockito.verify(conn).sendResponseHeader(error);
    Mockito.verify(conn).sendResponseEntity(error);
    Mockito.verify(conn).flush();
    Mockito.verify(conn).close();
  }
  