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

Wanted: Truth8Junit to support Java 8 types with assume() #1054

Closed
kaibolay opened this issue Dec 15, 2022 · 3 comments
Closed

Wanted: Truth8Junit to support Java 8 types with assume() #1054

kaibolay opened this issue Dec 15, 2022 · 3 comments
Labels
P3 not scheduled

Comments

@kaibolay
Copy link

I found myself wanting to use a java.util.Optional with TruthJunit.assume():

    assume().that(javaUtilOptional).isPresent();

Unfortunately this doesn't work, since TruthJunit doesn't support Java 8 types. Hence this feature request: It's be nice to have a Truth8Junit (analogous to Truth8) to fill this gap.

@cpovirk
Copy link
Member

cpovirk commented Dec 15, 2022

You can do this with:

import static com.google.common.truth.OptionalSubject.optionals;

assume().about(optionals()).that(javaUtilOptional).isPresent();

This is somewhat documented in https://truth.dev/faq#full-chain, but we were just recently discussing that we should mention it in https://truth.dev/faq#missing-import, too.

The longer-term plan is to make support for java.util.Optional part of core Truth (#746) as part of dropping support for Java 7.

Sorry that it's confusing and verbose in the meantime.

@cgdecker cgdecker added the P3 not scheduled label Dec 16, 2022
@kaibolay
Copy link
Author

Thanks!

That workaround is certainly better than what I did:

assume().that(javaUtilOptional.isPresent()).isTrue();

Looking forward to #746,

@cpovirk
Copy link
Member

cpovirk commented Apr 17, 2024

Belatedly closing, given that #746 was resolved in Truth 1.4.2.

@cpovirk cpovirk closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 not scheduled
Projects
None yet
Development

No branches or pull requests

3 participants