// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/ExtensionTags.java
// public class ExtensionTags {
// 
//   private ExtensionTags() {
//   }
// 
//   /**
//    * Tag for {@link Class#getSimpleName()}
//    */
//   public static final StringTag CLASS_TAG = new StringTag("class");
// 
//   /**
//    * Tag for method name
//    */
//   public static final StringTag METHOD_TAG = new StringTag("method");
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/MockTracingConfiguration.java
// @Configuration
// @EnableAutoConfiguration
// public class MockTracingConfiguration {
// 
//   @Bean
//   public MockTracer mockTracer() {
//     GlobalTracerTestUtil.resetGlobalTracer();
//     return new MockTracer();
//   }
// 
//   @Bean
//   public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
//     return restTemplateBuilder.build();
//   }
// 
//   @Bean
//   public AsyncRestTemplate asyncRestTemplate() {
//     return new AsyncRestTemplate();
//   }
// 
//   public static TestRestTemplate createNotTracedRestTemplate(int port) {
//     return new TestRestTemplate(new RestTemplateBuilder().rootUri("http://localhost:" + port));
//   }
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/TestUtils.java
// public class TestUtils {
// 
//   /**
//    * Check if all spans have same traceId.
//    *
//    * @param spans the spans to check
//    */
//   public static void assertSameTraceId(Collection<MockSpan> spans) {
//     if (!spans.isEmpty()) {
//       final long traceId = spans.iterator().next().context().traceId();
//       for (MockSpan span : spans) {
//         Assert.assertEquals(traceId, span.context().traceId());
//       }
//     }
//   }
// }


import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.contrib.spring.cloud.ExtensionTags;
import io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.TestUtils;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;
import java.util.List;
import java.util.concurrent.Future;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    try (Scope scope = mockTracer.activateSpan(span)) {
      Future<String> fut = asyncService.fooAsync();
      await().until(() -> fut.isDone());
      assertThat(fut.get()).isNotNull();
    } finally {
      span.finish();
    }
    await().until(() -> mockTracer.finishedSpans().size() == 3);

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    // parent span from test, span modelling @Async, span inside @Async
    assertEquals(3, mockSpans.size());

    TestUtils.assertSameTraceId(mockSpans);

    MockSpan outerSpan = mockSpans.get(2);
    MockSpan fooAsyncSpan = mockSpans.get(1);
    MockSpan fooInnerSpan = mockSpans.get(0);

    assertEquals(
            "Expected the async method span to be a child of the outer span",
            outerSpan.context().spanId(), fooAsyncSpan.parentId());
    assertEquals(
            "Expected the inner span to be a child of the async method span",
            fooAsyncSpan.context().spanId(), fooInnerSpan.parentId());


    MockSpan asyncSpan = mockSpans.get(1);
    assertEquals(3, asyncSpan.tags().size());
    assertEquals(TraceAsyncAspect.TAG_COMPONENT, asyncSpan.tags().get(Tags.COMPONENT.getKey()));
// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/ExtensionTags.java
// public class ExtensionTags {
// 
//   private ExtensionTags() {
//   }
// 
//   /**
//    * Tag for {@link Class#getSimpleName()}
//    */
//   public static final StringTag CLASS_TAG = new StringTag("class");
// 
//   /**
//    * Tag for method name
//    */
//   public static final StringTag METHOD_TAG = new StringTag("method");
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/MockTracingConfiguration.java
// @Configuration
// @EnableAutoConfiguration
// public class MockTracingConfiguration {
// 
//   @Bean
//   public MockTracer mockTracer() {
//     GlobalTracerTestUtil.resetGlobalTracer();
//     return new MockTracer();
//   }
// 
//   @Bean
//   public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
//     return restTemplateBuilder.build();
//   }
// 
//   @Bean
//   public AsyncRestTemplate asyncRestTemplate() {
//     return new AsyncRestTemplate();
//   }
// 
//   public static TestRestTemplate createNotTracedRestTemplate(int port) {
//     return new TestRestTemplate(new RestTemplateBuilder().rootUri("http://localhost:" + port));
//   }
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/TestUtils.java
// public class TestUtils {
// 
//   /**
//    * Check if all spans have same traceId.
//    *
//    * @param spans the spans to check
//    */
//   public static void assertSameTraceId(Collection<MockSpan> spans) {
//     if (!spans.isEmpty()) {
//       final long traceId = spans.iterator().next().context().traceId();
//       for (MockSpan span : spans) {
//         Assert.assertEquals(traceId, span.context().traceId());
//       }
//     }
//   }
// }


// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/async/AsyncAnnotationTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.contrib.spring.cloud.ExtensionTags;
import io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.TestUtils;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;
import java.util.List;
import java.util.concurrent.Future;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

    try (Scope scope = mockTracer.activateSpan(span)) {
      Future<String> fut = asyncService.fooAsync();
      await().until(() -> fut.isDone());
      assertThat(fut.get()).isNotNull();
    } finally {
      span.finish();
    }
    await().until(() -> mockTracer.finishedSpans().size() == 3);

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    // parent span from test, span modelling @Async, span inside @Async
    assertEquals(3, mockSpans.size());

    TestUtils.assertSameTraceId(mockSpans);

    MockSpan outerSpan = mockSpans.get(2);
    MockSpan fooAsyncSpan = mockSpans.get(1);
    MockSpan fooInnerSpan = mockSpans.get(0);

    assertEquals(
            "Expected the async method span to be a child of the outer span",
            outerSpan.context().spanId(), fooAsyncSpan.parentId());
    assertEquals(
            "Expected the inner span to be a child of the async method span",
            fooAsyncSpan.context().spanId(), fooInnerSpan.parentId());


    MockSpan asyncSpan = mockSpans.get(1);
    assertEquals(3, asyncSpan.tags().size());
    assertEquals(TraceAsyncAspect.TAG_COMPONENT, asyncSpan.tags().get(Tags.COMPONENT.getKey()));
    assertEquals("fooAsync", asyncSpan.tags().get(ExtensionTags.METHOD_TAG.getKey()));