This commit is contained in:
Phillip Webb 2016-09-02 09:33:00 +01:00
parent b5294a48b2
commit 41dc53f5dd
10 changed files with 46 additions and 57 deletions

View File

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

View File

@ -22,7 +22,6 @@ import java.util.Properties;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; 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.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; 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("cluster_size")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_up")).isEqualTo(4L); assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L); assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
verify(redisConnectionFactory, Mockito.atLeastOnce()).getConnection(); verify(redisConnectionFactory, atLeastOnce()).getConnection();
} }
} }

View File

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

View File

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

View File

@ -53,23 +53,24 @@ something similar to the following:
[indent=0] [indent=0]
---- ----
*************************** ***************************
APPLICATION FAILED TO START APPLICATION FAILED TO START
*************************** ***************************
Description: Description:
Embedded servlet container failed to start. Port 8080 was already in use. Embedded servlet container failed to start. Port 8080 was already in use.
Action: Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
---- ----
NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you can NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you can
<<howto.adoc#howto-failure-analyzer,add your own>> very easily. <<howto.adoc#howto-failure-analyzer,add your own>> very easily.
[[boot-features-banner]] [[boot-features-banner]]
=== Customizing the Banner === Customizing the Banner
The banner that is printed on start up can be changed by adding a `banner.txt` file The banner that is printed on start up can be changed by adding a `banner.txt` file

View File

@ -77,7 +77,8 @@ public class DataJpaTestIntegrationTests {
Long.class); Long.class);
assertThat(id).isNotNull(); assertThat(id).isNotNull();
String reference = this.jdbcTemplate.queryForObject( 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"); assertThat(reference).isEqualTo("123");
} }

View File

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

View File

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

View File

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

View File

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