Git Product home page Git Product logo

Comments (7)

ryber avatar ryber commented on August 26, 2024

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.

timomeinen avatar timomeinen commented on August 26, 2024

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.

ryber avatar ryber commented on August 26, 2024

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.

ryber avatar ryber commented on August 26, 2024

ready to go in 4.0.7 @timomeinen

from unirest-java.

timomeinen avatar timomeinen commented on August 26, 2024

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.

timomeinen avatar timomeinen commented on August 26, 2024

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.

ryber avatar ryber commented on August 26, 2024

@timomeinen fixed in 4.1.1

from unirest-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.