Replies: 2 comments
-
Thanks for reporting this @Philzen, could you provide a minimal reproducible test so that we can try on our side? Have you tried using extracting(LogEvent::getThrowable).extracting(Optional::get) you would use: extracting(logEvent -> logEvent .getThrowable().get()) |
Beta Was this translation helpful? Give feedback.
0 replies
-
If I understood your requirement correctly, you could try the following: assertThat(logCaptor.getLogEvents())
.first(InstanceOfAssertFactories.type(LogEvent.class))
.extracting(LogEvent::getThrowable, InstanceOfAssertFactories.OPTIONAL)
.get(InstanceOfAssertFactories.THROWABLE) // isPresent() called implicitly
.isExactlyInstanceOf(NullPointerException.class)
.hasNoCause(); or less verbose, if giving up a bit of type-safety is an option: assertThat(logEvents)
.first()
.extracting("throwable.value", THROWABLE)
.isExactlyInstanceOf(NullPointerException.class)
.hasNoCause(); (static imports omitted for clarity) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am experimenting with https://github.com/Hakky54/log-captor for a migration. Now i'm stumbling over the extraction of Optionals.
The method LogEvent::getThrowable returns an
Optional<Throwable>
which i would expect to be able to either extract during the assertJ chain like in example (4) below, or even better which would be resolved on-the-fly as in example (3), although i understand that may be a breaking change for some people. Maybe there's a smarter way auto-get the content of the Optional which i haven't discovered in the AssertJ docs yet, always grateful for advice.The gist is, i'd really like to be able to use
.first()
in the fluent assertion, but the assertion chain seems to break as soon as i try that.Beta Was this translation helpful? Give feedback.
All reactions