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
@@ -1,5 +1,5 @@
/*
* Copyright 2021 VMware, Inc.
* Copyright 2021-2022 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@
* {@link SpansAssert#assertThat(Collection)} or {@link SpansAssert#then(Collection)}.
*
* @author Marcin Grzejszczak
* @author Artem Bilan
* @since 1.0.0
*/
public class SpansAssert extends CollectionAssert<FinishedSpan> {
Expand All @@ -39,7 +40,7 @@ public class SpansAssert extends CollectionAssert<FinishedSpan> {
* Creates a new instance of {@link SpansAssert}.
* @param actual actual object to assert
*/
protected SpansAssert(Collection<FinishedSpan> actual) {
protected SpansAssert(Collection<? extends FinishedSpan> actual) {
super(actual);
}

Expand All @@ -48,7 +49,7 @@ protected SpansAssert(Collection<FinishedSpan> actual) {
* @param actual span to assert against
* @return span collection assertions
*/
public static SpansAssert assertThat(Collection<FinishedSpan> actual) {
public static SpansAssert assertThat(Collection<? extends FinishedSpan> actual) {
return new SpansAssert(actual);
}

Expand All @@ -57,7 +58,7 @@ public static SpansAssert assertThat(Collection<FinishedSpan> actual) {
* @param actual span to assert against
* @return span collection assertions
*/
public static SpansAssert then(Collection<FinishedSpan> actual) {
public static SpansAssert then(Collection<? extends FinishedSpan> actual) {
return new SpansAssert(actual);
}

Expand Down Expand Up @@ -125,12 +126,14 @@ public SpansAssert hasASpanWithName(String name) {
* @throws AssertionError if the span assertion is not met
* @since 1.0.0
*/
@SuppressWarnings("rawtypes")
public SpansAssert hasASpanWithName(String name, Consumer<SpanAssert> spanConsumer) {
isNotEmpty();
atLeastOneSpanPassesTheAssertion(name, spanConsumer);
return this;
}

@SuppressWarnings("rawtypes")
private void atLeastOneSpanPassesTheAssertion(String name, Consumer<SpanAssert> spanConsumer) {
FinishedSpan finishedSpan = this.actual.stream().filter(f -> name.equals(f.getName())).filter(f -> {
try {
Expand Down Expand Up @@ -165,12 +168,14 @@ private void atLeastOneSpanPassesTheAssertion(String name, Consumer<SpanAssert>
* @throws AssertionError if the span assertion is not met
* @since 1.0.0
*/
@SuppressWarnings("rawtypes")
public SpansAssert hasASpanWithNameIgnoreCase(String name, Consumer<SpanAssert> spanConsumer) {
isNotEmpty();
atLeastOneSpanPassesTheAssertionIgnoreCase(name, spanConsumer);
return this;
}

@SuppressWarnings("rawtypes")
private void atLeastOneSpanPassesTheAssertionIgnoreCase(String name, Consumer<SpanAssert> spanConsumer) {
FinishedSpan finishedSpan = this.actual.stream().filter(f -> name.equalsIgnoreCase(f.getName())).filter(f -> {
try {
Expand Down Expand Up @@ -248,6 +253,7 @@ public SpansAssert hasASpanWithNameIgnoreCase(String name) {
* assertion is not successful
* @since 1.0.0
*/
@SuppressWarnings("rawtypes")
public SpansAssert forAllSpansWithNameEqualTo(String name, Consumer<SpanAssert> spanConsumer) {
isNotEmpty();
hasASpanWithName(name);
Expand All @@ -273,6 +279,7 @@ public SpansAssert forAllSpansWithNameEqualTo(String name, Consumer<SpanAssert>
* the additional assertion is not successful
* @since 1.0.0
*/
@SuppressWarnings("rawtypes")
public SpansAssert forAllSpansWithNameEqualToIgnoreCase(String name, Consumer<SpanAssert> spanConsumer) {
isNotEmpty();
hasASpanWithNameIgnoreCase(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 VMware, Inc.
* Copyright 2021-2022 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,4 +79,18 @@ void should_throw_exception_when_size_reported_spans_is_invalid() {
thenThrownBy(() -> assertThat(simpleTracer).reportedSpans().hasSize(2)).isInstanceOf(AssertionError.class);
}

@Test
void should_satisfy_reported_spans() {
SimpleTracer simpleTracer = new SimpleTracer();

simpleTracer.nextSpan().name("foo").start().end();

assertThat(simpleTracer)
.reportedSpans()
.hasSize(1)
.satisfies(simpleSpans ->
SpansAssert.assertThat(simpleSpans)
.hasASpanWithName("foo"));
}

}