-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Make MvcResultAssert.getResponse()
public
#32643
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
Comments
Shouldn’t you use |
I need to return the result from a method. |
Ok. An assert object is not meant to expose anything. You can assign the result of perform and get the response from there. Would that work? |
Yes, that works and is what I do as a workaround. I assume that other trying to migrate their existing assertion pipelines will run into this as well. Furthermore, |
It doesn’t matter that the method already exists. As I’ve tried to explain, we’re following what AssertJ does and they don’t expose their internal state with a getter like that (and they have them protected just because the hierarchy needs access to it). Mixing AssetJ with returning an element of the result and not willing to assign the result doesn’t look like a common case to me. But perhaps I am missing something. |
Well, we're extending AssertJ. Which naturally means adding stuff to the thing that's extended, isn't it? So, AssertJ not doing something we do is by definition, isn't it? Furthermore, that internal state already is exposed on
Not willing sounds stubborn. I just think it would be nice to return the result of such an operation immediately, without having to capture some state initially solely to obtain the thing I want to return from it later. It's already possible on Using the response of a request is pretty common, as soon as you move beyond one-line examples and have test methods that execute slightly more complex testing flows that span multiple requests. Find an example of that in Spring RESTBucks. |
Yes, just like any custom
Again, that doesn't matter. And to be clear, I am not denying the use case here, just that it has to be fixed by making a method public, because it "is already present". I've already noticed a use case with async request where you want to first make a request and then get the response to trigger another WDYT? |
In the end, I, personally, am more concerned about our users' ability to write boilerplate-free code. IMO, what is or is not deemed idiomatic should be of lower priority. Especially, as in this case, the absence of a certain style of method is equated with being non-idiomatic, which, I think, is not the same thing. But I've already argued that in a multitude of ways. Find the translation of the Hamcrest-based definition of matchers to the AssertJ ones in Spring RESTBucks here. Note how, on multiple occasions (more here and here), this causes what could have been expressed in a single, fluent statement now has to be broken up into multiple expressions. |
Thanks for sharing the migration.
I am sorry but I don't see how this has to be a must have. Doing so would mean you'd have to write something like I think you've done that by accident actually, calling I am going to close this now, but I am keeping the use case of producing another request based on a previous response in mind as I've shared in my previous comment. |
MockMvc
allows returning the response that one defined expectations on as a subsequent operation, which allows writing assertions like this:I would appreciate it if we could return the response of an operation from a
MvcResultAssert
, too.The text was updated successfully, but these errors were encountered: