// 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 io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.TestUtils;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import java.util.List;
import java.util.concurrent.Callable;
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.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.WebAsyncTask;
    }

    @RequestMapping("/callable")
    public Callable<String> callable() {
      return () -> {
        mockTracer.buildSpan("foo").start().finish();
        return "callable";
      };
    }
  }

  @Autowired
  private MockTracer mockTracer;

  @LocalServerPort
  private int port;

  @Before
  public void before() {
    mockTracer.reset();
  }

  @Test
  public void testWebAsyncTaskTraceAndSpans() throws Exception {
    String response = MockTracingConfiguration.createNotTracedRestTemplate(port).getForObject("/webAsyncTask", String.class);
    assertThat(response).isNotNull();
    await().until(() -> mockTracer.finishedSpans().size() == 2);

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    assertEquals(2, mockSpans.size());
// 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/WebAsyncTaskTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
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 java.util.List;
import java.util.concurrent.Callable;
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.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.WebAsyncTask;

    }

    @RequestMapping("/callable")
    public Callable<String> callable() {
      return () -> {
        mockTracer.buildSpan("foo").start().finish();
        return "callable";
      };
    }
  }

  @Autowired
  private MockTracer mockTracer;

  @LocalServerPort
  private int port;

  @Before
  public void before() {
    mockTracer.reset();
  }

  @Test
  public void testWebAsyncTaskTraceAndSpans() throws Exception {
    String response = MockTracingConfiguration.createNotTracedRestTemplate(port).getForObject("/webAsyncTask", String.class);
    assertThat(response).isNotNull();
    await().until(() -> mockTracer.finishedSpans().size() == 2);

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    assertEquals(2, mockSpans.size());
    TestUtils.assertSameTraceId(mockSpans);