pull/6842/head
Phillip Webb 8 years ago
parent b5294a48b2
commit 41dc53f5dd

@ -22,7 +22,6 @@ import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@ -48,6 +47,9 @@ import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link MetricExportAutoConfiguration}.
@ -82,7 +84,7 @@ public class MetricExportAutoConfigurationTests {
MetricExporters flusher = this.context.getBean(MetricExporters.class);
flusher.close(); // this will be called by Spring on shutdown
MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class));
verify(writer, atLeastOnce()).set(any(Metric.class));
}
@Test
@ -113,7 +115,7 @@ public class MetricExportAutoConfigurationTests {
exporter.setIgnoreTimestamps(true);
exporter.export();
MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class));
Mockito.verify(writer, Mockito.atLeastOnce()).set(any(Metric.class));
}
@Test

@ -22,7 +22,6 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration;
@ -38,6 +37,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@ -129,7 +129,7 @@ public class RedisHealthIndicatorTests {
assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
verify(redisConnectionFactory, Mockito.atLeastOnce()).getConnection();
verify(redisConnectionFactory, atLeastOnce()).getConnection();
}
}

@ -21,7 +21,6 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
@ -29,6 +28,7 @@ import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link MetricExporters}.
@ -43,9 +43,9 @@ public class MetricExportersTests {
private Map<String, GaugeWriter> writers = new LinkedHashMap<String, GaugeWriter>();
private MetricReader reader = Mockito.mock(MetricReader.class);
private MetricReader reader = mock(MetricReader.class);
private MetricWriter writer = Mockito.mock(MetricWriter.class);
private MetricWriter writer = mock(MetricWriter.class);
@Test
public void emptyWriters() {

@ -21,7 +21,6 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.http.HttpStatus;
@ -31,6 +30,7 @@ import org.springframework.web.client.RestOperations;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
@ -42,7 +42,7 @@ public class OpenTsdbGaugeWriterTests {
private OpenTsdbGaugeWriter writer;
private RestOperations restTemplate = Mockito.mock(RestOperations.class);
private RestOperations restTemplate = mock(RestOperations.class);
@Before
public void init() {

@ -70,6 +70,7 @@ NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you ca
<<howto.adoc#howto-failure-analyzer,add your own>> very easily.
[[boot-features-banner]]
=== Customizing the Banner
The banner that is printed on start up can be changed by adding a `banner.txt` file

@ -77,7 +77,8 @@ public class DataJpaTestIntegrationTests {
Long.class);
assertThat(id).isNotNull();
String reference = this.jdbcTemplate.queryForObject(
"SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?", new Object[] {id}, String.class);
"SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?", new Object[] { id },
String.class);
assertThat(reference).isEqualTo("123");
}

@ -25,7 +25,7 @@ import java.util.List;
*
* @author Andy Wilkinson
*/
public class MockitoBeans implements Iterable<Object> {
class MockitoBeans implements Iterable<Object> {
private final List<Object> beans = new ArrayList<Object>();

@ -37,9 +37,9 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriTemplateHandler;
/**
* {@link RequestExpectationManager} that strips the specified root URI from the
* request before verification. Can be used to simply test declarations when all REST
* calls start the same way. For example: <pre class="code">
* {@link RequestExpectationManager} that strips the specified root URI from the request
* before verification. Can be used to simply test declarations when all REST calls start
* the same way. For example: <pre class="code">
* RestTemplate restTemplate = new RestTemplateBuilder().rootUri("http://example.com").build();
* MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
* server.expect(requestTo("/hello")).andRespond(withSuccess());

@ -384,29 +384,25 @@ public class JsonContentAssertTests {
@Test
public void isEqualToJsonWhenStringIsMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(LENIENT_SAME,
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(LENIENT_SAME, COMPARATOR);
}
@Test(expected = AssertionError.class)
public void isEqualToJsonWhenStringIsNotMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(DIFFERENT,
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(DIFFERENT, COMPARATOR);
}
@Test
public void isEqualToJsonWhenResourcePathIsMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson("lenient-same.json",
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson("lenient-same.json", COMPARATOR);
}
@Test(expected = AssertionError.class)
public void isEqualToJsonWhenResourcePathIsNotMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson("different.json",
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson("different.json", COMPARATOR);
}
@Test
@ -426,29 +422,25 @@ public class JsonContentAssertTests {
@Test
public void isEqualToJsonWhenBytesAreMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(LENIENT_SAME.getBytes(),
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(LENIENT_SAME.getBytes(), COMPARATOR);
}
@Test(expected = AssertionError.class)
public void isEqualToJsonWhenBytesAreNotMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(DIFFERENT.getBytes(),
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(DIFFERENT.getBytes(), COMPARATOR);
}
@Test
public void isEqualToJsonWhenFileIsMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(createFile(LENIENT_SAME),
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(createFile(LENIENT_SAME), COMPARATOR);
}
@Test(expected = AssertionError.class)
public void isEqualToJsonWhenFileIsNotMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(createFile(DIFFERENT),
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(createFile(DIFFERENT), COMPARATOR);
}
@Test
@ -475,8 +467,7 @@ public class JsonContentAssertTests {
@Test(expected = AssertionError.class)
public void isEqualToJsonWhenResourceIsNotMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isEqualToJson(createResource(DIFFERENT),
COMPARATOR);
assertThat(forJson(SOURCE)).isEqualToJson(createResource(DIFFERENT), COMPARATOR);
}
@Test(expected = AssertionError.class)
@ -809,29 +800,25 @@ public class JsonContentAssertTests {
@Test(expected = AssertionError.class)
public void isNotEqualToJsonWhenStringIsMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson(LENIENT_SAME,
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson(LENIENT_SAME, COMPARATOR);
}
@Test
public void isNotEqualToJsonWhenStringIsNotMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson(DIFFERENT,
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson(DIFFERENT, COMPARATOR);
}
@Test(expected = AssertionError.class)
public void isNotEqualToJsonWhenResourcePathIsMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson("lenient-same.json",
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson("lenient-same.json", COMPARATOR);
}
@Test
public void isNotEqualToJsonWhenResourcePathIsNotMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson("different.json",
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson("different.json", COMPARATOR);
}
@Test(expected = AssertionError.class)
@ -851,15 +838,13 @@ public class JsonContentAssertTests {
@Test(expected = AssertionError.class)
public void isNotEqualToJsonWhenBytesAreMatchingAndComparatorShouldFail()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson(LENIENT_SAME.getBytes(),
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson(LENIENT_SAME.getBytes(), COMPARATOR);
}
@Test
public void isNotEqualToJsonWhenBytesAreNotMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson(DIFFERENT.getBytes(),
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson(DIFFERENT.getBytes(), COMPARATOR);
}
@Test(expected = AssertionError.class)
@ -872,8 +857,7 @@ public class JsonContentAssertTests {
@Test
public void isNotEqualToJsonWhenFileIsNotMatchingAndComparatorShouldPass()
throws Exception {
assertThat(forJson(SOURCE)).isNotEqualToJson(createFile(DIFFERENT),
COMPARATOR);
assertThat(forJson(SOURCE)).isNotEqualToJson(createFile(DIFFERENT), COMPARATOR);
}
@Test(expected = AssertionError.class)

@ -20,9 +20,10 @@ import java.util.Random;
import java.util.UUID;
import org.junit.Test;
import org.mockito.Mockito;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.spy;
/**
* Tests for {@link RandomValuePropertySource}.
@ -91,8 +92,8 @@ public class RandomValuePropertySourceTests {
@Test
public void longOverflow() {
RandomValuePropertySource source = Mockito.spy(this.source);
Mockito.when(source.getSource()).thenReturn(new Random() {
RandomValuePropertySource source = spy(this.source);
given(source.getSource()).willReturn(new Random() {
@Override
public long nextLong() {

Loading…
Cancel
Save