Fixing tests

This commit is contained in:
Marcin Grzejszczak
2017-06-02 17:10:42 +02:00
parent ddf4ea131d
commit 83cc5b8064
12 changed files with 73 additions and 96 deletions

13
pom.xml
View File

@@ -195,6 +195,11 @@
<version>2.1</version>
<!-- not test because we need it in stream -->
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
@@ -209,19 +214,19 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.5.1</version>
<version>2.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.0.6</version>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.2</version>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -236,7 +241,7 @@
<checkstyle.version>2.17</checkstyle.version>
<spring-cloud-build.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-build.version>
<spring-cloud-commons.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-stream.version>Chelsea.BUILD-SNAPSHOT</spring-cloud-stream.version>
<spring-cloud-stream.version>Elmhurst.BUILD-SNAPSHOT</spring-cloud-stream.version>
<spring-cloud-netflix.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
</properties>

View File

@@ -104,6 +104,11 @@
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -16,26 +16,10 @@
package org.springframework.cloud.sleuth.documentation;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.junit.Test;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.NoOpSpanReporter;
import org.springframework.cloud.sleuth.Sampler;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.TraceCallable;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.TraceRunnable;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.*;
import org.springframework.cloud.sleuth.instrument.async.SpanContinuingTraceCallable;
import org.springframework.cloud.sleuth.instrument.async.SpanContinuingTraceRunnable;
import org.springframework.cloud.sleuth.log.NoOpSpanLogger;
@@ -44,6 +28,9 @@ import org.springframework.cloud.sleuth.trace.DefaultTracer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Random;
import java.util.concurrent.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
@@ -90,7 +77,7 @@ public class SpringCloudSleuthDocTests {
future.get();
// end::span_name_annotated_runnable_execution[]
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), (Span) BDDMockito.any());
}
@Test
@@ -115,7 +102,7 @@ public class SpringCloudSleuthDocTests {
future.get();
// end::span_name_to_string_runnable_execution[]
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), (Span) BDDMockito.any());
executorService.shutdown();
}

View File

@@ -16,11 +16,6 @@
package org.springframework.cloud.sleuth.instrument.async;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
@@ -32,9 +27,14 @@ import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.BDDMockito.then;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
/**
* @author Marcin Grzejszczak

View File

@@ -27,8 +27,8 @@ import rx.plugins.RxJavaPlugins;
import rx.plugins.RxJavaSchedulersHook;
import static org.assertj.core.api.BDDAssertions.then;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
/**

View File

@@ -16,12 +16,12 @@
package org.springframework.cloud.sleuth.instrument.web;
import java.util.regex.Pattern;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration.SkipPatternProviderConfig;
import java.util.regex.Pattern;
import static org.assertj.core.api.BDDAssertions.then;
/**
@@ -46,7 +46,7 @@ public class SkipPatternProviderConfigTest {
Pattern pattern = SkipPatternProviderConfig.getPatternForManagementServerProperties(new ManagementServerProperties(), sleuthWebProperties);
then(pattern.pattern()).isEqualTo("foo.*|bar.*");
then(pattern.pattern()).isEqualTo("foo.*|bar.*|/application.*");
}
@Test
@@ -65,7 +65,13 @@ public class SkipPatternProviderConfigTest {
SleuthWebProperties sleuthWebProperties = new SleuthWebProperties();
sleuthWebProperties.setSkipPattern("");
Pattern pattern = SkipPatternProviderConfig.getPatternForManagementServerProperties(new ManagementServerProperties(), sleuthWebProperties);
Pattern pattern = SkipPatternProviderConfig.getPatternForManagementServerProperties(
new ManagementServerProperties() {
@Override
public String getContextPath() {
return "";
}
}, sleuthWebProperties);
then(pattern.pattern()).isEqualTo(SleuthWebProperties.DEFAULT_SKIP_PATTERN);
}

View File

@@ -27,6 +27,7 @@ import org.springframework.cloud.sleuth.util.ArrayListSpanAccumulator;
import org.springframework.cloud.sleuth.util.ExceptionUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
@@ -272,6 +273,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
@Configuration
static class ManagementServer {
@Bean
@Primary
ManagementServerProperties managementServerProperties() {
ManagementServerProperties managementServerProperties = new ManagementServerProperties();
managementServerProperties.setContextPath("/additionalContextPath");

View File

@@ -16,24 +16,18 @@
package org.springframework.cloud.sleuth.instrument.web.client;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.function.Predicate;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.BDDMockito;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.NoOpSpanReporter;
import org.springframework.cloud.sleuth.TraceCallable;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.TraceRunnable;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.*;
import org.springframework.cloud.sleuth.log.NoOpSpanLogger;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.cloud.sleuth.trace.DefaultTracer;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import java.util.Random;
import java.util.concurrent.Callable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
/**
@@ -56,32 +50,28 @@ public class TraceAsyncListenableTaskExecutorTest {
public void should_submit_listenable_trace_runnable() throws Exception {
this.traceAsyncListenableTaskExecutor.submitListenable(aRunnable());
BDDMockito.then(this.delegate).should().submitListenable(
BDDMockito.argThat(matcher(Runnable.class, instanceOf(TraceRunnable.class))));
BDDMockito.then(this.delegate).should().submitListenable(any(TraceRunnable.class));
}
@Test
public void should_submit_listenable_trace_callable() throws Exception {
this.traceAsyncListenableTaskExecutor.submitListenable(aCallable());
BDDMockito.then(this.delegate).should().submitListenable(
BDDMockito.argThat(matcher(Callable.class, instanceOf(TraceCallable.class))));
BDDMockito.then(this.delegate).should().submitListenable(any(TraceCallable.class));
}
@Test
public void should_execute_a_trace_runnable() throws Exception {
this.traceAsyncListenableTaskExecutor.execute(aRunnable());
BDDMockito.then(this.delegate).should()
.execute(BDDMockito.argThat(matcher(Runnable.class, instanceOf(TraceRunnable.class))));
BDDMockito.then(this.delegate).should().execute(any(TraceRunnable.class));
}
@Test
public void should_execute_with_timeout_a_trace_runnable() throws Exception {
this.traceAsyncListenableTaskExecutor.execute(aRunnable(), 1L);
BDDMockito.then(this.delegate).should().execute(
BDDMockito.argThat(matcher(Runnable.class, instanceOf(TraceRunnable.class))),
BDDMockito.then(this.delegate).should().execute(any(TraceRunnable.class),
BDDMockito.anyLong());
}
@@ -89,24 +79,14 @@ public class TraceAsyncListenableTaskExecutorTest {
public void should_submit_trace_callable() throws Exception {
this.traceAsyncListenableTaskExecutor.submit(aCallable());
BDDMockito.then(this.delegate).should()
.submit(BDDMockito.argThat(matcher(Callable.class, instanceOf(TraceCallable.class))));
BDDMockito.then(this.delegate).should().submit(any(TraceCallable.class));
}
@Test
public void should_submit_trace_runnable() throws Exception {
this.traceAsyncListenableTaskExecutor.submit(aRunnable());
BDDMockito.then(this.delegate).should()
.submit(BDDMockito.argThat(matcher(Runnable.class, instanceOf(TraceRunnable.class))));
}
Predicate<Object> instanceOf(Class clazz) {
return (argument) -> argument.getClass().isAssignableFrom(clazz);
}
<T> ArgumentMatcher<T> matcher(Class<T> clazz, Predicate predicate) {
return predicate::test;
BDDMockito.then(this.delegate).should().submit(any(TraceRunnable.class));
}
Runnable aRunnable() {

View File

@@ -39,8 +39,8 @@ import com.netflix.niws.client.http.RestClient;
import com.netflix.zuul.context.RequestContext;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
/**

View File

@@ -24,10 +24,10 @@ import org.slf4j.MDC;
import org.springframework.cloud.sleuth.Span;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -89,7 +89,7 @@ public class Slf4JSpanLoggerTest {
this.slf4JSpanLogger.logStartedSpan(this.spanWithNameNotToBeExcluded,
this.spanWithNameNotToBeExcluded);
then(this.log).should(times(2)).trace(anyString(), anyList());
then(this.log).should(times(2)).trace(anyString(), any(Span.class));
}
@Test
@@ -97,7 +97,7 @@ public class Slf4JSpanLoggerTest {
this.slf4JSpanLogger.logStartedSpan(this.spanWithNameToBeExcluded,
this.spanWithNameNotToBeExcluded);
then(this.log).should().trace(anyString(), anyList());
then(this.log).should().trace(anyString(), any(Span.class));
}
@Test
@@ -105,21 +105,21 @@ public class Slf4JSpanLoggerTest {
this.slf4JSpanLogger.logContinuedSpan(
this.spanWithNameNotToBeExcluded);
then(this.log).should().trace(anyString(), anyList());
then(this.log).should().trace(anyString(), any(Span.class));
}
@Test
public void should_not_log_when_continue_event_arrived_and_pattern_matches_name() throws Exception {
this.slf4JSpanLogger.logContinuedSpan(this.spanWithNameToBeExcluded);
then(this.log).should(never()).trace(anyString(), anyList());
then(this.log).should(never()).trace(anyString(), any(Span.class));
}
@Test
public void should_log_when_close_event_arrived_and_pattern_doesnt_match_span_name() throws Exception {
this.slf4JSpanLogger.logStoppedSpan(null, this.spanWithNameNotToBeExcluded);
then(this.log).should().trace(anyString(), anyList());
then(this.log).should().trace(anyString(), any(Span.class));
}
@Test
@@ -127,7 +127,7 @@ public class Slf4JSpanLoggerTest {
this.slf4JSpanLogger.logStoppedSpan(this.spanWithNameNotToBeExcluded,
this.spanWithNameNotToBeExcluded);
then(this.log).should(times(2)).trace(anyString(), anyList());
then(this.log).should(times(2)).trace(anyString(), any(Span.class));
}
@Test
@@ -135,7 +135,7 @@ public class Slf4JSpanLoggerTest {
this.slf4JSpanLogger.logStoppedSpan(this.spanWithNameToBeExcluded,
this.spanWithNameToBeExcluded);
then(this.log).should(never()).trace(anyString(), anyList());
then(this.log).should(never()).trace(anyString(), any(Span.class));
}
@Test
@@ -143,14 +143,14 @@ public class Slf4JSpanLoggerTest {
this.slf4JSpanLogger.logStoppedSpan(this.spanWithNameNotToBeExcluded,
this.spanWithNameToBeExcluded);
then(this.log).should().trace(anyString(), anyList());
then(this.log).should().trace(anyString(), any(Span.class));
}
@Test
public void should_log_only_current_span_if_there_is_no_parent() throws Exception {
this.slf4JSpanLogger.logStoppedSpan(null, this.spanWithNameNotToBeExcluded);
then(this.log).should().trace(anyString(), anyList());
then(this.log).should().trace(anyString(), any(Span.class));
}
@Test

View File

@@ -16,10 +16,6 @@
package org.springframework.cloud.sleuth.trace;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -27,20 +23,17 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.SpanReporter;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.*;
import org.springframework.cloud.sleuth.log.SpanLogger;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.cloud.sleuth.sampler.NeverSampler;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
/**
@@ -82,8 +75,7 @@ public class DefaultTracerTests {
tracer.close(span);
}
verify(this.spanLogger, times(NUM_SPANS))
.logStartedSpan(Mockito.any(Span.class), Mockito.any(Span.class));
verify(this.spanLogger,atLeastOnce()).logStartedSpan(Mockito.any(Span.class), Mockito.any(Span.class));
verify(this.spanReporter, times(NUM_SPANS))
.report(Mockito.any(Span.class));

View File

@@ -18,7 +18,7 @@ package org.springframework.cloud.sleuth.stream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;