HTTPRequest { public HTTPRequest withPayload(Payload payload) { if (!method.canHavePayload()) { throw new IllegalStateException(String.format("Unable to add payload to a %s request", method)); } return new HTTPRequest(requestURI, method, headers, challenge, Optional.ofNullable(payload)); } HTTPRequest(URI requestURI,
                       HTTPMethod method,
                       Headers headers,
                       Optional<Challenge> challenge,
                       Optional<Payload> payload);  HTTPRequest(URI requestURI);  HTTPRequest(String requestURI);  HTTPRequest(String requestURI, HTTPMethod method);  HTTPRequest(URI requestURI, HTTPMethod method); HTTPRequest copy(); URI getRequestURI(); URI getNormalizedURI(); Headers getHeaders(); Headers getAllHeaders(); HTTPRequest addHeader(Header header); HTTPRequest addHeader(String name, String value); HTTPRequest setHeader(String name, String value); HTTPMethod getMethod(); @Deprecated HTTPRequest method(HTTPMethod method); HTTPRequest withMethod(HTTPMethod method); Optional<Challenge> getChallenge(); @Deprecated HTTPRequest challenge(Challenge challenge); HTTPRequest withChallenge(Challenge challenge); Optional<Payload> getPayload(); @Deprecated HTTPRequest payload(Payload payload); HTTPRequest withPayload(Payload payload); HTTPRequest headers(final Headers headers); boolean hasPayload(); Optional<CacheControl> getCacheControl(); @Deprecated HTTPRequest cacheControl(CacheControl cc); HTTPRequest withCacheControl(CacheControl cc); HTTPRequest addIfNoneMatch(Tag tag); HTTPRequest addIfMatch(Tag tag); HTTPRequest withIfUnModifiedSince(LocalDateTime dt); HTTPRequest withIfModifiedSince(LocalDateTime dt); boolean isSecure(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test(expected = IllegalStateException.class) public void testISEWhenSettingPayloadOnGETRequest() { HTTPRequest request = new HTTPRequest(REQUEST_URI); try { request.withPayload(new ClosedInputStreamPayload(MIMEType.APPLICATION_OCTET_STREAM)); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("GET")); throw e; } }
@Test public void testSettingPayloadOnPUTAndPOSTRequestIsOK() { HTTPRequest request = new HTTPRequest(REQUEST_URI, HTTPMethod.POST); Payload payload = new ClosedInputStreamPayload(MIMEType.APPLICATION_OCTET_STREAM); request.withPayload(payload); request = new HTTPRequest(REQUEST_URI, HTTPMethod.PUT); request.withPayload(payload); }