Comments (7)
MockResponse is valid as a utility, people can use it in classes with methods that take a HttpResponse for example, it is not, as noted, intended to be used with the mock client.
You are not the first person to think this, and I think its reasonable to expect that if people think it should work some way, then maybe it should.
I'm intrigued that it EVER worked at least
from unirest-java.
Hi @ryber, I was not aware of that use case for MockResponse
which makes sense. And I like the fluent API, too.
In fact, the response worked in Unirest 3. I just came around this problem when updating my source to Unirest 4 and suddenly the test failed.
from unirest-java.
I'm actually going to re-open this temporarily because I'm making it work again. but I'm having a maven central problem and have a ticket open with SonaType, I want to keep this open until I get it all resolved
from unirest-java.
ready to go in 4.0.7 @timomeinen
from unirest-java.
Tested it and it works again. Thank you @ryber. On the other side as I now know the fluent API I will use that one. ;-)
from unirest-java.
HI @ryber,
today I realized that the provided fix does not work correctly for the statusText
:
unirestMock.expect(HttpMethod.GET, HEALTH_URL)
.thenReturn(MockResponse.bad("Fail"));
HttpResponse<Empty> response = Unirest.get(HEALTH_URL).asEmpty();
assertThat(response.getStatus()).isEqualTo(400);
assertThat(response.getStatusText()).isEqualTo("bad request"); // FAIL: No statustext
But using the fluent API works as expected:
unirestMock.expect(HttpMethod.GET, HEALTH_URL)
.thenReturn("Fail")
.withStatus(400, "bad request");
Although the kong.unirest.core.MockResponse does set a statustext:
public static <T> MockResponse<T> bad(T body) {
return new MockResponse<>(400, "bad request", body);
}
from unirest-java.
@timomeinen fixed in 4.1.1
from unirest-java.
Related Issues (20)
- Low level interceptor with shared context HOT 10
- bug query get with version 4 HOT 5
- Jackson MismatchedInputException for successful response with no body, after migrating to Unirest 4 HOT 2
- Automatic Retries not being used HOT 2
- MockClient: allow fine grained request verification or "un-expected" routes HOT 2
- Request cancellation (such as download cancellation) HOT 2
- Can't turn auto retries standard on HOT 10
- Incorrect Unirest version in README.md HOT 1
- Incorrect link to Interceptor file HOT 1
- Supported windows versions
- Configured HttpClient.Version ignored HOT 10
- MockClient: Mocking same route with different methods only invokes first registered/expected mocking response HOT 2
- multipart/form-data POST is missing content types HOT 6
- How to set read timeout duration HOT 4
- Can we add a response failure retry function? HOT 1
- Making header method to avoid redundant typing. HOT 2
- Make all HttpRequest.asObject work the same way HOT 2
- Strange behavior of response.getRequestSummary().getUrl() HOT 3
- Support the Partitioned flag on cookies HOT 1
- Is Unirest supported Server-Sent Events? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unirest-java.