Skip to content

Commit

Permalink
issue #461 return HttpResponse<Empty> for asEmpty()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Nov 26, 2022
1 parent e2ddec7 commit aa479ff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.14.0
* issue #461 return HttpResponse<Empty> for asEmpty()

## 3.13.13
* Cookie dates always follow US Locale to avoid invalid unicode in headers

Expand Down
17 changes: 14 additions & 3 deletions unirest-bdd-tests/src/test/java/BehaviorTests/AsEmptyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package BehaviorTests;

import kong.unirest.Empty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import kong.unirest.HttpResponse;
Expand All @@ -33,13 +34,23 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

@SuppressWarnings("rawtypes")

class AsEmptyTest extends BddTest {

@Test
void asEmptyParams() {
Unirest.get(MockServer.ERROR_RESPONSE)
.asEmpty()
.ifFailure(response -> {
assertEquals("Bad Request", response.getStatusText());
})
.ifSuccess(s -> {throw new RuntimeException("fail");});
}

@Test
void canDoAEmptyRequestThatDoesNotParseBodyAtAll() {
MockServer.addResponseHeader("Content-Type", "json");
HttpResponse res = Unirest.get(MockServer.GET).asEmpty();
HttpResponse<Empty> res = Unirest.get(MockServer.GET).asEmpty();

assertNull(res.getBody());
Assertions.assertEquals(200, res.getStatus());
Expand All @@ -49,7 +60,7 @@ void canDoAEmptyRequestThatDoesNotParseBodyAtAll() {
@Test
void canDoEmptyAsync() throws Exception {
MockServer.addResponseHeader("Content-Type", "json");
HttpResponse res = Unirest.get(MockServer.GET).asEmptyAsync().get();
HttpResponse<Empty> res = Unirest.get(MockServer.GET).asEmptyAsync().get();

assertNull(res.getBody());
Assertions.assertEquals(200, res.getStatus());
Expand Down
2 changes: 1 addition & 1 deletion unirest/src/main/java/kong/unirest/BaseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public R downloadMonitor(ProgressMonitor monitor) {
}

@Override
public HttpResponse asEmpty() {
public HttpResponse<Empty> asEmpty() {
return request(BasicResponse::new, Empty.class);
}

Expand Down
2 changes: 1 addition & 1 deletion unirest/src/main/java/kong/unirest/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <T> PagedList<T> asPaged(Function<HttpRequest, HttpResponse> mappingFunction,
* Executes the request and returns the response without parsing the body
* @return the basic HttpResponse
*/
HttpResponse asEmpty();
HttpResponse<Empty> asEmpty();

/**
* Executes the request asynchronously and returns the response without parsing the body
Expand Down

0 comments on commit aa479ff

Please sign in to comment.