Source format and clean-up

pull/123/head
Phillip Webb 11 years ago
parent 883fd9162f
commit 64f32893bb

@ -28,11 +28,11 @@ import org.springframework.boot.actuate.web.BasicErrorController;
import org.springframework.boot.actuate.web.ErrorController; import org.springframework.boot.actuate.web.ErrorController;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration; import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
@ -103,7 +103,8 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
context.getClassLoader())) { context.getClassLoader())) {
if (DefaultTemplateResolverConfiguration.templateExists( if (DefaultTemplateResolverConfiguration.templateExists(
context.getEnvironment(), context.getResourceLoader(), "error")) { context.getEnvironment(), context.getResourceLoader(), "error")) {
return ConditionOutcome.noMatch("Thymeleaf template found for error view"); return ConditionOutcome
.noMatch("Thymeleaf template found for error view");
} }
} }
// FIXME: add matcher for JSP view if Jasper detected // FIXME: add matcher for JSP view if Jasper detected
@ -128,6 +129,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
this.context.addPropertyAccessor(new MapAccessor()); this.context.addPropertyAccessor(new MapAccessor());
this.helper = new PropertyPlaceholderHelper("${", "}"); this.helper = new PropertyPlaceholderHelper("${", "}");
this.resolver = new PlaceholderResolver() { this.resolver = new PlaceholderResolver() {
@Override
public String resolvePlaceholder(String name) { public String resolvePlaceholder(String name) {
Expression expression = SpelView.this.parser.parseExpression(name); Expression expression = SpelView.this.parser.parseExpression(name);
Object value = expression.getValue(SpelView.this.context); Object value = expression.getValue(SpelView.this.context);
@ -136,10 +138,12 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
}; };
} }
@Override
public String getContentType() { public String getContentType() {
return "text/html"; return "text/html";
} }
@Override
public void render(Map<String, ?> model, HttpServletRequest request, public void render(Map<String, ?> model, HttpServletRequest request,
HttpServletResponse response) throws Exception { HttpServletResponse response) throws Exception {
if (response.getContentType() == null) { if (response.getContentType() == null) {

@ -72,6 +72,7 @@ public class SimpleHealthIndicator implements HealthIndicator<Map<String, Object
return map; return map;
} }
@Override
public void setEnvironment(Environment environment) { public void setEnvironment(Environment environment) {
this.environment = environment; this.environment = environment;
} }

@ -69,7 +69,8 @@ class OnWebApplicationCondition extends SpringBootCondition {
} }
if (context.getEnvironment() instanceof StandardServletEnvironment) { if (context.getEnvironment() instanceof StandardServletEnvironment) {
return ConditionOutcome.match("found web application StandardServletEnvironment"); return ConditionOutcome
.match("found web application StandardServletEnvironment");
} }
return ConditionOutcome.noMatch("not a web application"); return ConditionOutcome.noMatch("not a web application");

@ -281,7 +281,8 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) { AnnotatedTypeMetadata metadata) {
if (anyMatches(context, metadata, this.tomcatCondition, this.dbcpCondition)) { if (anyMatches(context, metadata, this.tomcatCondition, this.dbcpCondition)) {
return ConditionOutcome.noMatch("existing non-embedded database detected"); return ConditionOutcome
.noMatch("existing non-embedded database detected");
} }
EmbeddedDatabaseType type = EmbeddedDatabaseConnection.get( EmbeddedDatabaseType type = EmbeddedDatabaseConnection.get(
context.getClassLoader()).getType(); context.getClassLoader()).getType();
@ -311,7 +312,8 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors( if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
context.getBeanFactory(), DataSource.class, true, false).length > 0) { context.getBeanFactory(), DataSource.class, true, false).length > 0) {
return ConditionOutcome.match("Existing bean configured database detected"); return ConditionOutcome
.match("Existing bean configured database detected");
} }
return ConditionOutcome.noMatch("no existing bean configured database"); return ConditionOutcome.noMatch("no existing bean configured database");

@ -48,7 +48,7 @@ import static org.mockito.Mockito.mock;
/** /**
* Tests for {@link AutoConfigurationReportLoggingInitializer}. * Tests for {@link AutoConfigurationReportLoggingInitializer}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class AutoConfigurationReportLoggingInitializerTests { public class AutoConfigurationReportLoggingInitializerTests {

@ -34,7 +34,7 @@ import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link JpaRepositoriesAutoConfiguration}. * Tests for {@link JpaRepositoriesAutoConfiguration}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class JpaRepositoriesAutoConfigurationTests { public class JpaRepositoriesAutoConfigurationTests {
@ -46,7 +46,8 @@ public class JpaRepositoriesAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, this.context.register(TestConfiguration.class,
ComponentScanDetectorConfiguration.class, ComponentScanDetectorConfiguration.class,
EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
JpaRepositoriesAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();

@ -55,7 +55,10 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory); assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals(((ActiveMQConnectionFactory)jmsTemplate.getConnectionFactory()).getBrokerURL(), "vm://localhost"); assertEquals(
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL(),
"vm://localhost");
} }
@Test @Test
@ -109,7 +112,7 @@ public class JmsTemplateAutoConfigurationTests {
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
assertFalse(jmsTemplate.isPubSubDomain()); assertFalse(jmsTemplate.isPubSubDomain());
} }
@Test @Test
public void testJmsTemplateOverridden() { public void testJmsTemplateOverridden() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
@ -139,7 +142,9 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory); assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals(((ActiveMQConnectionFactory)jmsTemplate.getConnectionFactory()).getBrokerURL(), assertEquals(
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL(),
"tcp://localhost:61616"); "tcp://localhost:61616");
} }
@ -157,7 +162,9 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory); assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals(((ActiveMQConnectionFactory)jmsTemplate.getConnectionFactory()).getBrokerURL(), assertEquals(
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL(),
"tcp://remote-host:10000"); "tcp://remote-host:10000");
} }
@ -174,7 +181,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(pool); assertNotNull(pool);
assertEquals(jmsTemplate.getConnectionFactory(), pool); assertEquals(jmsTemplate.getConnectionFactory(), pool);
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory(); ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
.getConnectionFactory();
assertEquals("vm://localhost", factory.getBrokerURL()); assertEquals("vm://localhost", factory.getBrokerURL());
} }
@ -192,7 +200,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(pool); assertNotNull(pool);
assertEquals(jmsTemplate.getConnectionFactory(), pool); assertEquals(jmsTemplate.getConnectionFactory(), pool);
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory(); ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
.getConnectionFactory();
assertEquals("tcp://localhost:61616", factory.getBrokerURL()); assertEquals("tcp://localhost:61616", factory.getBrokerURL());
} }
@ -202,7 +211,8 @@ public class JmsTemplateAutoConfigurationTests {
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
TestUtils.addEnviroment(this.context, "spring.activemq.pooled:true", TestUtils.addEnviroment(this.context, "spring.activemq.pooled:true",
"spring.activemq.inMemory:false", "spring.activemq.brokerURL:tcp://remote-host:10000"); "spring.activemq.inMemory:false",
"spring.activemq.brokerURL:tcp://remote-host:10000");
this.context.refresh(); this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
PooledConnectionFactory pool = this.context PooledConnectionFactory pool = this.context
@ -210,7 +220,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(pool); assertNotNull(pool);
assertEquals(jmsTemplate.getConnectionFactory(), pool); assertEquals(jmsTemplate.getConnectionFactory(), pool);
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory(); ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
.getConnectionFactory();
assertEquals("tcp://remote-host:10000", factory.getBrokerURL()); assertEquals("tcp://remote-host:10000", factory.getBrokerURL());
} }

@ -39,7 +39,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
/** /**
* Tests for {@link DeviceResolverAutoConfiguration}. * Tests for {@link DeviceResolverAutoConfiguration}.
* *
* @author Roy Clarkson * @author Roy Clarkson
*/ */
public class DeviceResolverAutoConfigurationTests { public class DeviceResolverAutoConfigurationTests {

@ -133,6 +133,7 @@ public class OptionHandler {
@Override @Override
public String format(Map<String, ? extends OptionDescriptor> options) { public String format(Map<String, ? extends OptionDescriptor> options) {
Comparator<OptionDescriptor> comparator = new Comparator<OptionDescriptor>() { Comparator<OptionDescriptor> comparator = new Comparator<OptionDescriptor>() {
@Override
public int compare(OptionDescriptor first, OptionDescriptor second) { public int compare(OptionDescriptor first, OptionDescriptor second) {
return first.options().iterator().next() return first.options().iterator().next()
.compareTo(second.options().iterator().next()); .compareTo(second.options().iterator().next());

@ -58,8 +58,8 @@ public class SampleActuatorUiApplicationPortTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(
.run(SampleActuatorUiApplication.class, args); SampleActuatorUiApplication.class, args);
} }
}); });
context = future.get(60, TimeUnit.SECONDS); context = future.get(60, TimeUnit.SECONDS);

@ -58,7 +58,7 @@ public class SampleActuatorUiApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleActuatorUiApplication.class); .run(SampleActuatorUiApplication.class);
} }
}); });
@ -112,8 +112,10 @@ public class SampleActuatorUiApplicationTests {
.contains("<html>")); .contains("<html>"));
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody() assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody()
.contains("<body>")); .contains("<body>"));
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody() assertTrue(
.contains("Please contact the operator with the above information")); "Wrong body:\n" + entity.getBody(),
entity.getBody().contains(
"Please contact the operator with the above information"));
} }
private RestTemplate getRestTemplate() { private RestTemplate getRestTemplate() {

@ -59,8 +59,7 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(configuration, args);
.run(configuration, args);
} }
}); });
this.context = future.get(60, TimeUnit.SECONDS); this.context = future.get(60, TimeUnit.SECONDS);

@ -67,8 +67,8 @@ public class ManagementAddressSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(
.run(SampleActuatorApplication.class, args); SampleActuatorApplication.class, args);
} }
}); });
context = future.get(60, TimeUnit.SECONDS); context = future.get(60, TimeUnit.SECONDS);

@ -57,8 +57,8 @@ public class ManagementSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(
.run(SampleActuatorApplication.class, args); SampleActuatorApplication.class, args);
} }
}); });
context = future.get(60, TimeUnit.SECONDS); context = future.get(60, TimeUnit.SECONDS);

@ -65,8 +65,8 @@ public class NoManagementSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(
.run(SampleActuatorApplication.class, args); SampleActuatorApplication.class, args);
} }
}); });
context = future.get(60, TimeUnit.SECONDS); context = future.get(60, TimeUnit.SECONDS);

@ -69,7 +69,7 @@ public class SampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleActuatorApplication.class); .run(SampleActuatorApplication.class);
} }
}); });
@ -145,8 +145,7 @@ public class SampleActuatorApplicationTests {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
String body = entity.getBody(); String body = entity.getBody();
assertNotNull(body); assertNotNull(body);
assertTrue("Wrong body: " + body, assertTrue("Wrong body: " + body, body.contains("\"error\":"));
body.contains("\"error\":"));
} }
@Test @Test
@ -171,7 +170,7 @@ public class SampleActuatorApplicationTests {
.getForEntity("http://localhost:8080/trace", List.class); .getForEntity("http://localhost:8080/trace", List.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Map<String, Object>> list = (List<Map<String, Object>>) entity.getBody(); List<Map<String, Object>> list = entity.getBody();
Map<String, Object> trace = list.get(list.size() - 1); Map<String, Object> trace = list.get(list.size() - 1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace

@ -62,7 +62,7 @@ public class ShutdownSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleActuatorApplication.class); .run(SampleActuatorApplication.class);
} }
}); });

@ -41,7 +41,7 @@ import org.springframework.web.client.RestTemplate;
/** /**
* Integration tests for unsecured service endpoints (even with Spring Security on * Integration tests for unsecured service endpoints (even with Spring Security on
* classpath). * classpath).
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class UnsecureManagementSampleActuatorApplicationTests { public class UnsecureManagementSampleActuatorApplicationTests {
@ -55,9 +55,9 @@ public class UnsecureManagementSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(
.run(SampleActuatorApplication.class, SampleActuatorApplication.class,
"--security.management.enabled=false"); "--security.management.enabled=false");
} }
}); });
context = future.get(60, TimeUnit.SECONDS); context = future.get(60, TimeUnit.SECONDS);
@ -87,7 +87,8 @@ public class UnsecureManagementSampleActuatorApplicationTests {
public void testMetrics() throws Exception { public void testMetrics() throws Exception {
try { try {
testHomeIsSecure(); // makes sure some requests have been made testHomeIsSecure(); // makes sure some requests have been made
} catch (AssertionError ex) { }
catch (AssertionError ex) {
// ignore; // ignore;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")

@ -54,9 +54,9 @@ public class UnsecureSampleActuatorApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication.run(
.run(SampleActuatorApplication.class, SampleActuatorApplication.class,
"--security.basic.enabled=false"); "--security.basic.enabled=false");
} }
}); });
context = future.get(60, TimeUnit.SECONDS); context = future.get(60, TimeUnit.SECONDS);

@ -31,7 +31,7 @@ public class SampleController {
@RequestMapping("/") @RequestMapping("/")
@ResponseBody @ResponseBody
@Transactional(readOnly = true) @Transactional(readOnly = true)
public String helloWorld() { public String helloWorld() {
return this.cityService.getCity("Bath", "UK").getName(); return this.cityService.getCity("Bath", "UK").getName();
} }

@ -23,9 +23,10 @@ import org.springframework.web.context.WebApplicationContext;
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SampleDataJpaApplication.class, loader=SpringApplicationContextLoader.class) @ContextConfiguration(classes = SampleDataJpaApplication.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration @WebAppConfiguration
@ActiveProfiles("scratch") // Separate profile for web tests to avoid clashing databases @ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
public class SampleDataJpaApplicationTests { public class SampleDataJpaApplicationTests {
@Autowired @Autowired

@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SampleDataJpaApplication.class, loader=SpringApplicationContextLoader.class) @ContextConfiguration(classes = SampleDataJpaApplication.class, loader = SpringApplicationContextLoader.class)
public class CityRepositoryIntegrationTests { public class CityRepositoryIntegrationTests {
@Autowired @Autowired

@ -44,7 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SampleDataJpaApplication.class, loader=SpringApplicationContextLoader.class) @ContextConfiguration(classes = SampleDataJpaApplication.class, loader = SpringApplicationContextLoader.class)
public class HotelRepositoryIntegrationTests { public class HotelRepositoryIntegrationTests {
@Autowired @Autowired

@ -20,25 +20,24 @@ import org.springframework.data.annotation.Id;
public class Customer { public class Customer {
@Id @Id
private String id; private String id;
private String firstName; private String firstName;
private String lastName; private String lastName;
public Customer() {} public Customer() {
}
public Customer(String firstName, String lastName) { public Customer(String firstName, String lastName) {
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
} }
@Override @Override
public String toString() { public String toString() {
return String.format( return String.format("Customer[id=%s, firstName='%s', lastName='%s']", id,
"Customer[id=%s, firstName='%s', lastName='%s']", firstName, lastName);
id, firstName, lastName); }
}
} }

@ -22,8 +22,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
public interface CustomerRepository extends MongoRepository<Customer, String> { public interface CustomerRepository extends MongoRepository<Customer, String> {
public Customer findByFirstName(String firstName); public Customer findByFirstName(String firstName);
public List<Customer> findByLastName(String lastName); public List<Customer> findByLastName(String lastName);
} }

@ -27,7 +27,7 @@ import org.springframework.core.NestedCheckedException;
/** /**
* Tests for {@link SampleMongoApplication}. * Tests for {@link SampleMongoApplication}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class SampleMongoApplicationTests { public class SampleMongoApplicationTests {
@ -39,13 +39,15 @@ public class SampleMongoApplicationTests {
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
try { try {
SampleMongoApplication.main(new String[0]); SampleMongoApplication.main(new String[0]);
} catch (IllegalStateException ex) { }
catch (IllegalStateException ex) {
if (serverNotRunning(ex)) { if (serverNotRunning(ex)) {
return; return;
} }
} }
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("firstName='Alice', lastName='Smith'")); assertTrue("Wrong output: " + output,
output.contains("firstName='Alice', lastName='Smith'"));
} }
private boolean serverNotRunning(IllegalStateException e) { private boolean serverNotRunning(IllegalStateException e) {

@ -46,8 +46,7 @@ public class SampleIntegrationApplicationTests {
@BeforeClass @BeforeClass
public static void start() throws Exception { public static void start() throws Exception {
context = (ConfigurableApplicationContext) SpringApplication context = SpringApplication.run(SampleIntegrationApplication.class);
.run(SampleIntegrationApplication.class);
} }
@AfterClass @AfterClass

@ -51,7 +51,7 @@ public class SampleJettyApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleJettyApplication.class); .run(SampleJettyApplication.class);
} }
}); });

@ -28,7 +28,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SampleSimpleApplication.class, loader=SpringApplicationContextLoader.class) @ContextConfiguration(classes = SampleSimpleApplication.class, loader = SpringApplicationContextLoader.class)
public class SpringTestSampleSimpleApplicationTests { public class SpringTestSampleSimpleApplicationTests {
@Test @Test

@ -73,7 +73,7 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(NonAutoConfigurationSampleTomcatApplication.class); .run(NonAutoConfigurationSampleTomcatApplication.class);
} }
}); });

@ -51,7 +51,7 @@ public class SampleTomcatApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleTomcatApplication.class); .run(SampleTomcatApplication.class);
} }
}); });

@ -52,7 +52,7 @@ public class SampleTraditionalApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleTraditionalApplication.class); .run(SampleTraditionalApplication.class);
} }
}); });

@ -21,7 +21,7 @@ import static org.junit.Assert.*;
/** /**
* Basic integration tests for JSP application. * Basic integration tests for JSP application.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class SampleWebJspApplicationTests { public class SampleWebJspApplicationTests {
@ -35,7 +35,7 @@ public class SampleWebJspApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleWebJspApplication.class); .run(SampleWebJspApplication.class);
} }
}); });
@ -54,8 +54,8 @@ public class SampleWebJspApplicationTests {
ResponseEntity<String> entity = getRestTemplate().getForEntity( ResponseEntity<String> entity = getRestTemplate().getForEntity(
"http://localhost:8080", String.class); "http://localhost:8080", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue("Wrong body:\n" + entity.getBody(), entity assertTrue("Wrong body:\n" + entity.getBody(),
.getBody().contains("/resources/text.txt")); entity.getBody().contains("/resources/text.txt"));
} }
private RestTemplate getRestTemplate() { private RestTemplate getRestTemplate() {

@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class SampleWebStaticApplicationTests { public class SampleWebStaticApplicationTests {
@ -37,7 +37,7 @@ public class SampleWebStaticApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleWebStaticApplication.class); .run(SampleWebStaticApplication.class);
} }
}); });

@ -26,7 +26,7 @@ import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class SampleWebUiApplicationTests { public class SampleWebUiApplicationTests {
@ -40,7 +40,7 @@ public class SampleWebUiApplicationTests {
new Callable<ConfigurableApplicationContext>() { new Callable<ConfigurableApplicationContext>() {
@Override @Override
public ConfigurableApplicationContext call() throws Exception { public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication return SpringApplication
.run(SampleWebUiApplication.class); .run(SampleWebUiApplication.class);
} }
}); });

@ -37,8 +37,8 @@ public class SampleWebSocketsApplication extends SpringBootServletInitializer {
@Override @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SampleWebSocketsApplication.class); return application.sources(SampleWebSocketsApplication.class);
} }
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(SampleWebSocketsApplication.class, args); SpringApplication.run(SampleWebSocketsApplication.class, args);

@ -26,7 +26,7 @@ import org.springframework.boot.gradle.task.RunJar;
/** /**
* Gradle 'Spring Boot' {@link Plugin}. * Gradle 'Spring Boot' {@link Plugin}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class SpringBootPlugin implements Plugin<Project> { public class SpringBootPlugin implements Plugin<Project> {
@ -53,12 +53,14 @@ public class SpringBootPlugin implements Plugin<Project> {
} }
private Repackage addRepackageTask(Project project) { private Repackage addRepackageTask(Project project) {
Repackage packageTask = project.getTasks().create(REPACKAGE_TASK_NAME, Repackage.class); Repackage packageTask = project.getTasks().create(REPACKAGE_TASK_NAME,
Repackage.class);
packageTask.setDescription("Repackage existing JAR and WAR " packageTask.setDescription("Repackage existing JAR and WAR "
+ "archives so that they can be executed from the command " + "line using 'java -jar'"); + "archives so that they can be executed from the command "
+ "line using 'java -jar'");
packageTask.setGroup(BasePlugin.BUILD_GROUP); packageTask.setGroup(BasePlugin.BUILD_GROUP);
packageTask.dependsOn(project.getConfigurations().getByName(Dependency.ARCHIVES_CONFIGURATION) packageTask.dependsOn(project.getConfigurations().getByName(
.getAllArtifacts().getBuildDependencies()); Dependency.ARCHIVES_CONFIGURATION).getAllArtifacts().getBuildDependencies());
return packageTask; return packageTask;
} }

@ -1,3 +1,4 @@
package org.springframework.boot.gradle.task; package org.springframework.boot.gradle.task;
import java.io.File; import java.io.File;
@ -23,6 +24,7 @@ class ProjectLibraries implements Libraries {
/** /**
* Create a new {@link ProjectLibraries} instance of the specified {@link Project}. * Create a new {@link ProjectLibraries} instance of the specified {@link Project}.
*
* @param project the gradle project * @param project the gradle project
*/ */
public ProjectLibraries(Project project) { public ProjectLibraries(Project project) {
@ -31,6 +33,7 @@ class ProjectLibraries implements Libraries {
/** /**
* Set the name of the provided configuration. Defaults to 'providedRuntime'. * Set the name of the provided configuration. Defaults to 'providedRuntime'.
*
* @param providedConfigurationName the providedConfigurationName to set * @param providedConfigurationName the providedConfigurationName to set
*/ */
public void setProvidedConfigurationName(String providedConfigurationName) { public void setProvidedConfigurationName(String providedConfigurationName) {

@ -29,7 +29,7 @@ import org.springframework.boot.loader.tools.Repackager;
/** /**
* Repackage task. * Repackage task.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class Repackage extends DefaultTask { public class Repackage extends DefaultTask {
@ -44,6 +44,7 @@ public class Repackage extends DefaultTask {
libraries.setProvidedConfigurationName(extension.getProvidedConfiguration()); libraries.setProvidedConfigurationName(extension.getProvidedConfiguration());
} }
project.getTasks().withType(Jar.class, new Action<Jar>() { project.getTasks().withType(Jar.class, new Action<Jar>() {
@Override @Override
public void execute(Jar archive) { public void execute(Jar archive) {
if ("".equals(archive.getClassifier())) { if ("".equals(archive.getClassifier())) {

@ -29,7 +29,7 @@ import org.gradle.process.internal.ExecAction;
/** /**
* Run Jar task. Run the built jar file from Gradle. * Run Jar task. Run the built jar file from Gradle.
* *
* @author Dave Noel * @author Dave Noel
*/ */
public class RunJar extends DefaultTask { public class RunJar extends DefaultTask {
@ -40,6 +40,7 @@ public class RunJar extends DefaultTask {
public void runJar() { public void runJar() {
Project project = getProject(); Project project = getProject();
project.getTasks().withType(Jar.class, new Action<Jar>() { project.getTasks().withType(Jar.class, new Action<Jar>() {
@Override @Override
public void execute(Jar archive) { public void execute(Jar archive) {
file = archive.getArchivePath(); file = archive.getArchivePath();

@ -200,6 +200,7 @@ class JarWriter {
this.close = close; this.close = close;
} }
@Override
public void write(OutputStream outputStream) throws IOException { public void write(OutputStream outputStream) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = -1; int bytesRead = -1;

@ -157,6 +157,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
private void definePackageForFindClass(final String name, final String packageName) { private void definePackageForFindClass(final String name, final String packageName) {
try { try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws ClassNotFoundException { public Object run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class"); String path = name.replace('.', '/').concat(".class");
for (URL url : getURLs()) { for (URL url : getURLs()) {

@ -142,6 +142,7 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
/** /**
* Returns the port that the embedded servlet container should listen on. * Returns the port that the embedded servlet container should listen on.
*/ */
@Override
public int getPort() { public int getPort() {
return this.port; return this.port;
} }
@ -158,10 +159,12 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
return this.address; return this.address;
} }
@Override
public void setSessionTimeout(int sessionTimeout) { public void setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout; this.sessionTimeout = sessionTimeout;
} }
@Override
public void setSessionTimeout(int sessionTimeout, TimeUnit timeUnit) { public void setSessionTimeout(int sessionTimeout, TimeUnit timeUnit) {
Assert.notNull(timeUnit, "TimeUnit must not be null"); Assert.notNull(timeUnit, "TimeUnit must not be null");
this.sessionTimeout = (int) timeUnit.toSeconds(sessionTimeout); this.sessionTimeout = (int) timeUnit.toSeconds(sessionTimeout);

@ -35,6 +35,7 @@ public interface EmbeddedServletContainer {
*/ */
public static final EmbeddedServletContainer NONE = new EmbeddedServletContainer() { public static final EmbeddedServletContainer NONE = new EmbeddedServletContainer() {
@Override
public void start() throws EmbeddedServletContainerException { public void start() throws EmbeddedServletContainerException {
// Do nothing // Do nothing
}; };

@ -21,8 +21,7 @@ public class LiquibaseServiceLocatorInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext>, ApplicationContextInitializer<ConfigurableApplicationContext>,
SpringApplicationInitializer { SpringApplicationInitializer {
static final Log logger = LogFactory static final Log logger = LogFactory.getLog(LiquibaseServiceLocatorInitializer.class);
.getLog(LiquibaseServiceLocatorInitializer.class);
@Override @Override
public void initialize(SpringApplication springApplication, String[] args) { public void initialize(SpringApplication springApplication, String[] args) {
@ -39,12 +38,12 @@ public class LiquibaseServiceLocatorInitializer implements
* Inner class to prevent class not found issues * Inner class to prevent class not found issues
*/ */
private static class LiquibasePresent { private static class LiquibasePresent {
public void replaceServiceLocator() { public void replaceServiceLocator() {
ServiceLocator.setInstance(new CustomResolverServiceLocator( ServiceLocator.setInstance(new CustomResolverServiceLocator(
new SpringPackageScanClassResolver())); new SpringPackageScanClassResolver()));
} }
} }
} }

@ -16,7 +16,6 @@
package org.springframework.boot.config; package org.springframework.boot.config;
/** /**
* Tests for {@link JsonParser}. * Tests for {@link JsonParser}.
* *

Loading…
Cancel
Save