Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponseStubbing should accept Suppliers instead of values to unit-test endpoint that can fail #131

Open
adarmiento opened this issue May 20, 2020 · 0 comments

Comments

@adarmiento
Copy link

adarmiento commented May 20, 2020

A common use-case is the one in which my client implementation attempts multiple times to contact a server, retrying the call in case the server is momentarily unavailable.

I was not able to find a way to create something like this

onRequest()
                .havingMethodEqualTo("GET")
                .havingPathEqualTo("/my/path")
                .respond()
                .withDelay(1, SECONDS)
                .withStatus(() -> incrementAndGet(attemptNumber) >= 3 ? 200 : 503)
                .withBody("{...}")
                .withEncoding(StandardCharsets.UTF_8)
                .withContentType("application/json; charset=UTF-8");

In this example, the withStatus() method would accept a lambda instead of a value, and I can, therefore, use it to unit test my algorithm which retries failure calls.

This behaviour can be made possible by extending the ResponseStubbing interface by letting it receive Java Suppliers instead of actual values. E.g.

    ResponseStubbing withStatus(Supplier<int> statusSupplier);

The concrete implementation would then lazily compute them when returning values to the tester instead of being eagerly filled with setters at creation time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant