Skip to content

Commit f18f981

Browse files
committed
Fix failing MessagingSpanNameExtractorTest when running with both old and new naming conventions
1 parent 7d26666 commit f18f981

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/messaging/MessagingSpanNameExtractorTest.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.instrumentation.api.incubator.semconv.messaging;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
import static org.mockito.Mockito.lenient;
109
import static org.mockito.Mockito.when;
1110

1211
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
@@ -23,8 +22,14 @@
2322
@ExtendWith(MockitoExtension.class)
2423
class MessagingSpanNameExtractorTest {
2524

26-
@Mock MessagingAttributesGetter<Message, Void> getter;
27-
@Mock ServerAttributesGetter<Message> serverAttributesGetter;
25+
// This test is executed in 2 modes with old and new semantic conventions
26+
// Due to that some methods are not invoked that ofter
27+
// Mockito can complain about that in strict mode, Lenient mode helps to run both modes
28+
@Mock(strictness = Mock.Strictness.LENIENT)
29+
MessagingAttributesGetter<Message, Void> getter;
30+
31+
@Mock(strictness = Mock.Strictness.LENIENT)
32+
ServerAttributesGetter<Message> serverAttributesGetter;
2833

2934
@ParameterizedTest
3035
@MethodSource("spanNameParams")
@@ -40,18 +45,18 @@ void shouldExtractSpanName(
4045

4146
when(getter.getDestinationTemplate(message)).thenReturn(destinationTemplate);
4247
if (isAnonymous) {
43-
lenient().when(getter.isAnonymousDestination(message)).thenReturn(true);
48+
when(getter.isAnonymousDestination(message)).thenReturn(true);
4449
}
4550

4651
if (isTemporaryQueue) {
47-
lenient().when(getter.isTemporaryDestination(message)).thenReturn(true);
52+
when(getter.isTemporaryDestination(message)).thenReturn(true);
4853
} else {
49-
lenient().when(getter.getDestination(message)).thenReturn(destinationName);
54+
when(getter.getDestination(message)).thenReturn(destinationName);
5055
}
5156
when(getter.getOperationName(message, operation)).thenReturn(operation.operationType());
5257

53-
lenient().when(serverAttributesGetter.getServerPort(message)).thenReturn(1234);
54-
lenient().when(serverAttributesGetter.getServerAddress(message)).thenReturn("127.0.0.1");
58+
when(serverAttributesGetter.getServerPort(message)).thenReturn(1234);
59+
when(serverAttributesGetter.getServerAddress(message)).thenReturn("127.0.0.1");
5560

5661
SpanNameExtractor<Message> underTest =
5762
MessagingSpanNameExtractor.create(getter, operation, serverAttributesGetter);

0 commit comments

Comments
 (0)