@Test
  public void conversionWithBadInputTest() throws RestServiceException {
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
    // HttpRequest null.
    try {
      new NettyRequest(null, new MockChannel(), new NettyMetrics(new MetricRegistry()), DENY_LISTED_QUERY_PARAM_SET);
      fail("Provided null HttpRequest to NettyRequest, yet it did not fail");
    } catch (IllegalArgumentException e) {
      // expected. nothing to do.
    }

    // Channel null.
    try {
      new NettyRequest(httpRequest, null, new NettyMetrics(new MetricRegistry()), DENY_LISTED_QUERY_PARAM_SET);
      fail("Provided null Channel to NettyRequest, yet it did not fail");
    } catch (IllegalArgumentException e) {
      // expected. nothing to do.
    }

    // unknown http method
    try {
      createNettyRequest(HttpMethod.TRACE, "/", null, new MockChannel());
      fail("Unknown http method was supplied to NettyRequest. It should have failed to construct");
    } catch (RestServiceException e) {
      assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.UnsupportedHttpMethod, e.getErrorCode());
    }

    String[] invalidBlobSizeStrs = {"aba123", "12ab", "-1", "ddsdd", "999999999999999999999999999", "1.234"};
    for (String blobSizeStr : invalidBlobSizeStrs) {
      // bad blob size
      try {
        createNettyRequest(HttpMethod.GET, "/", new DefaultHttpHeaders().add(RestUtils.Headers.BLOB_SIZE, blobSizeStr),
            new MockChannel());
        fail("Bad blob size header was supplied to NettyRequest. It should have failed to construct");
      } catch (RestServiceException e) {
        assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.InvalidArgs, e.getErrorCode());
      }
    }
  }
Tests conversion of {@link HttpRequest} to {@link NettyRequest} given bad input (i.e. checks for the correct
exception and {@link RestServiceErrorCode} if any).
@throws RestServiceException
ambry-rest/src/test/java/com/github/ambry/rest/NettyRequestTest.java