I´m trying to mock brave.Tracer. to get Tracer.currenSpan(), but I can´t get it, here is my code.
I´m usign:
io.zipkin.brave:5.13.9
spring-cloud-sleuth-zipkin:3.1.3
could you give me some advice?
my test method
import brave.Span;
import brave.Tracer;
import brave.Tracing;
@ExtendedWith(SpringExtension.class)
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM.PORT,
classes = {Main.class, TestConfig.class})
public class TestingClass{
@Autowired
private Tracer tracer;
@Test
public void must_return_currentSpan() throws Exception {
brave.Span span = Tracing.newBuilder().build().tracer().nextSpan().name("span").start();
doReturn(span).when(tracer).currentSpan();
mvc.perform(get("the url")); //this is only contextual, an example to avoid write all code.
}
}
the class to test
import brave.Span;
@Service
@RequiredArgsConstructor
public class TheClass {
private final Tracer tracer;
public Span generateSpan() {
return tracer.currentSpan();
}
}
In some point after execute the test method, I get this error
java.lang.NullPointerException: Cannot invoke "brave.Tracer$SpanInScope.close()" because "this.delegate" is null
at org.springframework.cloud.sleuth.brave.bridge.BraveSpanInScope.close(BraveTracer.java:153)
Hi
I´m trying to mock brave.Tracer. to get Tracer.currenSpan(), but I can´t get it, here is my code.
I´m usign:
could you give me some advice?
my test method
the class to test
In some point after execute the test method, I get this error