Add vararg hasEvents assertion (#3377)
* Add vararg hasEvents assertion * Test
This commit is contained in:
parent
d8999911fc
commit
d7e8651767
|
@ -3,3 +3,5 @@ Comparing source compatibility of against
|
|||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.SpanDataAssert hasAttributes(java.util.Map$Entry[])
|
||||
+++ NEW ANNOTATION: java.lang.SafeVarargs
|
||||
+++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.SpanDataAssert hasEventsSatisfyingExactly(java.util.function.Consumer[])
|
||||
+++ NEW ANNOTATION: java.lang.SafeVarargs
|
||||
|
|
|
@ -261,6 +261,22 @@ public final class SpanDataAssert extends AbstractAssert<SpanDataAssert, SpanDat
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the span under assertion has the same number of events as provided {@code
|
||||
* assertions} and executes each {@link EventDataAssert} in {@code assertions} in order with the
|
||||
* corresponding event.
|
||||
*/
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("varargs")
|
||||
public final SpanDataAssert hasEventsSatisfyingExactly(Consumer<EventDataAssert>... assertions) {
|
||||
assertThat(actual.getEvents())
|
||||
.hasSize(assertions.length)
|
||||
.zipSatisfy(
|
||||
Arrays.asList(assertions),
|
||||
(event, assertion) -> assertion.accept(new EventDataAssert(event)));
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Asserts the span has the given links. */
|
||||
public SpanDataAssert hasLinks(Iterable<LinkData> links) {
|
||||
isNotNull();
|
||||
|
|
|
@ -171,6 +171,8 @@ class OpenTelemetryAssertionsTest {
|
|||
attributes -> assertThat(attributes).isEqualTo(Attributes.empty()))
|
||||
.hasAttributesSatisfying(attributes -> assertThat(attributes).isEmpty());
|
||||
})
|
||||
.hasEventsSatisfyingExactly(
|
||||
event -> event.hasName("event"), event -> event.hasName("event2"))
|
||||
.hasLinks(LINKS)
|
||||
.hasLinks(LINKS.toArray(new LinkData[0]))
|
||||
.hasLinksSatisfying(links -> assertThat(links).hasSize(LINKS.size()))
|
||||
|
@ -250,6 +252,9 @@ class OpenTelemetryAssertionsTest {
|
|||
assertThat(SPAN1)
|
||||
.hasEventsSatisfying(events -> assertThat(events.get(0)).hasName("notevent")))
|
||||
.isInstanceOf(AssertionError.class);
|
||||
assertThatThrownBy(
|
||||
() -> assertThat(SPAN1).hasEventsSatisfyingExactly(event -> event.hasName("notevent")))
|
||||
.isInstanceOf(AssertionError.class);
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
assertThat(SPAN1)
|
||||
|
|
Loading…
Reference in New Issue