Skip to content

Commit c634f71

Browse files
committed
convert test to java
1 parent 1d8ac68 commit c634f71

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

sdk-autoconfigure-support/src/test/java/io/opentelemetry/instrumentation/tracer/AddThreadDetailsSpanProcessorTest.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,37 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.tracer
6+
package io.opentelemetry.instrumentation.tracer;
77

8-
import io.opentelemetry.context.Context
9-
import io.opentelemetry.sdk.trace.ReadWriteSpan
10-
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes
11-
import spock.lang.Specification
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.mockito.Mockito.mock;
10+
import static org.mockito.Mockito.verify;
11+
import static org.mockito.Mockito.verifyNoMoreInteractions;
1212

13-
class AddThreadDetailsSpanProcessorTest extends Specification {
14-
def span = Mock(ReadWriteSpan)
13+
import io.opentelemetry.context.Context;
14+
import io.opentelemetry.sdk.trace.ReadWriteSpan;
15+
import io.opentelemetry.sdk.trace.SpanProcessor;
16+
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
17+
import org.junit.jupiter.api.Test;
1518

16-
def processor = new AddThreadDetailsSpanProcessor()
19+
class AddThreadDetailsSpanProcessorTest {
1720

18-
def "should require onStart call"() {
19-
expect:
20-
processor.isStartRequired()
21-
}
21+
private ReadWriteSpan span = mock(ReadWriteSpan.class);
22+
23+
private SpanProcessor spanProcessor = new AddThreadDetailsSpanProcessor();
2224

23-
def "should set thread attributes on span start"() {
24-
given:
25-
def currentThreadName = Thread.currentThread().name
26-
def currentThreadId = Thread.currentThread().id
25+
@Test
26+
void onStart() {
27+
assertThat(spanProcessor.isStartRequired()).isTrue();
28+
}
2729

28-
when:
29-
processor.onStart(Context.root(), span)
30+
@Test
31+
void setThreadAttributes() {
32+
Thread thread = Thread.currentThread();
33+
spanProcessor.onStart(Context.root(), span);
3034

31-
then:
32-
1 * span.setAttribute(ThreadIncubatingAttributes.THREAD_ID, currentThreadId)
33-
1 * span.setAttribute(ThreadIncubatingAttributes.THREAD_NAME, currentThreadName)
35+
verify(span).setAttribute(ThreadIncubatingAttributes.THREAD_ID, thread.getId());
36+
verify(span).setAttribute(ThreadIncubatingAttributes.THREAD_NAME, thread.getName());
37+
verifyNoMoreInteractions(span);
3438
}
3539
}

0 commit comments

Comments
 (0)