mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
d1ce83e3c3
commit
2e7aa4685b
@ -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
|
||||
|
@ -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<Health> response = (ResponseEntity<Health>) 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();
|
||||
|
@ -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() {
|
||||
|
@ -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"));
|
||||
|
@ -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 }");
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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<Object> response = new NamedList<Object>();
|
||||
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();
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
@ -145,6 +145,7 @@ public class RepositoryRestMvcAutoConfigurationTests {
|
||||
objectMapperBuilder.simpleDateFormat("yyyy-MM");
|
||||
return objectMapperBuilder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,4 +69,5 @@ public class SpringDataWebAutoConfigurationTests {
|
||||
.getBeansOfType(PageableHandlerMethodArgumentResolver.class);
|
||||
assertThat(beans.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -55,11 +55,9 @@ class GroovyGrabDependencyResolver implements DependencyResolver {
|
||||
groovyCompiler.compile(createSources(artifactIdentifiers));
|
||||
List<URL> artifactUrls = getClassPathUrls(groovyCompiler);
|
||||
artifactUrls.removeAll(initialUrls);
|
||||
|
||||
for (URL artifactUrl : artifactUrls) {
|
||||
artifactFiles.add(toFile(artifactUrl));
|
||||
}
|
||||
|
||||
}
|
||||
return artifactFiles;
|
||||
}
|
||||
|
@ -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<String> args = (List<String>) 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;
|
||||
}
|
||||
|
||||
|
@ -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> 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<String> artifactIdentifiers) throws Exception {
|
||||
File libDirectory = getDefaultLibDirectory();
|
||||
libDirectory.mkdirs();
|
||||
|
||||
Log.info("Installing into: " + libDirectory);
|
||||
|
||||
List<File> 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<String> artifactIdentifiers) throws Exception {
|
||||
File libDirectory = getDefaultLibDirectory();
|
||||
|
||||
Log.info("Uninstalling from: " + libDirectory);
|
||||
|
||||
List<File> 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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,34 +56,28 @@ public class UninstallCommand extends OptionParsingCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ExitStatus run(OptionSet options) throws Exception {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> args = (List<String>) 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ public class GroovyGrabDependencyResolverTests {
|
||||
public String[] getClasspath() {
|
||||
return new String[] { "." };
|
||||
}
|
||||
|
||||
};
|
||||
this.resolver = new GroovyGrabDependencyResolver(configuration);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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`
|
||||
|
@ -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("");
|
||||
|
@ -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<Void>() {
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user