-
Notifications
You must be signed in to change notification settings - Fork 259
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
IterableSubject.containsMatch(Predicate) #206
Comments
Since we're still not using Java8 lang features inside of Google, we haven't really investigated anything like this yet, but it sounds pretty reasonable. Thanks for the suggestion! |
I just did the lambda cuz it made it easier to type. This is what I had in mind for java7
|
Right, but it'd be sad to add new APIs at this point in time that require On Fri, Oct 2, 2015 at 1:11 PM, Raul E Rangel notifications@github.com
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb@google.com |
Summarizing some internal discussion:
|
Any update on this? We are currently having to resort to:
or if creating a list is expensive (or just very long)
Whereas
Would be more readable and could provide better error messages. Thanks. |
We have an internal proposal for a |
We should be releasing a java8 extension (to keep the core deps usable by On Mon, Jun 13, 2016, 18:08 Kurt Alfred Kluever notifications@github.com
|
Wonderful. Look forward to testing it out. |
A couple notes:
... storing up failures and reporting the first N all together...? |
Honestly maybe we don't even need this with java8:
I think that reads just fine. Or if you wanted to print out the original list we could add a map method:
This will allow truth to print out myList, the value of the getId, and the value it was expecting. Or using the existing API we can do this:
Should I just close this out? Not sure we really need to do anything here. |
Thanks Raul. As you point out, example #1 won't print the original list. Example #2 won't be able to print any details about what the "map transform" is. Example #3 will include all of the information we want, but it's still not best. I think ultimately we'll want to add some APIs that take the functional types with a description string. Something like: |
Our main answer to this nowadays is http://google.github.io/truth/fuzzy. It's still not quite as straightforward as we might someday make it, though. |
Would it be really that crazy to have support in extensions/java8 which would let one do things like:
which, to me, is both much more obvious to read as well as write than I guess:
Or am I just missing re. doing this with better streams, to make it as obvious? I also don't really get how to do this with Fuzzy.. nobody wants to have to write a This seems easy to do (an |
So, yeah, to do this with Fuzzy Truth today, you'd have to subclass
We agree that having to subclass
|
I think that Fuzzy Truth is going to be our only supported approach for this. We did add some more convenient static factories for An approach like @vorburger lays out is a possibility, but the failure messages are likely to be odd, since the messages for assertions like For users who do want an approach like that or an approach like |
It would be nice to have
I could then do something like
assertThat(myList).contains(p -> p.getId() == 55);
The text was updated successfully, but these errors were encountered: