diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java index 59c848f376..97ae9643e3 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java @@ -47,10 +47,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; /** * Tests for {@link MetricRepositoryAutoConfiguration}. @@ -129,7 +129,7 @@ public class MetricRepositoryAutoConfigurationTests { RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class); assertNotNull(richGaugeReader); - when(richGaugeReader.findAll()).thenReturn( + given(richGaugeReader.findAll()).willReturn( Collections.singletonList(new RichGauge("bar", 3.7d))); RichGaugeReaderPublicMetrics publicMetrics = context diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java index 814731c3e6..08c7873eb4 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java @@ -28,8 +28,8 @@ import org.springframework.http.ResponseEntity; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link HealthMvcEndpoint}. @@ -45,13 +45,13 @@ public class HealthMvcEndpointTests { @Before public void init() { this.endpoint = mock(HealthEndpoint.class); - when(this.endpoint.isEnabled()).thenReturn(true); + given(this.endpoint.isEnabled()).willReturn(true); this.mvc = new HealthMvcEndpoint(this.endpoint); } @Test public void up() { - when(this.endpoint.invoke()).thenReturn(new Health.Builder().up().build()); + given(this.endpoint.invoke()).willReturn(new Health.Builder().up().build()); Object result = this.mvc.invoke(); assertTrue(result instanceof Health); assertTrue(((Health) result).getStatus() == Status.UP); @@ -60,7 +60,7 @@ public class HealthMvcEndpointTests { @SuppressWarnings("unchecked") @Test public void down() { - when(this.endpoint.invoke()).thenReturn(new Health.Builder().down().build()); + given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); Object result = this.mvc.invoke(); assertTrue(result instanceof ResponseEntity); ResponseEntity response = (ResponseEntity) result; @@ -71,8 +71,8 @@ public class HealthMvcEndpointTests { @SuppressWarnings("unchecked") @Test public void customMapping() { - when(this.endpoint.invoke()) - .thenReturn(new Health.Builder().status("OK").build()); + given(this.endpoint.invoke()).willReturn( + new Health.Builder().status("OK").build()); this.mvc.setStatusMapping(Collections.singletonMap("OK", HttpStatus.INTERNAL_SERVER_ERROR)); Object result = this.mvc.invoke(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java index ba25de88b5..98764dec2d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint.mvc; import java.util.Map; -import org.junit.Before; import org.junit.Test; import org.springframework.boot.actuate.endpoint.ShutdownEndpoint; import org.springframework.http.HttpStatus; @@ -26,7 +25,6 @@ import org.springframework.http.ResponseEntity; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link ShutdownMvcEndpoint}. @@ -36,12 +34,8 @@ import static org.mockito.Mockito.when; public class ShutdownMvcEndpointTests { private ShutdownEndpoint endpoint = mock(ShutdownEndpoint.class); - private ShutdownMvcEndpoint mvc = new ShutdownMvcEndpoint(this.endpoint); - @Before - public void init() { - when(this.endpoint.isEnabled()).thenReturn(false); - } + private ShutdownMvcEndpoint mvc = new ShutdownMvcEndpoint(this.endpoint); @Test public void disabled() { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java index 9d821ebd2b..0eb4e05bae 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java @@ -31,10 +31,10 @@ import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; /** * Tests for {@link DataSourceHealthIndicator}. @@ -88,9 +88,9 @@ public class DataSourceHealthIndicatorTests { public void connectionClosed() throws Exception { DataSource dataSource = mock(DataSource.class); Connection connection = mock(Connection.class); - when(connection.getMetaData()).thenReturn( + given(connection.getMetaData()).willReturn( this.dataSource.getConnection().getMetaData()); - when(dataSource.getConnection()).thenReturn(connection); + given(dataSource.getConnection()).willReturn(connection); this.indicator.setDataSource(dataSource); Health health = this.indicator.health(); assertNotNull(health.getDetails().get("database")); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java index bd3938f593..ae5fc29882 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.health; 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; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; @@ -33,6 +32,9 @@ import com.mongodb.MongoException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /** * Tests for {@link MongoHealthIndicator}. @@ -64,25 +66,24 @@ public class MongoHealthIndicatorTests { @Test public void mongoIsUp() throws Exception { - CommandResult commandResult = Mockito.mock(CommandResult.class); - Mockito.when(commandResult.getString("version")).thenReturn("2.6.4"); - MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class); - Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenReturn( - commandResult); + CommandResult commandResult = mock(CommandResult.class); + given(commandResult.getString("version")).willReturn("2.6.4"); + MongoTemplate mongoTemplate = mock(MongoTemplate.class); + given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(commandResult); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); Health health = healthIndicator.health(); assertEquals(Status.UP, health.getStatus()); assertEquals("2.6.4", health.getDetails().get("version")); - Mockito.verify(commandResult).getString("version"); - Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); + verify(commandResult).getString("version"); + verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); } @Test public void mongoIsDown() throws Exception { - MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class); - Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenThrow( + MongoTemplate mongoTemplate = mock(MongoTemplate.class); + given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow( new MongoException("Connection failed")); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); @@ -91,6 +92,6 @@ public class MongoHealthIndicatorTests { assertTrue(((String) health.getDetails().get("error")) .contains("Connection failed")); - Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); + verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java index 839bd57e6c..87bb844100 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java @@ -20,7 +20,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; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; @@ -33,6 +32,9 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /** * Tests for {@link RedisHealthIndicator}. @@ -67,11 +69,10 @@ public class RedisHealthIndicatorTests { Properties info = new Properties(); info.put("redis_version", "2.8.9"); - RedisConnection redisConnection = Mockito.mock(RedisConnection.class); - RedisConnectionFactory redisConnectionFactory = Mockito - .mock(RedisConnectionFactory.class); - Mockito.when(redisConnectionFactory.getConnection()).thenReturn(redisConnection); - Mockito.when(redisConnection.info()).thenReturn(info); + RedisConnection redisConnection = mock(RedisConnection.class); + RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class); + given(redisConnectionFactory.getConnection()).willReturn(redisConnection); + given(redisConnection.info()).willReturn(info); RedisHealthIndicator healthIndicator = new RedisHealthIndicator( redisConnectionFactory); @@ -79,17 +80,16 @@ public class RedisHealthIndicatorTests { assertEquals(Status.UP, health.getStatus()); assertEquals("2.8.9", health.getDetails().get("version")); - Mockito.verify(redisConnectionFactory).getConnection(); - Mockito.verify(redisConnection).info(); + verify(redisConnectionFactory).getConnection(); + verify(redisConnection).info(); } @Test public void redisIsDown() throws Exception { - RedisConnection redisConnection = Mockito.mock(RedisConnection.class); - RedisConnectionFactory redisConnectionFactory = Mockito - .mock(RedisConnectionFactory.class); - Mockito.when(redisConnectionFactory.getConnection()).thenReturn(redisConnection); - Mockito.when(redisConnection.info()).thenThrow( + RedisConnection redisConnection = mock(RedisConnection.class); + RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class); + given(redisConnectionFactory.getConnection()).willReturn(redisConnection); + given(redisConnection.info()).willThrow( new RedisConnectionFailureException("Connection failed")); RedisHealthIndicator healthIndicator = new RedisHealthIndicator( redisConnectionFactory); @@ -99,7 +99,7 @@ public class RedisHealthIndicatorTests { assertTrue(((String) health.getDetails().get("error")) .contains("Connection failed")); - Mockito.verify(redisConnectionFactory).getConnection(); - Mockito.verify(redisConnection).info(); + verify(redisConnectionFactory).getConnection(); + verify(redisConnection).info(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java index e29b7ab5a1..a60b4147c8 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java @@ -32,8 +32,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link SolrHealthIndicator} @@ -69,7 +69,7 @@ public class SolrHealthIndicatorTests { NamedList response = new NamedList(); response.add("status", "OK"); pingResponse.setResponse(response); - when(solrServer.ping()).thenReturn(pingResponse); + given(solrServer.ping()).willReturn(pingResponse); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer); Health health = healthIndicator.health(); @@ -80,7 +80,7 @@ public class SolrHealthIndicatorTests { @Test public void solrIsDown() throws Exception { SolrServer solrServer = mock(SolrServer.class); - when(solrServer.ping()).thenThrow(new IOException("Connection failed")); + given(solrServer.ping()).willThrow(new IOException("Connection failed")); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer); Health health = healthIndicator.health(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java index 3c0f2f3825..94b0be51ff 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.security; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.security.authentication.BadCredentialsException; @@ -30,6 +29,7 @@ import org.springframework.security.core.userdetails.User; import org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent; import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** @@ -39,8 +39,7 @@ public class AuthenticationAuditListenerTests { private final AuthenticationAuditListener listener = new AuthenticationAuditListener(); - private final ApplicationEventPublisher publisher = Mockito - .mock(ApplicationEventPublisher.class); + private final ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class); @Before public void init() { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java index 8112af6e82..58423c0be3 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java @@ -20,7 +20,6 @@ import java.util.Arrays; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.security.access.AccessDeniedException; @@ -30,6 +29,7 @@ import org.springframework.security.access.event.AuthorizationFailureEvent; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** @@ -39,8 +39,7 @@ public class AuthorizationAuditListenerTests { private final AuthorizationAuditListener listener = new AuthorizationAuditListener(); - private final ApplicationEventPublisher publisher = Mockito - .mock(ApplicationEventPublisher.class); + private final ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class); @Before public void init() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index e2bca318d1..8e2c4ff9b4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -20,7 +20,6 @@ import javax.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.pool.PooledConnectionFactory; - import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java index 5a68395b8d..b383db98d9 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java @@ -145,6 +145,7 @@ public class RepositoryRestMvcAutoConfigurationTests { objectMapperBuilder.simpleDateFormat("yyyy-MM"); return objectMapperBuilder; } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java index 2b8b7d3e5e..c94dc9bf76 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java @@ -69,4 +69,5 @@ public class SpringDataWebAutoConfigurationTests { .getBeansOfType(PageableHandlerMethodArgumentResolver.class); assertThat(beans.size(), is(equalTo(0))); } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java index 335dc2828e..b1b77b91ce 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java @@ -25,7 +25,6 @@ import org.joda.time.LocalDateTime; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -53,6 +52,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** @@ -365,7 +365,7 @@ public class JacksonAutoConfigurationTests { @Bean @Primary public ObjectMapper objectMapper() { - return Mockito.mock(ObjectMapper.class); + return mock(ObjectMapper.class); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index 93bf7574af..5d5660666e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -33,7 +33,6 @@ import org.apache.commons.dbcp.BasicDataSource; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.EnvironmentTestUtils; @@ -51,6 +50,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; /** * Tests for {@link DataSourceAutoConfiguration}. @@ -263,7 +263,7 @@ public class DataSourceAutoConfigurationTests { @Override public Connection connect(String url, Properties info) throws SQLException { - return Mockito.mock(Connection.class); + return mock(Connection.class); } @Override @@ -294,7 +294,7 @@ public class DataSourceAutoConfigurationTests { @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { - return Mockito.mock(Logger.class); + return mock(Logger.class); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilderTests.java index f36bbd915c..0013d0c568 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilderTests.java @@ -21,12 +21,12 @@ import java.util.Collections; import javax.sql.DataSource; import org.junit.Test; -import org.mockito.Mockito; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; /** * Tests for {@link EntityManagerFactoryBuilder}. @@ -37,9 +37,9 @@ public class EntityManagerFactoryBuilderTests { private JpaProperties properties = new JpaProperties(); - private DataSource dataSource1 = Mockito.mock(DataSource.class); + private DataSource dataSource1 = mock(DataSource.class); - private DataSource dataSource2 = Mockito.mock(DataSource.class); + private DataSource dataSource2 = mock(DataSource.class); @Test public void entityManagerFactoryPropertiesNotOverwritingDefaults() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index c2550ecb94..b2ade70ece 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -23,7 +23,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Mockito; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; @@ -40,6 +39,8 @@ import org.springframework.context.annotation.Configuration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /** * Tests for {@link ServerPropertiesAutoConfiguration}. @@ -57,7 +58,7 @@ public class ServerPropertiesAutoConfigurationTests { @Before public void init() { - containerFactory = Mockito.mock(AbstractEmbeddedServletContainerFactory.class); + containerFactory = mock(AbstractEmbeddedServletContainerFactory.class); } @After @@ -77,12 +78,12 @@ public class ServerPropertiesAutoConfigurationTests { ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); assertEquals(9000, server.getPort().intValue()); - Mockito.verify(containerFactory).setPort(9000); + verify(containerFactory).setPort(9000); } @Test public void tomcatProperties() throws Exception { - containerFactory = Mockito.mock(TomcatEmbeddedServletContainerFactory.class); + containerFactory = mock(TomcatEmbeddedServletContainerFactory.class); this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); @@ -92,7 +93,7 @@ public class ServerPropertiesAutoConfigurationTests { ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); assertEquals(new File("target/foo"), server.getTomcat().getBasedir()); - Mockito.verify(containerFactory).setPort(9000); + verify(containerFactory).setPort(9000); } @Test @@ -113,7 +114,7 @@ public class ServerPropertiesAutoConfigurationTests { @Test public void customizeTomcatWithCustomizer() throws Exception { - containerFactory = Mockito.mock(TomcatEmbeddedServletContainerFactory.class); + containerFactory = mock(TomcatEmbeddedServletContainerFactory.class); this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.register(Config.class, CustomizeConfig.class, ServerPropertiesAutoConfiguration.class, @@ -123,7 +124,7 @@ public class ServerPropertiesAutoConfigurationTests { assertNotNull(server); // The server.port environment property was not explicitly set so the container // customizer should take precedence... - Mockito.verify(containerFactory).setPort(3000); + verify(containerFactory).setPort(3000); } @Test diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/DependencyResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/DependencyResolver.java index fc28f0e2b3..de664e512e 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/DependencyResolver.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/DependencyResolver.java @@ -20,6 +20,9 @@ import java.io.File; import java.util.List; /** + * Resolve artifact identifiers (typically in the form {@literal group:artifact:version}) + * to {@link File}s. + * * @author Andy Wilkinson * @since 1.2.0 */ @@ -28,7 +31,6 @@ interface DependencyResolver { /** * Resolves the given {@code artifactIdentifiers}, typically in the form * "group:artifact:version", and their dependencies. - * * @param artifactIdentifiers The artifacts to resolve * @return The {@code File}s for the resolved artifacts * @throws Exception if dependency resolution fails diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolver.java index 7ce76c96d2..0ade46d745 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolver.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolver.java @@ -55,11 +55,9 @@ class GroovyGrabDependencyResolver implements DependencyResolver { groovyCompiler.compile(createSources(artifactIdentifiers)); List artifactUrls = getClassPathUrls(groovyCompiler); artifactUrls.removeAll(initialUrls); - for (URL artifactUrl : artifactUrls) { artifactFiles.add(toFile(artifactUrl)); } - } return artifactFiles; } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/InstallCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/InstallCommand.java index 8ecada309f..2c44480376 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/InstallCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/InstallCommand.java @@ -24,6 +24,7 @@ import org.springframework.boot.cli.command.OptionParsingCommand; import org.springframework.boot.cli.command.options.CompilerOptionHandler; import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.util.Log; +import org.springframework.util.Assert; /** * {@link Command} to install additional dependencies into the CLI. @@ -47,24 +48,18 @@ public class InstallCommand extends OptionParsingCommand { private static final class InstallOptionHandler extends CompilerOptionHandler { @Override + @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { - - @SuppressWarnings("unchecked") List args = (List) options.nonOptionArguments(); - - if (args.isEmpty()) { - throw new IllegalArgumentException( - "Please specify at least one dependency, in the form group:artifact:version, to install"); - } - + Assert.notEmpty(args, "Please specify at least one " + + "dependency, in the form group:artifact:version, to install"); try { new Installer(options, this).install(args); } - catch (Exception e) { - String message = e.getMessage(); - Log.error(message != null ? message : e.getClass().toString()); + catch (Exception ex) { + String message = ex.getMessage(); + Log.error(message != null ? message : ex.getClass().toString()); } - return ExitStatus.OK; } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java index 7a53464436..3bf72d3200 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java @@ -35,6 +35,8 @@ import org.springframework.util.FileCopyUtils; import org.springframework.util.SystemPropertyUtils; /** + * Shared logic for the {@link InstallCommand} and {@link UninstallCommand}. + * * @author Andy Wilkinson * @since 1.2.0 */ @@ -44,13 +46,13 @@ class Installer { private final Properties installCounts; - Installer(OptionSet options, CompilerOptionHandler compilerOptionHandler) + public Installer(OptionSet options, CompilerOptionHandler compilerOptionHandler) throws IOException { this(new GroovyGrabDependencyResolver(createCompilerConfiguration(options, compilerOptionHandler))); } - Installer(DependencyResolver resolver) throws IOException { + public Installer(DependencyResolver resolver) throws IOException { this.dependencyResolver = resolver; this.installCounts = loadInstallCounts(); } @@ -59,7 +61,6 @@ class Installer { OptionSet options, CompilerOptionHandler compilerOptionHandler) { List repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); - return new OptionSetGroovyCompilerConfiguration(options, compilerOptionHandler, repositoryConfiguration) { @Override @@ -69,17 +70,14 @@ class Installer { }; } - private static Properties loadInstallCounts() throws IOException { - + private Properties loadInstallCounts() throws IOException { Properties properties = new Properties(); - File installed = getInstalled(); if (installed.exists()) { FileReader reader = new FileReader(installed); properties.load(reader); reader.close(); } - return properties; } @@ -96,9 +94,7 @@ class Installer { public void install(List artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); libDirectory.mkdirs(); - Log.info("Installing into: " + libDirectory); - List artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); @@ -108,7 +104,6 @@ class Installer { } setInstallCount(artifactFile, installCount + 1); } - saveInstallCounts(); } @@ -131,9 +126,7 @@ class Installer { public void uninstall(List artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); - Log.info("Uninstalling from: " + libDirectory); - List artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); @@ -142,31 +135,27 @@ class Installer { } setInstallCount(artifactFile, installCount - 1); } - saveInstallCounts(); } public void uninstallAll() throws Exception { File libDirectory = getDefaultLibDirectory(); - Log.info("Uninstalling from: " + libDirectory); - for (String name : this.installCounts.stringPropertyNames()) { new File(libDirectory, name).delete(); } - this.installCounts.clear(); saveInstallCounts(); } - private static File getDefaultLibDirectory() { + private File getDefaultLibDirectory() { String home = SystemPropertyUtils .resolvePlaceholders("${spring.home:${SPRING_HOME:.}}"); - final File lib = new File(home, "lib"); - return lib; + return new File(home, "lib"); } - private static File getInstalled() { + private File getInstalled() { return new File(getDefaultLibDirectory(), ".installed"); } + } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/UninstallCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/UninstallCommand.java index bf136d986f..9c783cb020 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/UninstallCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/UninstallCommand.java @@ -56,34 +56,28 @@ public class UninstallCommand extends OptionParsingCommand { } @Override + @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { - - @SuppressWarnings("unchecked") List args = (List) options.nonOptionArguments(); - try { if (options.has(this.allOption)) { if (!args.isEmpty()) { throw new IllegalArgumentException( "Please use --all without specifying any dependencies"); } - new Installer(options, this).uninstallAll(); } if (args.isEmpty()) { throw new IllegalArgumentException( "Please specify at least one dependency, in the form group:artifact:version, to uninstall"); } - new Installer(options, this).uninstall(args); } - catch (Exception e) { - String message = e.getMessage(); - Log.error(message != null ? message : e.getClass().toString()); + catch (Exception ex) { + String message = ex.getMessage(); + Log.error(message != null ? message : ex.getClass().toString()); } - return ExitStatus.OK; - } } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/RabbitCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/RabbitCompilerAutoConfiguration.java index c6099a8272..686fc76b24 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/RabbitCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/RabbitCompilerAutoConfiguration.java @@ -22,7 +22,6 @@ import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.springframework.boot.cli.compiler.AstUtils; import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; import org.springframework.boot.cli.compiler.DependencyCustomizer; -import org.springframework.boot.groovy.EnableRabbitMessaging; /** * {@link CompilerAutoConfiguration} for Spring Rabbit. @@ -46,6 +45,7 @@ public class RabbitCompilerAutoConfiguration extends CompilerAutoConfiguration { } @Override + @SuppressWarnings("deprecation") public void applyImports(ImportCustomizer imports) throws CompilationFailedException { imports.addStarImports("org.springframework.amqp.rabbit.annotation", "org.springframework.amqp.rabbit.core", @@ -54,7 +54,7 @@ public class RabbitCompilerAutoConfiguration extends CompilerAutoConfiguration { "org.springframework.amqp.rabbit.listener", "org.springframework.amqp.rabbit.listener.adapter", "org.springframework.amqp.core").addImports( - EnableRabbitMessaging.class.getCanonicalName()); + org.springframework.boot.groovy.EnableRabbitMessaging.class.getName()); } } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java index f8d936ce8b..7c746390cd 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java @@ -78,6 +78,7 @@ public class GroovyGrabDependencyResolverTests { public String[] getClasspath() { return new String[] { "." }; } + }; this.resolver = new GroovyGrabDependencyResolver(configuration); } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/InstallerTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/InstallerTests.java index 2130e7d074..e667d7f962 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/InstallerTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/InstallerTests.java @@ -32,8 +32,8 @@ import org.springframework.util.FileSystemUtils; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link Installer} @@ -65,22 +65,17 @@ public class InstallerTests { @Test public void installNewDependency() throws Exception { File foo = createTemporaryFile("foo.jar"); - - when(this.resolver.resolve(Arrays.asList("foo"))).thenReturn(Arrays.asList(foo)); + given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo)); this.installer.install(Arrays.asList("foo")); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder("foo.jar", ".installed")); } @Test public void installAndUninstall() throws Exception { File foo = createTemporaryFile("foo.jar"); - - when(this.resolver.resolve(Arrays.asList("foo"))).thenReturn(Arrays.asList(foo)); - + given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo)); this.installer.install(Arrays.asList("foo")); this.installer.uninstall(Arrays.asList("foo")); - assertThat(getNamesOfFilesInLib(), contains(".installed")); } @@ -89,30 +84,24 @@ public class InstallerTests { File alpha = createTemporaryFile("alpha.jar"); File bravo = createTemporaryFile("bravo.jar"); File charlie = createTemporaryFile("charlie.jar"); - - when(this.resolver.resolve(Arrays.asList("bravo"))).thenReturn( + given(this.resolver.resolve(Arrays.asList("bravo"))).willReturn( Arrays.asList(bravo, alpha)); - - when(this.resolver.resolve(Arrays.asList("charlie"))).thenReturn( + given(this.resolver.resolve(Arrays.asList("charlie"))).willReturn( Arrays.asList(charlie, alpha)); this.installer.install(Arrays.asList("bravo")); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar", ".installed")); this.installer.install(Arrays.asList("charlie")); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar", "charlie.jar", ".installed")); this.installer.uninstall(Arrays.asList("bravo")); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "charlie.jar", ".installed")); this.installer.uninstall(Arrays.asList("charlie")); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed")); } @@ -122,20 +111,17 @@ public class InstallerTests { File bravo = createTemporaryFile("bravo.jar"); File charlie = createTemporaryFile("charlie.jar"); - when(this.resolver.resolve(Arrays.asList("bravo"))).thenReturn( + given(this.resolver.resolve(Arrays.asList("bravo"))).willReturn( Arrays.asList(bravo, alpha)); - - when(this.resolver.resolve(Arrays.asList("charlie"))).thenReturn( + given(this.resolver.resolve(Arrays.asList("charlie"))).willReturn( Arrays.asList(charlie, alpha)); this.installer.install(Arrays.asList("bravo")); this.installer.install(Arrays.asList("charlie")); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar", "charlie.jar", ".installed")); this.installer.uninstallAll(); - assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed")); } @@ -152,4 +138,5 @@ public class InstallerTests { temporaryFile.deleteOnExit(); return temporaryFile; } + } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java index 8500c9d2ac..7f915799ae 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java @@ -35,7 +35,7 @@ import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; /** * Tests for {@link DependencyCustomizer} @@ -56,13 +56,12 @@ public class DependencyCustomizerTests { @Before public void setUp() { MockitoAnnotations.initMocks(this); - - when(this.resolver.getGroupId("spring-boot-starter-logging")).thenReturn( + given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn( "org.springframework.boot"); - when(this.resolver.getArtifactId("spring-boot-starter-logging")).thenReturn( + given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn( "spring-boot-starter-logging"); - when(this.resolver.getVersion("spring-boot-starter-logging")).thenReturn("1.2.3"); - + given(this.resolver.getVersion("spring-boot-starter-logging")) + .willReturn("1.2.3"); this.moduleNode.addClass(this.classNode); this.dependencyCustomizer = new DependencyCustomizer(new GroovyClassLoader( getClass().getClassLoader()), this.moduleNode, @@ -169,4 +168,5 @@ public class DependencyCustomizerTests { private Object getMemberValue(AnnotationNode annotationNode, String member) { return ((ConstantExpression) annotationNode.getMember(member)).getValue(); } + } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java index 4a45c8dd22..919ff4eba5 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java @@ -46,8 +46,8 @@ import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesRes import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; import static org.junit.Assert.assertEquals; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link ResolveDependencyCoordinatesTransformation} @@ -73,9 +73,9 @@ public final class ResolveDependencyCoordinatesTransformationTests { @Before public void setupExpectations() { - when(this.coordinatesResolver.getGroupId("spring-core")).thenReturn( + given(this.coordinatesResolver.getGroupId("spring-core")).willReturn( "org.springframework"); - when(this.coordinatesResolver.getVersion("spring-core")).thenReturn("4.0.0.RC1"); + given(this.coordinatesResolver.getVersion("spring-core")).willReturn("4.0.0.RC1"); } @Test diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 436a3f9788..4016e88818 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2047,7 +2047,7 @@ customize the Atomikos `UserTransactionServiceIml`. See the {dc-spring-boot}/jta/atomikos/AtomikosProperties.{dc-ext}[`AtomikosProperties` javadoc] for complete details. -CAUTION: To ensure that multiple transaction managers can safely coordinate the same +NOTE: To ensure that multiple transaction managers can safely coordinate the same resource managers, each Atomikos instance must be configured with a unique ID. By default this ID is the IP address of the machine on which Atomikos is running. To ensure uniqueness in production, you should configure the `spring.jta.transaction-manager-id` @@ -2069,7 +2069,7 @@ are also bound to the `bitronix.tm.Configuration` bean, allowing for complete customization. See the http://btm.codehaus.org/api/2.0.1/bitronix/tm/Configuration.html[Bitronix documentation] for details. -CAUTION: To ensure that multiple transaction managers can safely coordinate the same +NOTE: To ensure that multiple transaction managers can safely coordinate the same resource managers, each Bitronix instance must be configured with a unique ID. By default this ID is the IP address of the machine on which Bitronix is running. To ensure uniqueness in production, you should configure the `spring.jta.transaction-manager-id` diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/snake/SnakeTimerTests.java index c58be5a57b..9a8305e46b 100644 --- a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/snake/SnakeTimerTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/snake/SnakeTimerTests.java @@ -22,8 +22,8 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.willThrow; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; public class SnakeTimerTests { @@ -31,7 +31,7 @@ public class SnakeTimerTests { @Test public void removeDysfunctionalSnakes() throws Exception { Snake snake = mock(Snake.class); - doThrow(new IOException()).when(snake).sendMessage(anyString()); + willThrow(new IOException()).given(snake).sendMessage(anyString()); SnakeTimer.addSnake(snake); SnakeTimer.broadcast(""); diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java index 3a52f7f73c..3108b35287 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java @@ -29,7 +29,7 @@ import org.springframework.boot.loader.archive.Archive.Entry; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; /** * Tests for {@link ExecutableArchiveLauncher} @@ -71,9 +71,7 @@ public class ExecutableArchiveLauncherTests { public void javaAgentJarsAreExcludedFromClasspath() throws Exception { URL javaAgent = new File("my-agent.jar").getCanonicalFile().toURI().toURL(); final URL one = new URL("file:one"); - - when(this.javaAgentDetector.isJavaAgentJar(javaAgent)).thenReturn(true); - + given(this.javaAgentDetector.isJavaAgentJar(javaAgent)).willReturn(true); doWithTccl(new URLClassLoader(new URL[] { javaAgent, one }), new Callable() { diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java index 6a1d498d1e..07ef2746a1 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java @@ -20,7 +20,7 @@ import org.slf4j.bridge.SLF4JBridgeHandler; import org.springframework.util.ClassUtils; /** - * Abstract base class for {@link LoggingSystem} implementations that utilise SLF4J. + * Abstract base class for {@link LoggingSystem} implementations that utilize SLF4J. * * @author Andy Wilkinson * @since 1.2.0 diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 0c9ad21529..ff12539a0f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -72,6 +72,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -152,10 +153,11 @@ public class SpringApplicationTests { application.setWebEnvironment(false); application.setShowBanner(false); application.run(); - verify(application, never()).printBanner(); + verify(application, never()).printBanner((Environment) anyObject()); } @Test + @SuppressWarnings("deprecation") public void customBanner() throws Exception { SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); application.setWebEnvironment(false); @@ -164,6 +166,7 @@ public class SpringApplicationTests { } @Test + @SuppressWarnings("deprecation") public void customBannerWithProperties() throws Exception { SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); application.setWebEnvironment(false); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java index 37cbb57924..3e8341ad21 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java @@ -35,7 +35,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.InOrder; -import org.mockito.Mockito; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConstructorArgumentValues; @@ -206,7 +205,7 @@ public class EmbeddedWebApplicationContextTests { OrderedFilter filter = new OrderedFilter(); this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setFilter(Mockito.mock(Filter.class)); + registration.setFilter(mock(Filter.class)); registration.setOrder(100); this.context.registerBeanDefinition("filterRegistrationBean", beanDefinition(registration)); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBeanTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBeanTests.java index 8294428baa..359d6bf7ed 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBeanTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBeanTests.java @@ -26,7 +26,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import static org.mockito.Matchers.any; @@ -43,8 +42,8 @@ public class ServletListenerRegistrationBeanTests { @Rule public ExpectedException thrown = ExpectedException.none(); - private final ServletContextListener listener = Mockito - .mock(ServletContextListener.class); + @Mock + private ServletContextListener listener; @Mock private ServletContext servletContext;