// 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));
//   }
// }


import io.opentracing.Tracer;
import io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.aop.Traced;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;
import org.assertj.core.api.WithAssertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  @Test
  public void givenActiveTracer_whenITraceWithCustomComponent_thenTraceIsGenerated() {
    tracedClass.tracedComponent();
    assertThat(tracer.finishedSpans()).hasSize(1);
    assertThat(tracer.finishedSpans().get(0).operationName()).isEqualTo("tracedComponent");
    assertThat(tracer.finishedSpans().get(0).tags().get(Tags.COMPONENT.getKey()))
        .isEqualTo("custom");
  }

  @Test
  public void givenActiveTracer_whenITraceWithCustomOperation_thenTraceIsGenerated() {
    tracedClass.tracedOperation();
    assertThat(tracer.finishedSpans()).hasSize(1);
    assertThat(tracer.finishedSpans().get(0).operationName()).isEqualTo("customOps");
    assertThat(tracer.finishedSpans().get(0).tags().get(Tags.COMPONENT.getKey()))
        .isEqualTo("traced");
  }

  @Test
  public void givenActiveTracer_whenITraceWhitChild_thenTraceIsGenerated() {
    tracedClass.child("someChildSpan");
    assertThat(tracer.finishedSpans()).hasSize(2);
    assertThat(tracer.finishedSpans().get(1).operationName()).isEqualTo("child");
    assertThat(tracer.finishedSpans().get(1).tags().get(Tags.COMPONENT.getKey()))
        .isEqualTo("traced");
    assertThat(tracer.finishedSpans().get(0).operationName()).isEqualTo("someChildSpan");
    assertThat(tracer.finishedSpans().get(0).tags()).isEmpty();
  }

  @SpringBootApplication
// 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/traced/TracedAutoConfigurationTest.java
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.aop.Traced;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;
import org.assertj.core.api.WithAssertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

  @Test
  public void givenActiveTracer_whenITraceWithCustomComponent_thenTraceIsGenerated() {
    tracedClass.tracedComponent();
    assertThat(tracer.finishedSpans()).hasSize(1);
    assertThat(tracer.finishedSpans().get(0).operationName()).isEqualTo("tracedComponent");
    assertThat(tracer.finishedSpans().get(0).tags().get(Tags.COMPONENT.getKey()))
        .isEqualTo("custom");
  }

  @Test
  public void givenActiveTracer_whenITraceWithCustomOperation_thenTraceIsGenerated() {
    tracedClass.tracedOperation();
    assertThat(tracer.finishedSpans()).hasSize(1);
    assertThat(tracer.finishedSpans().get(0).operationName()).isEqualTo("customOps");
    assertThat(tracer.finishedSpans().get(0).tags().get(Tags.COMPONENT.getKey()))
        .isEqualTo("traced");
  }

  @Test
  public void givenActiveTracer_whenITraceWhitChild_thenTraceIsGenerated() {
    tracedClass.child("someChildSpan");
    assertThat(tracer.finishedSpans()).hasSize(2);
    assertThat(tracer.finishedSpans().get(1).operationName()).isEqualTo("child");
    assertThat(tracer.finishedSpans().get(1).tags().get(Tags.COMPONENT.getKey()))
        .isEqualTo("traced");
    assertThat(tracer.finishedSpans().get(0).operationName()).isEqualTo("someChildSpan");
    assertThat(tracer.finishedSpans().get(0).tags()).isEmpty();
  }

  @SpringBootApplication
  @Import(MockTracingConfiguration.class)