Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,28 @@ public SpanDataAssert hasAttributesSatisfyingExactly(Iterable<AttributeAssertion

/**
* Asserts the span has an exception event for the given {@link Throwable}. The stack trace is not
* matched against.
* matched against. If {@code exception} is {@code null}, asserts the span has no exception event.
*/
// Workaround "passing @Nullable parameter 'stackTrace' where @NonNull is required", Nullaway
// seems to think assertThat is supposed to be passed NonNull even though we know that can't be
// true for assertions.
@SuppressWarnings("NullAway")
public SpanDataAssert hasException(Throwable exception) {
public SpanDataAssert hasException(@Nullable Throwable exception) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another case of: #7359 (review)

I support retaining the ability to add the @Nullable annotation to parameters, and think its useful here. Also, there was never any followup to #7359 to update VERSIONING.md to disallow this type of change, so it's still allowed.

EventData exceptionEvent =
actual.getEvents().stream()
.filter(event -> event.getName().equals(EXCEPTION_EVENT_NAME))
.findFirst()
.orElse(null);

if (exception == null) {
if (exceptionEvent != null) {
failWithMessage(
"Expected span [%s] to have no exception event but had <%s>",
actual.getName(), exceptionEvent);
}
return this;
}

if (exceptionEvent == null) {
failWithMessage(
"Expected span [%s] to have an exception event but only had events <%s>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ void passing() {

assertThat(RESOURCE.getAttributes())
.containsOnly(entry(DOG, "bark"), entry(AttributeKey.booleanKey("dog is cute"), true));

assertThat(buildTestSpan(SPAN_ID1, "span")).hasException(null);
}

@Test
Expand Down Expand Up @@ -564,6 +566,8 @@ void failure() {
assertThatThrownBy(
() -> assertThat(SPAN1).hasException(new IllegalArgumentException("good argument")))
.isInstanceOf(AssertionError.class);
assertThatThrownBy(() -> assertThat(SPAN1).hasException(null))
.isInstanceOf(AssertionError.class);
assertThatThrownBy(() -> assertThat(SPAN1).hasLinks()).isInstanceOf(AssertionError.class);
assertThatThrownBy(() -> assertThat(SPAN1).hasLinks(Collections.emptyList()))
.isInstanceOf(AssertionError.class);
Expand Down
Loading