From 9d28238598b31c8e76a93a0cd4b8f7815b317d3b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Sat, 8 Jun 2019 08:16:27 +0100 Subject: [PATCH] Update formatting of spring-boot-samples --- .../customsecurity/SecurityConfiguration.java | 9 ++- .../CorsSampleActuatorApplicationTests.java | 24 +++----- ...AndPathSampleActuatorApplicationTests.java | 16 ++---- ...ctuatorCustomSecurityApplicationTests.java | 44 ++++++--------- .../SampleActuatorLog4J2ApplicationTests.java | 14 ++--- .../SampleActuatorUiApplicationPortTests.java | 18 +++--- .../ui/SampleActuatorUiApplicationTests.java | 18 +++--- .../sample/actuator/SampleController.java | 5 +- ...pertiesSampleActuatorApplicationTests.java | 9 ++- ...gementAddressActuatorApplicationTests.java | 13 ++--- ...entPathSampleActuatorApplicationTests.java | 3 +- ...AndPathSampleActuatorApplicationTests.java | 29 ++++------ ...entPortSampleActuatorApplicationTests.java | 20 +++---- ...agementSampleActuatorApplicationTests.java | 11 ++-- .../SampleActuatorApplicationTests.java | 55 +++++++------------ ...letPathSampleActuatorApplicationTests.java | 12 ++-- ...hutdownSampleActuatorApplicationTests.java | 13 ++--- .../sample/ant/SampleAntApplicationIT.java | 8 +-- .../java/sample/atmosphere/ChatService.java | 6 +- .../SampleAtmosphereApplication.java | 10 ++-- .../SampleAtmosphereApplicationTests.java | 31 ++++------- .../sample/batch/SampleBatchApplication.java | 8 +-- .../batch/SampleBatchApplicationTests.java | 5 +- .../java/sample/cache/CacheManagerCheck.java | 6 +- .../sample/cache/SampleCacheApplication.java | 5 +- .../main/java/sample/cache/SampleClient.java | 40 ++++++-------- .../java/sample/data/cassandra/Customer.java | 5 +- ...OrderedCassandraTestExecutionListener.java | 8 +-- .../main/java/sample/data/couchbase/User.java | 6 +- .../SampleCouchbaseApplicationTests.java | 5 +- .../sample/data/elasticsearch/Customer.java | 6 +- .../java/sample/data/jpa/domain/City.java | 3 +- .../java/sample/data/jpa/domain/Hotel.java | 3 +- .../java/sample/data/jpa/domain/Review.java | 3 +- .../data/jpa/service/CityRepository.java | 5 +- .../data/jpa/service/CityServiceImpl.java | 7 +-- .../jpa/SampleDataJpaApplicationTests.java | 9 +-- .../HotelRepositoryIntegrationTests.java | 11 ++-- .../main/java/sample/data/mongo/Customer.java | 5 +- .../main/java/sample/data/neo4j/Customer.java | 5 +- .../java/sample/data/rest/domain/City.java | 3 +- .../java/sample/data/rest/domain/Hotel.java | 3 +- .../data/rest/service/CityRepository.java | 10 ++-- .../rest/SampleDataRestApplicationTests.java | 18 +++--- .../CityRepositoryIntegrationTests.java | 8 +-- .../main/java/sample/data/solr/Product.java | 4 +- .../java/sample/devtools/MyController.java | 3 +- ...leDevToolsApplicationIntegrationTests.java | 9 +-- .../src/main/java/sample/flyway/Person.java | 6 +- .../flyway/SampleFlywayApplicationTests.java | 3 +- .../SampleHateoasApplicationTests.java | 10 ++-- .../SampleIntegrationApplication.java | 11 ++-- .../SampleIntegrationApplicationTests.java | 40 ++++++-------- .../producer/ProducerApplication.java | 5 +- .../jersey/SampleJerseyApplication.java | 6 +- .../jersey/SampleJerseyApplicationTests.java | 14 ++--- .../jersey1/SampleJersey1Application.java | 8 +-- .../SampleJersey1ApplicationTests.java | 5 +- .../jetty/SampleJettyApplicationTests.java | 11 ++-- .../main/java/sample/jooq/JooqExamples.java | 19 +++---- .../jooq/SampleJooqApplicationTests.java | 5 +- .../src/main/java/sample/jpa/domain/Note.java | 3 +- .../src/main/java/sample/jpa/domain/Tag.java | 3 +- .../jpa/repository/JpaNoteRepository.java | 3 +- .../jpa/repository/JpaTagRepository.java | 3 +- .../sample/jpa/SampleJpaApplicationTests.java | 3 +- .../atomikos/SampleAtomikosApplication.java | 3 +- .../SampleAtomikosApplicationTests.java | 3 +- .../bitronix/SampleBitronixApplication.java | 5 +- .../SampleBitronixApplicationTests.java | 11 ++-- .../narayana/SampleNarayanaApplication.java | 5 +- .../SampleNarayanaApplicationTests.java | 5 +- .../main/java/sample/kafka/SampleMessage.java | 5 +- .../kafka/SampleKafkaApplicationTests.java | 6 +- .../SampleLiquibaseApplicationTests.java | 14 ++--- .../logback/SampleLogbackApplication.java | 5 +- .../SampleLogbackApplicationTests.java | 5 +- .../SampleOAuth2ClientApplicationTests.java | 10 ++-- .../SampleParentContextApplication.java | 14 ++--- ...mpleIntegrationParentApplicationTests.java | 11 ++-- .../parent/producer/ProducerApplication.java | 5 +- .../SampleProfileApplicationTests.java | 5 +- .../SamplePropertiesValidator.java | 5 +- ...plePropertyValidationApplicationTests.java | 11 ++-- .../main/java/sample/quartz/SampleJob.java | 5 +- .../quartz/SampleQuartzApplication.java | 14 ++--- .../quartz/SampleQuartzApplicationTests.java | 8 +-- .../SampleSecureWebFluxApplicationTests.java | 16 +++--- ...ampleSecureWebFluxCustomSecurityTests.java | 52 +++++++----------- .../secure/SampleSecureApplication.java | 7 +-- .../servlet/SampleServletApplication.java | 5 +- .../SampleServletApplicationTests.java | 8 +-- .../SampleSessionWebFluxApplicationTests.java | 19 +++---- .../SampleSessionApplicationTests.java | 11 ++-- .../service/RemoteVehicleDetailsService.java | 12 ++-- .../sample/test/service/VehicleDetails.java | 3 +- ...IdentificationNumberNotFoundException.java | 3 +- .../sample/test/web/UserVehicleService.java | 6 +- ...pleTestApplicationWebIntegrationTests.java | 6 +- .../sample/test/domain/UserEntityTests.java | 5 +- .../test/domain/UserRepositoryTests.java | 5 +- .../VehicleIdentificationNumberTests.java | 5 +- .../RemoteVehicleDetailsServiceTests.java | 14 ++--- .../test/service/VehicleDetailsJsonTests.java | 8 +-- ...UserVehicleControllerApplicationTests.java | 12 ++-- .../UserVehicleControllerHtmlUnitTests.java | 5 +- .../UserVehicleControllerSeleniumTests.java | 5 +- .../test/web/UserVehicleControllerTests.java | 27 ++++----- .../test/web/UserVehicleServiceTests.java | 11 ++-- ...leTomcatTwoConnectorsApplicationTests.java | 13 ++--- ...igurationSampleTomcatApplicationTests.java | 8 +-- .../tomcat/SampleTomcatApplicationTests.java | 17 ++---- .../sample/traditional/config/WebConfig.java | 5 +- .../SampleTraditionalApplicationTests.java | 5 +- .../SampleUndertowApplicationTests.java | 14 ++--- .../SampleWebFreeMarkerApplicationTests.java | 12 ++-- .../mvc/MessageController.java | 5 +- .../MessageControllerWebTests.java | 11 ++-- .../SampleGroovyTemplateApplicationTests.java | 5 +- .../jsp/SampleWebJspApplicationTests.java | 8 +-- .../SampleMethodSecurityApplication.java | 5 +- .../SampleMethodSecurityApplicationTests.java | 39 ++++++------- .../SampleWebMustacheApplicationTests.java | 21 ++++--- .../SampleWebSecureCustomApplication.java | 7 +-- ...SampleWebSecureCustomApplicationTests.java | 26 ++++----- .../jdbc/SampleWebSecureJdbcApplication.java | 7 +-- .../SampleWebSecureJdbcApplicationTests.java | 26 ++++----- .../secure/SampleSecureApplicationTests.java | 26 ++++----- .../SampleWebStaticApplicationTests.java | 9 ++- .../sample/web/ui/mvc/MessageController.java | 5 +- .../web/ui/MessageControllerWebTests.java | 11 ++-- .../web/ui/SampleWebUiApplicationTests.java | 6 +- .../sample/webflux/ExampleController.java | 6 +- .../SampleWebFluxApplicationTests.java | 18 +++--- .../webservices/endpoint/HolidayEndpoint.java | 23 +++----- .../service/StubHumanResourceService.java | 5 +- .../webservices/SampleWsApplicationTests.java | 13 ++--- .../SampleJettyWebSocketsApplication.java | 5 +- .../client/SimpleClientWebSocketHandler.java | 9 ++- .../jetty/echo/EchoWebSocketHandler.java | 8 +-- .../reverse/ReverseWebSocketEndpoint.java | 5 +- .../samples/websocket/jetty/snake/Snake.java | 14 ++--- .../websocket/jetty/snake/SnakeTimer.java | 5 +- .../websocket/jetty/snake/SnakeUtils.java | 5 +- .../jetty/snake/SnakeWebSocketHandler.java | 23 +++----- .../SampleWebSocketsApplicationTests.java | 32 ++++------- ...omContainerWebSocketsApplicationTests.java | 36 +++++------- .../SampleTomcatWebSocketApplication.java | 5 +- .../client/SimpleClientWebSocketHandler.java | 9 ++- .../tomcat/echo/EchoWebSocketHandler.java | 8 +-- .../reverse/ReverseWebSocketEndpoint.java | 5 +- .../samples/websocket/tomcat/snake/Snake.java | 14 ++--- .../websocket/tomcat/snake/SnakeTimer.java | 5 +- .../websocket/tomcat/snake/SnakeUtils.java | 5 +- .../tomcat/snake/SnakeWebSocketHandler.java | 23 +++----- .../SampleWebSocketsApplicationTests.java | 32 ++++------- ...omContainerWebSocketsApplicationTests.java | 36 +++++------- .../SampleUndertowWebSocketsApplication.java | 11 ++-- .../client/SimpleClientWebSocketHandler.java | 9 ++- .../undertow/echo/EchoWebSocketHandler.java | 8 +-- .../reverse/ReverseWebSocketEndpoint.java | 5 +- .../websocket/undertow/snake/Snake.java | 14 ++--- .../websocket/undertow/snake/SnakeTimer.java | 5 +- .../websocket/undertow/snake/SnakeUtils.java | 5 +- .../undertow/snake/SnakeWebSocketHandler.java | 23 +++----- .../SampleWebSocketsApplicationTests.java | 32 ++++------- ...omContainerWebSocketsApplicationTests.java | 36 +++++------- 167 files changed, 745 insertions(+), 1172 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java index 13a8a021f2..039ae03117 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +33,9 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Bean public InMemoryUserDetailsManager inMemoryUserDetailsManager() { return new InMemoryUserDetailsManager( - User.withDefaultPasswordEncoder().username("user").password("password") - .authorities("ROLE_USER").build(), - User.withDefaultPasswordEncoder().username("beans").password("beans") - .authorities("ROLE_BEANS").build(), + User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER") + .build(), + User.withDefaultPasswordEncoder().username("beans").password("beans").authorities("ROLE_BEANS").build(), User.withDefaultPasswordEncoder().username("admin").password("admin") .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java index 08887db79f..e1a1debb49 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,37 +55,31 @@ public class CorsSampleActuatorApplicationTests { @Before public void setUp() { RestTemplateBuilder builder = new RestTemplateBuilder(); - LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler( - this.applicationContext.getEnvironment(), "http"); + LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(), + "http"); builder = builder.uriTemplateHandler(handler); this.testRestTemplate = new TestRestTemplate(builder); } @Test public void endpointShouldReturnUnauthorized() { - ResponseEntity entity = this.testRestTemplate.getForEntity("/actuator/env", - Map.class); + ResponseEntity entity = this.testRestTemplate.getForEntity("/actuator/env", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void preflightRequestToEndpointShouldReturnOk() throws Exception { RequestEntity healthRequest = RequestEntity.options(new URI("/actuator/env")) - .header("Origin", "http://localhost:8080") - .header("Access-Control-Request-Method", "GET").build(); - ResponseEntity exchange = this.testRestTemplate.exchange(healthRequest, - Map.class); + .header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build(); + ResponseEntity exchange = this.testRestTemplate.exchange(healthRequest, Map.class); assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test - public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() - throws Exception { + public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception { RequestEntity entity = RequestEntity.options(new URI("/actuator/env")) - .header("Origin", "http://localhost:9095") - .header("Access-Control-Request-Method", "GET").build(); - ResponseEntity exchange = this.testRestTemplate.exchange(entity, - byte[].class); + .header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build(); + ResponseEntity exchange = this.testRestTemplate.exchange(entity, byte[].class); assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java index 10a2fe46fd..d2956f47a8 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", - "management.server.servlet.context-path=/management" }) + properties = { "management.server.port=0", "management.server.servlet.context-path=/management" }) public class ManagementPortAndPathSampleActuatorApplicationTests { @LocalServerPort @@ -58,17 +57,15 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @Test public void testSecureActuator() { - ResponseEntity entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/management/actuator/env", - String.class); + ResponseEntity entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/env", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testInsecureActuator() { - ResponseEntity entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/management/actuator/health", - String.class); + ResponseEntity entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @@ -76,8 +73,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @Test public void testMissing() { ResponseEntity entity = new TestRestTemplate("admin", "admin") - .getForEntity("http://localhost:" + this.managementPort - + "/management/actuator/missing", String.class); + .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getBody()).contains("\"status\":404"); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java index 49e1d07034..18cd36b953 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,30 +61,26 @@ public class SampleActuatorCustomSecurityApplicationTests { assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map body = entity.getBody(); - assertThat((String) body.get("message")) - .contains("Expected exception in controller"); + assertThat((String) body.get("message")).contains("Expected exception in controller"); } @Test public void testInsecureStaticResources() { - ResponseEntity entity = restTemplate() - .getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity entity = restTemplate().getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } @Test public void actuatorInsecureEndpoint() { - ResponseEntity entity = restTemplate().getForEntity("/actuator/health", - String.class); + ResponseEntity entity = restTemplate().getForEntity("/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @Test public void actuatorLinksIsSecure() { - ResponseEntity entity = restTemplate().getForEntity("/actuator", - Object.class); + ResponseEntity entity = restTemplate().getForEntity("/actuator", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); entity = adminRestTemplate().getForEntity("/actuator", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -92,43 +88,40 @@ public class SampleActuatorCustomSecurityApplicationTests { @Test public void actuatorSecureEndpointWithAnonymous() { - ResponseEntity entity = restTemplate().getForEntity("/actuator/env", - Object.class); + ResponseEntity entity = restTemplate().getForEntity("/actuator/env", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void actuatorSecureEndpointWithUnauthorizedUser() { - ResponseEntity entity = userRestTemplate().getForEntity("/actuator/env", - Object.class); + ResponseEntity entity = userRestTemplate().getForEntity("/actuator/env", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); } @Test public void actuatorSecureEndpointWithAuthorizedUser() { - ResponseEntity entity = adminRestTemplate().getForEntity("/actuator/env", - Object.class); + ResponseEntity entity = adminRestTemplate().getForEntity("/actuator/env", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void actuatorCustomMvcSecureEndpointWithAnonymous() { - ResponseEntity entity = restTemplate() - .getForEntity("/actuator/example/echo?text={t}", String.class, "test"); + ResponseEntity entity = restTemplate().getForEntity("/actuator/example/echo?text={t}", String.class, + "test"); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void actuatorCustomMvcSecureEndpointWithUnauthorizedUser() { - ResponseEntity entity = userRestTemplate() - .getForEntity("/actuator/example/echo?text={t}", String.class, "test"); + ResponseEntity entity = userRestTemplate().getForEntity("/actuator/example/echo?text={t}", String.class, + "test"); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); } @Test public void actuatorCustomMvcSecureEndpointWithAuthorizedUser() { - ResponseEntity entity = adminRestTemplate() - .getForEntity("/actuator/example/echo?text={t}", String.class, "test"); + ResponseEntity entity = adminRestTemplate().getForEntity("/actuator/example/echo?text={t}", + String.class, "test"); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("test"); assertThat(entity.getHeaders().getFirst("echo")).isEqualTo("test"); @@ -136,15 +129,13 @@ public class SampleActuatorCustomSecurityApplicationTests { @Test public void actuatorExcludedFromEndpointRequestMatcher() { - ResponseEntity entity = userRestTemplate() - .getForEntity("/actuator/mappings", Object.class); + ResponseEntity entity = userRestTemplate().getForEntity("/actuator/mappings", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void mvcMatchersCanBeUsedToSecureActuators() { - ResponseEntity entity = beansRestTemplate() - .getForEntity("/actuator/beans", Object.class); + ResponseEntity entity = beansRestTemplate().getForEntity("/actuator/beans", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); entity = beansRestTemplate().getForEntity("/actuator/beans/", Object.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -167,8 +158,7 @@ public class SampleActuatorCustomSecurityApplicationTests { } private TestRestTemplate configure(TestRestTemplate restTemplate) { - restTemplate - .setUriTemplateHandler(new LocalHostUriTemplateHandler(this.environment)); + restTemplate.setUriTemplateHandler(new LocalHostUriTemplateHandler(this.environment)); return restTemplate; } diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java index bc59ddfee3..8c6075e781 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @AutoConfigureMockMvc public class SampleActuatorLog4J2ApplicationTests { - private static final Logger logger = LogManager - .getLogger(SampleActuatorLog4J2ApplicationTests.class); + private static final Logger logger = LogManager.getLogger(SampleActuatorLog4J2ApplicationTests.class); @Rule public OutputCapture output = new OutputCapture(); @@ -65,12 +64,9 @@ public class SampleActuatorLog4J2ApplicationTests { @Test public void validateLoggersEndpoint() throws Exception { - this.mvc.perform( - get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol") - .header("Authorization", "Basic " + getBasicAuth())) - .andExpect(status().isOk()) - .andExpect(content().string(equalTo("{\"configuredLevel\":\"WARN\"," - + "\"effectiveLevel\":\"WARN\"}"))); + this.mvc.perform(get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol").header("Authorization", + "Basic " + getBasicAuth())).andExpect(status().isOk()).andExpect( + content().string(equalTo("{\"configuredLevel\":\"WARN\"," + "\"effectiveLevel\":\"WARN\"}"))); } private String getBasicAuth() { diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index bd143f51b7..5d43adff7d 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port:0" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port:0" }) public class SampleActuatorUiApplicationPortTests { @LocalServerPort @@ -50,26 +49,23 @@ public class SampleActuatorUiApplicationPortTests { @Test public void testHome() { - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.port, String.class); + ResponseEntity entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void testMetrics() { @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/actuator/metrics", - Map.class); + ResponseEntity entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHealth() { - ResponseEntity entity = new TestRestTemplate() - .withBasicAuth("user", getPassword()).getForEntity( - "http://localhost:" + this.managementPort + "/actuator/health", - String.class); + ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java index 9b17ccb5b5..e48bbdc2f7 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,17 +52,15 @@ public class SampleActuatorUiApplicationTests { public void testHome() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity entity = this.restTemplate - .withBasicAuth("user", getPassword()).exchange("/", HttpMethod.GET, - new HttpEntity(headers), String.class); + ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/", + HttpMethod.GET, new HttpEntity(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("Hello"); } @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } @@ -70,8 +68,7 @@ public class SampleActuatorUiApplicationTests { @Test public void testMetrics() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", - Map.class); + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @@ -79,9 +76,8 @@ public class SampleActuatorUiApplicationTests { public void testError() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()).exchange("/error", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/error", + HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getBody()).contains("<html>").contains("<body>") .contains("Please contact the operator with the above information"); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java index abfb59d618..6c136ee68f 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,7 @@ public class SampleController { @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Map<String, String> hello() { - return Collections.singletonMap("message", - this.helloWorldService.getHelloMessage()); + return Collections.singletonMap("message", this.helloWorldService.getHelloMessage()); } @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 36d060ffc6..00ad0aa1ae 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,8 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { @Test public void testCustomErrorPath() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/oops", Map.class); + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); @@ -59,8 +59,7 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { @Test public void testCustomContextPath() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index 251d8d2ae0..060e737918 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", "management.server.address=127.0.0.1", - "management.server.servlet.context-path:/admin" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0", + "management.server.address=127.0.0.1", "management.server.servlet.context-path:/admin" }) public class ManagementAddressActuatorApplicationTests { @LocalServerPort @@ -52,16 +51,14 @@ public class ManagementAddressActuatorApplicationTests { @Test public void testHome() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.port, Map.class); + ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate() - .withBasicAuth("user", getPassword()).getForEntity("http://localhost:" - + this.managementPort + "/admin/actuator/health", String.class); + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java index 8ee4826540..2e524cb415 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -46,8 +46,7 @@ public class ManagementPathSampleActuatorApplicationTests { @Test public void testHealth() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index e3c88ba778..a8a39e98c7 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -40,10 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", - "management.endpoints.web.base-path=/admin", - "management.endpoint.health.show-details=never" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0", + "management.endpoints.web.base-path=/admin", "management.endpoint.health.show-details=never" }) public class ManagementPortAndPathSampleActuatorApplicationTests { @LocalServerPort @@ -70,17 +68,15 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { public void testMetrics() { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/admin/metrics", Map.class); + ResponseEntity<Map> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate() - .withBasicAuth("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/admin/health", - String.class); + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); } @@ -89,19 +85,15 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { public void testEnvNotFound() { String unknownProperty = "test-does-not-exist"; assertThat(this.environment.containsProperty(unknownProperty)).isFalse(); - ResponseEntity<String> entity = new TestRestTemplate() - .withBasicAuth("user", getPassword()).getForEntity("http://localhost:" - + this.managementPort + "/admin/env/" + unknownProperty, - String.class); + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()).getForEntity( + "http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } @Test public void testMissing() { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) - .getForEntity( - "http://localhost:" + this.managementPort + "/admin/missing", - String.class); + .getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getBody()).contains("\"status\":404"); } @@ -121,8 +113,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { public void testManagementErrorPage() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/error", - Map.class); + .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index c2dd637366..94c5ccce88 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { - "management.server.port=0", "management.endpoint.health.show-details=always" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = { "management.server.port=0", "management.endpoint.health.show-details=always" }) public class ManagementPortSampleActuatorApplicationTests { @LocalServerPort @@ -63,18 +63,15 @@ public class ManagementPortSampleActuatorApplicationTests { public void testMetrics() { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/actuator/metrics", - Map.class); + ResponseEntity<Map> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate() - .withBasicAuth("user", getPassword()).getForEntity( - "http://localhost:" + this.managementPort + "/actuator/health", - String.class); + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"example\""); @@ -85,8 +82,7 @@ public class ManagementPortSampleActuatorApplicationTests { public void testErrorPage() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/error", - Map.class); + .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java index 0efc29d3cc..e617796926 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -37,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=-1" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=-1" }) public class NoManagementSampleActuatorApplicationTests { @Autowired @@ -47,8 +46,8 @@ public class NoManagementSampleActuatorApplicationTests { @Test public void testHome() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/", Map.class); + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); @@ -59,8 +58,8 @@ public class NoManagementSampleActuatorApplicationTests { public void testMetricsNotAvailable() { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/metrics", Map.class); + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index 0fc98a929d..2295e5b8e4 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,8 +69,7 @@ public class SampleActuatorApplicationTests { @Test public void testMetricsIsSecure() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", - Map.class); + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); entity = this.restTemplate.getForEntity("/actuator/metrics/", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @@ -83,8 +82,8 @@ public class SampleActuatorApplicationTests { @Test public void testHome() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/", Map.class); + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); @@ -96,8 +95,7 @@ public class SampleActuatorApplicationTests { public void testMetrics() { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/actuator/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); Map<String, Object> body = entity.getBody(); @@ -109,8 +107,7 @@ public class SampleActuatorApplicationTests { @Test public void testEnv() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/actuator/env", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") @@ -120,8 +117,7 @@ public class SampleActuatorApplicationTests { @Test public void testHealth() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); @@ -130,23 +126,19 @@ public class SampleActuatorApplicationTests { @Test public void testInfo() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/actuator/info", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()) - .contains("\"artifact\":\"spring-boot-sample-actuator\""); + assertThat(entity.getBody()).contains("\"artifact\":\"spring-boot-sample-actuator\""); assertThat(entity.getBody()).contains("\"someKey\":\"someValue\""); - assertThat(entity.getBody()).contains("\"java\":{", "\"source\":\"1.8\"", - "\"target\":\"1.8\""); - assertThat(entity.getBody()).contains("\"encoding\":{", "\"source\":\"UTF-8\"", - "\"reporting\":\"UTF-8\""); + assertThat(entity.getBody()).contains("\"java\":{", "\"source\":\"1.8\"", "\"target\":\"1.8\""); + assertThat(entity.getBody()).contains("\"encoding\":{", "\"source\":\"UTF-8\"", "\"reporting\":\"UTF-8\""); } @Test public void testErrorPage() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/foo", String.class); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); assertThat(body).contains("\"error\":"); @@ -157,9 +149,8 @@ public class SampleActuatorApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<?> request = new HttpEntity<Void>(headers); - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()) - .exchange("/foo", HttpMethod.GET, request, String.class); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", + HttpMethod.GET, request, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); assertThat(body).as("Body was null").isNotNull(); @@ -169,8 +160,8 @@ public class SampleActuatorApplicationTests { @Test public void testErrorPageDirectAccess() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/error", Map.class); + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/error", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); @@ -182,8 +173,7 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("unchecked") public void testBeans() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/actuator/beans", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).containsOnlyKeys("contexts"); @@ -193,17 +183,14 @@ public class SampleActuatorApplicationTests { @Test public void testConfigProps() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/actuator/configprops", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); Map<String, Object> body = entity.getBody(); Map<String, Object> contexts = (Map<String, Object>) body.get("contexts"); - Map<String, Object> context = (Map<String, Object>) contexts - .get(this.applicationContext.getId()); + Map<String, Object> context = (Map<String, Object>) contexts.get(this.applicationContext.getId()); Map<String, Object> beans = (Map<String, Object>) context.get("beans"); - assertThat(beans) - .containsKey("spring.datasource-" + DataSourceProperties.class.getName()); + assertThat(beans).containsKey("spring.datasource-" + DataSourceProperties.class.getName()); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java index 9b83e64075..ca30ea63bc 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java @@ -37,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "server.servlet.path=/spring" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "server.servlet.path=/spring" }) public class ServletPathSampleActuatorApplicationTests { @Autowired @@ -47,8 +46,7 @@ public class ServletPathSampleActuatorApplicationTests { @Test public void testErrorPath() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/spring/error", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") @@ -59,8 +57,7 @@ public class ServletPathSampleActuatorApplicationTests { @Test public void testHealth() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) .getForEntity("/spring/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); @@ -69,8 +66,7 @@ public class ServletPathSampleActuatorApplicationTests { @Test public void testHomeIsSecure() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", - Map.class); + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java index ed322a01fc..74a187de96 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java @@ -41,10 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@SpringBootTest( - classes = { ShutdownSampleActuatorApplicationTests.SecurityConfiguration.class, - SampleActuatorApplication.class }, - webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = { ShutdownSampleActuatorApplicationTests.SecurityConfiguration.class, + SampleActuatorApplication.class }, webEnvironment = WebEnvironment.RANDOM_PORT) public class ShutdownSampleActuatorApplicationTests { @Autowired @@ -53,8 +51,8 @@ public class ShutdownSampleActuatorApplicationTests { @Test public void testHome() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/", Map.class); + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); @@ -65,8 +63,7 @@ public class ShutdownSampleActuatorApplicationTests { @DirtiesContext public void testShutdown() { @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate - .withBasicAuth("user", getPassword()) + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .postForEntity("/actuator/shutdown", null, Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") diff --git a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java index 63fbfd2ce1..cfd2a61820 100644 --- a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java +++ b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,12 +48,10 @@ public class SampleAntApplicationIT { }); assertThat(jarFiles).hasSize(1); - Process process = new JavaExecutable() - .processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); + Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); process.waitFor(5, TimeUnit.MINUTES); assertThat(process.exitValue()).isEqualTo(0); - String output = FileCopyUtils - .copyToString(new InputStreamReader(process.getInputStream())); + String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); assertThat(output).contains("Spring Boot Ant Example"); } diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java index 9d3d6b1255..3b4263463b 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java @@ -48,13 +48,11 @@ public class ChatService { @org.atmosphere.config.service.Message(encoders = JacksonEncoderDecoder.class, decoders = JacksonEncoderDecoder.class) public Message onMessage(Message message) throws IOException { - this.logger.info("Author {} sent message {}", message.getAuthor(), - message.getMessage()); + this.logger.info("Author {} sent message {}", message.getAuthor(), message.getMessage()); return message; } - public static class JacksonEncoderDecoder - implements Encoder<Message, String>, Decoder<String, Message> { + public static class JacksonEncoderDecoder implements Encoder<Message, String>, Decoder<String, Message> { private final ObjectMapper mapper = new ObjectMapper(); diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java index 2b393a9640..0732b8a318 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,11 +48,11 @@ public class SampleAtmosphereApplication { public ServletRegistrationBean<AtmosphereServlet> atmosphereServlet() { // Dispatcher servlet is mapped to '/home' to allow the AtmosphereServlet // to be mapped to '/chat' - ServletRegistrationBean<AtmosphereServlet> registration = new ServletRegistrationBean<>( - new AtmosphereServlet(), "/chat/*"); + ServletRegistrationBean<AtmosphereServlet> registration = new ServletRegistrationBean<>(new AtmosphereServlet(), + "/chat/*"); registration.addInitParameter("org.atmosphere.cpr.packages", "sample"); - registration.addInitParameter("org.atmosphere.interceptor.HeartbeatInterceptor" - + ".clientHeartbeatFrequencyInSeconds", "10"); + registration.addInitParameter( + "org.atmosphere.interceptor.HeartbeatInterceptor" + ".clientHeartbeatFrequencyInSeconds", "10"); registration.setLoadOnStartup(0); // Need to occur before the EmbeddedAtmosphereInitializer registration.setOrder(Ordered.HIGHEST_PRECEDENCE); diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java index 75d268093e..eae3e51820 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java @@ -45,8 +45,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SampleAtmosphereApplication.class, - webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = SampleAtmosphereApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleAtmosphereApplicationTests { private static Log logger = LogFactory.getLog(SampleAtmosphereApplicationTests.class); @@ -56,18 +55,15 @@ public class SampleAtmosphereApplicationTests { @Test public void chatEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/chat/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/chat/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0L); - assertThat(messagePayloadReference.get()) - .contains("{\"message\":\"test\",\"author\":\"test\",\"time\":"); + assertThat(messagePayloadReference.get()).contains("{\"message\":\"test\",\"author\":\"test\",\"time\":"); } @Configuration @@ -93,8 +89,7 @@ public class SampleAtmosphereApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; } @@ -109,17 +104,13 @@ public class SampleAtmosphereApplicationTests { return new TextWebSocketHandler() { @Override - public void afterConnectionEstablished(WebSocketSession session) - throws Exception { - session.sendMessage(new TextMessage( - "{\"author\":\"test\",\"message\":\"test\"}")); + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + session.sendMessage(new TextMessage("{\"author\":\"test\",\"message\":\"test\"}")); } @Override - protected void handleTextMessage(WebSocketSession session, - TextMessage message) throws Exception { - logger.info("Received: " + message + " (" - + ClientConfiguration.this.latch.getCount() + ")"); + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + logger.info("Received: " + message + " (" + ClientConfiguration.this.latch.getCount() + ")"); session.close(); ClientConfiguration.this.messagePayload.set(message.getPayload()); ClientConfiguration.this.latch.countDown(); diff --git a/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java b/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java index 9c62d82b9e..0c737c4a55 100644 --- a/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java +++ b/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,7 @@ public class SampleBatchApplication { return new Tasklet() { @Override - public RepeatStatus execute(StepContribution contribution, - ChunkContext context) { + public RepeatStatus execute(StepContribution contribution, ChunkContext context) { return RepeatStatus.FINISHED; } }; @@ -66,8 +65,7 @@ public class SampleBatchApplication { public static void main(String[] args) { // System.exit is common for Batch applications since the exit code can be used to // drive a workflow - System.exit(SpringApplication - .exit(SpringApplication.run(SampleBatchApplication.class, args))); + System.exit(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class, args))); } } diff --git a/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java b/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java index a147798b48..dcf00f18d1 100644 --- a/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,7 @@ public class SampleBatchApplicationTests { @Test public void testDefaultSettings() { - assertThat(SpringApplication - .exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0); + assertThat(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0); String output = this.outputCapture.toString(); assertThat(output).contains("completed with the following parameters"); } diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java index b97dce15d6..3e5849e073 100644 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java +++ b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ public class CacheManagerCheck implements CommandLineRunner { @Override public void run(String... strings) throws Exception { - logger.info("\n\n" + "=========================================================\n" - + "Using cache manager: " + this.cacheManager.getClass().getName() + "\n" + logger.info("\n\n" + "=========================================================\n" + "Using cache manager: " + + this.cacheManager.getClass().getName() + "\n" + "=========================================================\n\n"); } diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java index 1ee30c660d..2d4d5fb657 100644 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java +++ b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; public class SampleCacheApplication { public static void main(String[] args) { - new SpringApplicationBuilder().sources(SampleCacheApplication.class) - .profiles("app").run(args); + new SpringApplicationBuilder().sources(SampleCacheApplication.class).profiles("app").run(args); } } diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java index 9731e05cd5..27823e8f4b 100644 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java +++ b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,26 +28,21 @@ import org.springframework.stereotype.Component; @Profile("app") class SampleClient { - private static final List<String> SAMPLE_COUNTRY_CODES = Arrays.asList("AF", "AX", - "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", - "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", - "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", - "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", - "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", - "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", - "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", - "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", - "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", - "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", - "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", - "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", - "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", - "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", - "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", - "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", - "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", - "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", - "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"); + private static final List<String> SAMPLE_COUNTRY_CODES = Arrays.asList("AF", "AX", "AL", "DZ", "AS", "AD", "AO", + "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", + "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", + "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", + "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", + "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", + "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", + "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", + "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", + "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", + "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", + "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", + "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", + "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", + "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"); private final CountryRepository countryService; @@ -60,8 +55,7 @@ class SampleClient { @Scheduled(fixedDelay = 500) public void retrieveCountry() { - String randomCode = SAMPLE_COUNTRY_CODES - .get(this.random.nextInt(SAMPLE_COUNTRY_CODES.size())); + String randomCode = SAMPLE_COUNTRY_CODES.get(this.random.nextInt(SAMPLE_COUNTRY_CODES.size())); System.out.println("Looking for country with code '" + randomCode + "'"); this.countryService.findByCode(randomCode); } diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java index 1ca9ad4873..f6544d802e 100644 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java +++ b/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,7 @@ public class Customer { @Override public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, - this.firstName, this.lastName); + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); } } diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java index 870fb87443..644d8e5ee6 100644 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java +++ b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,9 @@ import org.slf4j.LoggerFactory; import org.springframework.core.Ordered; -public class OrderedCassandraTestExecutionListener - extends CassandraUnitDependencyInjectionTestExecutionListener { +public class OrderedCassandraTestExecutionListener extends CassandraUnitDependencyInjectionTestExecutionListener { - private static final Logger logger = LoggerFactory - .getLogger(OrderedCassandraTestExecutionListener.class); + private static final Logger logger = LoggerFactory.getLogger(OrderedCassandraTestExecutionListener.class); @Override public int getOrder() { diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java b/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java index dac594d578..c8253536fe 100644 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java +++ b/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,8 +59,8 @@ public class User { @Override public String toString() { - return "User{" + "id='" + this.id + '\'' + ", firstName='" + this.firstName + '\'' - + ", lastName='" + this.lastName + '\'' + '}'; + return "User{" + "id='" + this.id + '\'' + ", firstName='" + this.firstName + '\'' + ", lastName='" + + this.lastName + '\'' + '}'; } } diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java index b3f2d7a4a7..5bd6f70fc3 100644 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,7 @@ public class SampleCouchbaseApplicationTests { @Test public void testDefaultSettings() { try { - new SpringApplicationBuilder(SampleCouchbaseApplication.class) - .run("--server.port=0"); + new SpringApplicationBuilder(SampleCouchbaseApplication.class).run("--server.port=0"); } catch (RuntimeException ex) { if (serverNotRunning(ex)) { diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java index c214eac59f..8002e9ddd3 100644 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java @@ -19,8 +19,7 @@ package sample.data.elasticsearch; import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; -@Document(indexName = "customer", type = "customer", shards = 1, replicas = 0, - refreshInterval = "-1") +@Document(indexName = "customer", type = "customer", shards = 1, replicas = 0, refreshInterval = "-1") public class Customer { @Id @@ -64,8 +63,7 @@ public class Customer { @Override public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, - this.firstName, this.lastName); + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); } } diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java index dd62c7a6d1..69b2a72247 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java @@ -30,8 +30,7 @@ public class City implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", - initialValue = 23) + @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) @GeneratedValue(generator = "city_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java index 3743a3a0b7..a2d7804710 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java @@ -36,8 +36,7 @@ public class Hotel implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", - initialValue = 28) + @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) @GeneratedValue(generator = "hotel_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java index 36ad46e16b..608943423b 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java @@ -38,8 +38,7 @@ public class Review implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name = "review_generator", sequenceName = "review_sequence", - initialValue = 64) + @SequenceGenerator(name = "review_generator", sequenceName = "review_sequence", initialValue = 64) @GeneratedValue(generator = "review_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java index 99d44d78a1..c16ec30dfb 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ interface CityRepository extends Repository<City, Long> { Page<City> findAll(Pageable pageable); - Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(String name, - String country, Pageable pageable); + Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(String name, String country, Pageable pageable); City findByNameAndCountryAllIgnoringCase(String name, String country); diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java index 2fa9c35be4..6ba53659c3 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,9 +57,8 @@ class CityServiceImpl implements CityService { name = name.substring(0, splitPos); } - return this.cityRepository - .findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(), - country.trim(), pageable); + return this.cityRepository.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(), country.trim(), + pageable); } @Override diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java index 5b22832d7a..f7ec49edce 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java @@ -45,8 +45,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @RunWith(SpringRunner.class) // Enable JMX so we can test the MBeans (you can't do this in a properties file) -@SpringBootTest( - properties = { "spring.jmx.enabled:true", "spring.datasource.jmx-enabled:true" }) +@SpringBootTest(properties = { "spring.jmx.enabled:true", "spring.datasource.jmx-enabled:true" }) @ActiveProfiles("scratch") // Separate profile for web tests to avoid clashing databases public class SampleDataJpaApplicationTests { @@ -64,15 +63,13 @@ public class SampleDataJpaApplicationTests { @Test public void testHome() throws Exception { - this.mvc.perform(get("/")).andExpect(status().isOk()) - .andExpect(content().string("Bath")); + this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Bath")); } @Test public void testJmx() throws Exception { assertThat(ManagementFactory.getPlatformMBeanServer() - .queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null)) - .hasSize(1); + .queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null)).hasSize(1); } } diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java index 777843c301..ced0856838 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,13 +51,10 @@ public class HotelRepositoryIntegrationTests { @Test public void executesQueryMethodsCorrectly() { - City city = this.cityRepository - .findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0); + City city = this.cityRepository.findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0); assertThat(city.getName()).isEqualTo("Atlanta"); - Page<HotelSummary> hotels = this.repository.findByCity(city, - PageRequest.of(0, 10, Direction.ASC, "name")); - Hotel hotel = this.repository.findByCityAndName(city, - hotels.getContent().get(0).getName()); + Page<HotelSummary> hotels = this.repository.findByCity(city, PageRequest.of(0, 10, Direction.ASC, "name")); + Hotel hotel = this.repository.findByCityAndName(city, hotels.getContent().get(0).getName()); assertThat(hotel.getName()).isEqualTo("Doubletree"); List<RatingCount> counts = this.repository.findRatingCounts(hotel); assertThat(counts).hasSize(1); diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java index d2d6f5351c..80860e0bf9 100644 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java +++ b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,7 @@ public class Customer { @Override public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, - this.firstName, this.lastName); + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); } } diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java index eb04ad9765..1568eca45d 100644 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java +++ b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,8 +41,7 @@ public class Customer { @Override public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, - this.firstName, this.lastName); + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); } } diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java index 71776d03ec..2359abc991 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java @@ -30,8 +30,7 @@ public class City implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", - initialValue = 23) + @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) @GeneratedValue(generator = "city_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java index 3f135c59c0..91e249e93b 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java @@ -33,8 +33,7 @@ public class Hotel implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", - initialValue = 28) + @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) @GeneratedValue(generator = "hotel_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java index cf2f66c3b8..566d54db8a 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,9 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "cities", path = "cities") interface CityRepository extends PagingAndSortingRepository<City, Long> { - Page<City> findByNameContainingAndCountryContainingAllIgnoringCase( - @Param("name") String name, @Param("country") String country, - Pageable pageable); + Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(@Param("name") String name, + @Param("country") String country, Pageable pageable); - City findByNameAndCountryAllIgnoringCase(@Param("name") String name, - @Param("country") String country); + City findByNameAndCountryAllIgnoringCase(@Param("name") String name, @Param("country") String country); } diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java index a557dd7483..b605dbeb14 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,25 +58,21 @@ public class SampleDataRestApplicationTests { @Test public void testHome() throws Exception { - this.mvc.perform(get("/api")).andExpect(status().isOk()) - .andExpect(content().string(containsString("hotels"))); + this.mvc.perform(get("/api")).andExpect(status().isOk()).andExpect(content().string(containsString("hotels"))); } @Test public void findByNameAndCountry() throws Exception { - this.mvc.perform(get( - "/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia")) - .andExpect(status().isOk()) - .andExpect(jsonPath("state", equalTo("Victoria"))) + this.mvc.perform(get("/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia")) + .andExpect(status().isOk()).andExpect(jsonPath("state", equalTo("Victoria"))) .andExpect(jsonPath("name", equalTo("Melbourne"))); } @Test public void findByContaining() throws Exception { - this.mvc.perform(get( - "/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK")) - .andExpect(status().isOk()) - .andExpect(jsonPath("_embedded.cities", hasSize(3))); + this.mvc.perform( + get("/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK")) + .andExpect(status().isOk()).andExpect(jsonPath("_embedded.cities", hasSize(3))); } } diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java index 25700d0371..a2852f155f 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java @@ -49,17 +49,15 @@ public class CityRepositoryIntegrationTests { @Test public void findByNameAndCountry() { - City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne", - "Australia"); + City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne", "Australia"); assertThat(city).isNotNull(); assertThat(city.getName()).isEqualTo("Melbourne"); } @Test public void findContaining() { - Page<City> cities = this.repository - .findByNameContainingAndCountryContainingAllIgnoringCase("", "UK", - PageRequest.of(0, 10)); + Page<City> cities = this.repository.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK", + PageRequest.of(0, 10)); assertThat(cities.getTotalElements()).isEqualTo(3L); } diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java index 3d44260f8f..f569740eb4 100644 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java +++ b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java @@ -93,8 +93,8 @@ public class Product { @Override public String toString() { - return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price - + ", category=" + this.category + ", location=" + this.location + "]"; + return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price + ", category=" + + this.category + ", location=" + this.location + "]"; } } diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java index 8a0dcb8fb6..d0778e9dd0 100644 --- a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java +++ b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java @@ -41,8 +41,7 @@ public class MyController { sessionVar = new Date(); session.setAttribute("var", sessionVar); } - ModelMap model = new ModelMap("message", Message.MESSAGE) - .addAttribute("sessionVar", sessionVar); + ModelMap model = new ModelMap("message", Message.MESSAGE).addAttribute("sessionVar", sessionVar); return new ModelAndView("hello", model); } diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java index 09d4230e68..b7a97652b2 100644 --- a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java @@ -44,24 +44,21 @@ public class SampleDevToolsApplicationIntegrationTests { @Test public void testStaticResource() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/css/application.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/application.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("color: green;"); } @Test public void testPublicResource() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/public.txt", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/public.txt", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("public file"); } @Test public void testClassResource() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/application.properties", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/application.properties", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java index 0371889556..fdf9cc55d4 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java +++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java @@ -25,8 +25,7 @@ import javax.persistence.SequenceGenerator; public class Person { @Id - @SequenceGenerator(name = "person_generator", sequenceName = "person_sequence", - allocationSize = 1) + @SequenceGenerator(name = "person_generator", sequenceName = "person_sequence", allocationSize = 1) @GeneratedValue(generator = "person_generator") private Long id; @@ -52,8 +51,7 @@ public class Person { @Override public String toString() { - return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName - + "]"; + return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName + "]"; } } diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java b/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java index 54e8a02f87..2f17c29c32 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java @@ -35,8 +35,7 @@ public class SampleFlywayApplicationTests { @Test public void testDefaultSettings() { - assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", - Integer.class)).isEqualTo(1); + assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class)).isEqualTo(1); } } diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java index 5385e96e85..93a13b441c 100644 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java @@ -42,11 +42,9 @@ public class SampleHateoasApplicationTests { @Test public void hasHalLinks() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/customers/1", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/customers/1", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).startsWith( - "{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\""); + assertThat(entity.getBody()).startsWith("{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\""); assertThat(entity.getBody()).contains("_links\":{\"self\":{\"href\""); } @@ -55,8 +53,8 @@ public class SampleHateoasApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.ACCEPT, "application/xml;q=0.9,application/json;q=0.8"); HttpEntity<?> request = new HttpEntity<>(headers); - ResponseEntity<String> response = this.restTemplate.exchange("/customers/1", - HttpMethod.GET, request, String.class); + ResponseEntity<String> response = this.restTemplate.exchange("/customers/1", HttpMethod.GET, request, + String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getHeaders().getContentType()) .isEqualTo(MediaType.parseMediaType("application/json;charset=UTF-8")); diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java index 5a4b555488..484088511e 100644 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java +++ b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java @@ -54,25 +54,22 @@ public class SampleIntegrationApplication { @Bean public FileWritingMessageHandler fileWriter() { - FileWritingMessageHandler writer = new FileWritingMessageHandler( - new File("target/output")); + FileWritingMessageHandler writer = new FileWritingMessageHandler(new File("target/output")); writer.setExpectReply(false); return writer; } @Bean public IntegrationFlow integrationFlow(SampleEndpoint endpoint) { - return IntegrationFlows.from(fileReader(), new FixedRatePoller()) - .channel(inputChannel()).handle(endpoint).channel(outputChannel()) - .handle(fileWriter()).get(); + return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint) + .channel(outputChannel()).handle(fileWriter()).get(); } public static void main(String[] args) { SpringApplication.run(SampleIntegrationApplication.class, args); } - private static class FixedRatePoller - implements Consumer<SourcePollingChannelAdapterSpec> { + private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> { @Override public void accept(SourcePollingChannelAdapterSpec spec) { diff --git a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java index 3dc1ceedb6..2f78e6bf17 100644 --- a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java @@ -79,38 +79,34 @@ public class SampleIntegrationApplicationTests { @Test public void testMessageGateway() throws Exception { - this.context = SpringApplication.run(SampleIntegrationApplication.class, - "testviamg"); + this.context = SpringApplication.run(SampleIntegrationApplication.class, "testviamg"); String output = getOutput(); assertThat(output).contains("testviamg"); } private String getOutput() throws Exception { - Future<String> future = Executors.newSingleThreadExecutor() - .submit(new Callable<String>() { - @Override - public String call() throws Exception { - Resource[] resources = getResourcesWithContent(); - while (resources.length == 0) { - Thread.sleep(200); - resources = getResourcesWithContent(); - } - StringBuilder builder = new StringBuilder(); - for (Resource resource : resources) { - try (InputStream inputStream = resource.getInputStream()) { - builder.append(new String( - StreamUtils.copyToByteArray(inputStream))); - } - } - return builder.toString(); + Future<String> future = Executors.newSingleThreadExecutor().submit(new Callable<String>() { + @Override + public String call() throws Exception { + Resource[] resources = getResourcesWithContent(); + while (resources.length == 0) { + Thread.sleep(200); + resources = getResourcesWithContent(); + } + StringBuilder builder = new StringBuilder(); + for (Resource resource : resources) { + try (InputStream inputStream = resource.getInputStream()) { + builder.append(new String(StreamUtils.copyToByteArray(inputStream))); } - }); + } + return builder.toString(); + } + }); return future.get(30, TimeUnit.SECONDS); } private Resource[] getResourcesWithContent() throws IOException { - Resource[] candidates = ResourcePatternUtils - .getResourcePatternResolver(new DefaultResourceLoader()) + Resource[] candidates = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader()) .getResources("file:target/output/**"); for (Resource candidate : candidates) { if (candidate.contentLength() == 0) { diff --git a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java index 9bb2d2f6a2..f435d05b0d 100644 --- a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java +++ b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,7 @@ public class ProducerApplication implements CommandLineRunner { public void run(String... args) throws Exception { new File("target/input").mkdirs(); if (args.length > 0) { - FileOutputStream stream = new FileOutputStream( - "target/input/data" + System.currentTimeMillis() + ".txt"); + FileOutputStream stream = new FileOutputStream("target/input/data" + System.currentTimeMillis() + ".txt"); for (String arg : args) { stream.write(arg.getBytes()); } diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java index eeb157c8f0..20362e4a59 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer public class SampleJerseyApplication extends SpringBootServletInitializer { public static void main(String[] args) { - new SampleJerseyApplication() - .configure(new SpringApplicationBuilder(SampleJerseyApplication.class)) - .run(args); + new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)).run(args); } } diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java index d4c8873230..0d6dd4928e 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,30 +38,26 @@ public class SampleJerseyApplicationTests { @Test public void contextLoads() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void reverse() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/reverse?input=olleh", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse?input=olleh", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("hello"); } @Test public void validation() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); } @Test public void actuatorStatus() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); } diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java b/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java index e482bd01fe..a46500aeca 100644 --- a/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,14 +49,12 @@ public class SampleJersey1Application { public FilterRegistrationBean<ServletContainer> jersey() { FilterRegistrationBean<ServletContainer> bean = new FilterRegistrationBean<>(); bean.setFilter(new ServletContainer()); - bean.addInitParameter("com.sun.jersey.config.property.packages", - "com.sun.jersey;sample.jersey1"); + bean.addInitParameter("com.sun.jersey.config.property.packages", "com.sun.jersey;sample.jersey1"); return bean; } public static void main(String[] args) { - new SpringApplicationBuilder(SampleJersey1Application.class) - .web(WebApplicationType.SERVLET).run(args); + new SpringApplicationBuilder(SampleJersey1Application.class).web(WebApplicationType.SERVLET).run(args); } } diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java index 365e3fb294..f499fa84b0 100644 --- a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,7 @@ public class SampleJersey1ApplicationTests { @Test public void rootReturnsHelloWorld() { - assertThat(this.restTemplate.getForObject("/", String.class)) - .isEqualTo("Hello World"); + assertThat(this.restTemplate.getForObject("/", String.class)).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java index a9d9abf92d..63a441b776 100644 --- a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,13 +62,10 @@ public class SampleJettyApplicationTests { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Accept-Encoding", "gzip"); HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, - requestEntity, byte[].class); + ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - try (GZIPInputStream inflater = new GZIPInputStream( - new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)) - .isEqualTo("Hello World"); + try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { + assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java index b38cb7bf2e..68f5819820 100644 --- a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java +++ b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java @@ -62,18 +62,15 @@ public class JooqExamples implements CommandLineRunner { } private void jooqSql() { - Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME) - .from(BOOK).join(AUTHOR).on(BOOK.AUTHOR_ID.equal(AUTHOR.ID)) - .where(BOOK.PUBLISHED_IN.equal(2015)); + Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME).from(BOOK).join(AUTHOR) + .on(BOOK.AUTHOR_ID.equal(AUTHOR.ID)).where(BOOK.PUBLISHED_IN.equal(2015)); Object[] bind = query.getBindValues().toArray(new Object[0]); - List<String> list = this.jdbc.query(query.getSQL(), bind, - new RowMapper<String>() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString(1) + " : " + rs.getString(2) + " " - + rs.getString(3); - } - }); + List<String> list = this.jdbc.query(query.getSQL(), bind, new RowMapper<String>() { + @Override + public String mapRow(ResultSet rs, int rowNum) throws SQLException { + return rs.getString(1) + " : " + rs.getString(2) + " " + rs.getString(3); + } + }); System.out.println("jOOQ SQL " + list); } diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java b/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java index 97b6dd76f9..d9ac66b3bd 100644 --- a/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java @@ -38,9 +38,8 @@ public class SampleJooqApplicationTests { SampleJooqApplication.main(NO_ARGS); assertThat(this.out.toString()).contains("jOOQ Fetch 1 Greg Turnquest"); assertThat(this.out.toString()).contains("jOOQ Fetch 2 Craig Walls"); - assertThat(this.out.toString()) - .contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " - + "Spring Boot in Action : Craig Walls]"); + assertThat(this.out.toString()).contains( + "jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " + "Spring Boot in Action : Craig Walls]"); } } diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java index 5079ba175f..f9c1a8e147 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java @@ -28,8 +28,7 @@ import javax.persistence.SequenceGenerator; public class Note { @Id - @SequenceGenerator(name = "note_generator", sequenceName = "note_sequence", - initialValue = 5) + @SequenceGenerator(name = "note_generator", sequenceName = "note_sequence", initialValue = 5) @GeneratedValue(generator = "note_generator") private long id; diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java index d5255f240d..09c5673408 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java @@ -28,8 +28,7 @@ import javax.persistence.SequenceGenerator; public class Tag { @Id - @SequenceGenerator(name = "tag_generator", sequenceName = "tag_sequence", - initialValue = 4) + @SequenceGenerator(name = "tag_generator", sequenceName = "tag_sequence", initialValue = 4) @GeneratedValue(generator = "tag_generator") private long id; diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java index 1f18fd3f3f..f530dd0997 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java @@ -33,8 +33,7 @@ class JpaNoteRepository implements NoteRepository { @Override public List<Note> findAll() { - return this.entityManager.createQuery("SELECT n FROM Note n", Note.class) - .getResultList(); + return this.entityManager.createQuery("SELECT n FROM Note n", Note.class).getResultList(); } } diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java index 28cf6095dd..4fbcd3d43c 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java @@ -33,8 +33,7 @@ class JpaTagRepository implements TagRepository { @Override public List<Tag> findAll() { - return this.entityManager.createQuery("SELECT t FROM Tag t", Tag.class) - .getResultList(); + return this.entityManager.createQuery("SELECT t FROM Tag t", Tag.class).getResultList(); } } diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java index c73edffdad..fa26f31ff4 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java @@ -55,8 +55,7 @@ public class SampleJpaApplicationTests { @Test public void testHome() throws Exception { - this.mvc.perform(get("/")).andExpect(status().isOk()) - .andExpect(xpath("//tbody/tr").nodeCount(4)); + this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(xpath("//tbody/tr").nodeCount(4)); } } diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java index beb4372d16..29518952d8 100644 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java +++ b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java @@ -26,8 +26,7 @@ import org.springframework.context.ApplicationContext; public class SampleAtomikosApplication { public static void main(String[] args) throws Exception { - ApplicationContext context = SpringApplication - .run(SampleAtomikosApplication.class, args); + ApplicationContext context = SpringApplication.run(SampleAtomikosApplication.class, args); AccountService service = context.getBean(AccountService.class); AccountRepository repository = context.getBean(AccountRepository.class); service.createAccountAndNotify("josh"); diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java index b74328d7da..3d1e75924b 100644 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java @@ -45,8 +45,7 @@ public class SampleAtomikosApplicationTests { } private Condition<String> substring(int times, String substring) { - return new Condition<String>( - "containing '" + substring + "' " + times + " times") { + return new Condition<String>("containing '" + substring + "' " + times + " times") { @Override public boolean matches(String value) { diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java index 98d09e9091..dfa42e8064 100644 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java +++ b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ import org.springframework.context.ApplicationContext; public class SampleBitronixApplication { public static void main(String[] args) throws Exception { - ApplicationContext context = SpringApplication - .run(SampleBitronixApplication.class, args); + ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class, args); AccountService service = context.getBean(AccountService.class); AccountRepository repository = context.getBean(AccountRepository.class); service.createAccountAndNotify("josh"); diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java index 60ec0d8084..25d77bfba1 100644 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,20 +49,17 @@ public class SampleBitronixApplicationTests { @Test public void testExposesXaAndNonXa() { - ApplicationContext context = SpringApplication - .run(SampleBitronixApplication.class); + ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class); Object jmsConnectionFactory = context.getBean("jmsConnectionFactory"); Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory"); Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory"); assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory); assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class); - assertThat(nonXaJmsConnectionFactory) - .isNotInstanceOf(PoolingConnectionFactory.class); + assertThat(nonXaJmsConnectionFactory).isNotInstanceOf(PoolingConnectionFactory.class); } private Condition<String> substring(int times, String substring) { - return new Condition<String>( - "containing '" + substring + "' " + times + " times") { + return new Condition<String>("containing '" + substring + "' " + times + " times") { @Override public boolean matches(String value) { diff --git a/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/java/sample/narayana/SampleNarayanaApplication.java b/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/java/sample/narayana/SampleNarayanaApplication.java index 9e9990b56c..823726866c 100644 --- a/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/java/sample/narayana/SampleNarayanaApplication.java +++ b/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/java/sample/narayana/SampleNarayanaApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ import org.springframework.context.ApplicationContext; public class SampleNarayanaApplication { public static void main(String[] args) throws Exception { - ApplicationContext context = SpringApplication - .run(SampleNarayanaApplication.class, args); + ApplicationContext context = SpringApplication.run(SampleNarayanaApplication.class, args); AccountService service = context.getBean(AccountService.class); AccountRepository repository = context.getBean(AccountRepository.class); service.createAccountAndNotify("josh"); diff --git a/spring-boot-samples/spring-boot-sample-jta-narayana/src/test/java/sample/narayana/SampleNarayanaApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-narayana/src/test/java/sample/narayana/SampleNarayanaApplicationTests.java index 2a7919ccdf..cd3dd42c15 100644 --- a/spring-boot-samples/spring-boot-sample-jta-narayana/src/test/java/sample/narayana/SampleNarayanaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jta-narayana/src/test/java/sample/narayana/SampleNarayanaApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,7 @@ public class SampleNarayanaApplicationTests { } private Condition<String> substring(int times, String substring) { - return new Condition<String>( - "containing '" + substring + "' " + times + " times") { + return new Condition<String>("containing '" + substring + "' " + times + " times") { @Override public boolean matches(String value) { diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java index 875fd9b027..bd6cf687e8 100644 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java +++ b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,7 @@ public class SampleMessage { private final String message; @JsonCreator - public SampleMessage(@JsonProperty("id") Integer id, - @JsonProperty("message") String message) { + public SampleMessage(@JsonProperty("id") Integer id, @JsonProperty("message") String message) { this.id = id; this.message = message; } diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java index 8d3c446109..1e80b3bbfe 100644 --- a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java @@ -39,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll */ @RunWith(SpringRunner.class) -@SpringBootTest( - properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}") +@SpringBootTest(properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}") @EmbeddedKafka public class SampleKafkaApplicationTests { @@ -52,8 +51,7 @@ public class SampleKafkaApplicationTests { @Test public void testVanillaExchange() throws Exception { assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); - assertThat(this.outputCapture.toString().contains("A simple test message")) - .isTrue(); + assertThat(this.outputCapture.toString().contains("A simple test message")).isTrue(); } @TestConfiguration diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java b/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java index f7e7edfa5b..3c01a8fbbe 100644 --- a/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,16 +43,12 @@ public class SampleLiquibaseApplicationTests { } String output = this.outputCapture.toString(); assertThat(output).contains("Successfully acquired change log lock") - .contains("Creating database history " - + "table with name: PUBLIC.DATABASECHANGELOG") + .contains("Creating database history " + "table with name: PUBLIC.DATABASECHANGELOG") .contains("Table person created") - .contains("ChangeSet classpath:/db/" - + "changelog/db.changelog-master.yaml::1::" - + "marceloverdijk ran successfully") - .contains("New row inserted into person") - .contains("ChangeSet classpath:/db/changelog/" - + "db.changelog-master.yaml::2::" + .contains("ChangeSet classpath:/db/" + "changelog/db.changelog-master.yaml::1::" + "marceloverdijk ran successfully") + .contains("New row inserted into person").contains("ChangeSet classpath:/db/changelog/" + + "db.changelog-master.yaml::2::" + "marceloverdijk ran successfully") .contains("Successfully released change log lock"); } diff --git a/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java b/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java index 57f9aa406d..bc24bc3ca1 100644 --- a/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java +++ b/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SampleLogbackApplication { - private static final Logger logger = LoggerFactory - .getLogger(SampleLogbackApplication.class); + private static final Logger logger = LoggerFactory.getLogger(SampleLogbackApplication.class); @PostConstruct public void logSomething() { diff --git a/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java b/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java index d75600a41b..b733173bed 100644 --- a/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,7 @@ public class SampleLogbackApplicationTests { @Test public void testProfile() throws Exception { - SampleLogbackApplication - .main(new String[] { "--spring.profiles.active=staging" }); + SampleLogbackApplication.main(new String[] { "--spring.profiles.active=staging" }); this.outputCapture.expect(containsString("Sample Debug Message")); this.outputCapture.expect(containsString("Sample Trace Message")); } diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java b/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java index 83059a70d4..105c6d7971 100644 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java @@ -32,8 +32,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "APP-CLIENT-ID=my-client-id", "APP-CLIENT-SECRET=my-client-secret" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { "APP-CLIENT-ID=my-client-id", "APP-CLIENT-SECRET=my-client-secret" }) public class SampleOAuth2ClientApplicationTests { @LocalServerPort @@ -46,14 +46,12 @@ public class SampleOAuth2ClientApplicationTests { public void everythingShouldRedirectToLogin() { ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation()) - .isEqualTo(URI.create("http://localhost:" + this.port + "/login")); + assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create("http://localhost:" + this.port + "/login")); } @Test public void loginShouldHaveBothOAuthClientsToChooseFrom() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/login", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/login", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-1"); assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-2"); diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java index 646f2417ee..4ff2bc3a86 100644 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java +++ b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java @@ -38,8 +38,7 @@ import org.springframework.integration.file.FileWritingMessageHandler; public class SampleParentContextApplication { public static void main(String[] args) throws Exception { - new SpringApplicationBuilder(Parent.class) - .child(SampleParentContextApplication.class).run(args); + new SpringApplicationBuilder(Parent.class).child(SampleParentContextApplication.class).run(args); } @Configuration @@ -65,21 +64,18 @@ public class SampleParentContextApplication { @Bean public FileWritingMessageHandler fileWriter() { - FileWritingMessageHandler writer = new FileWritingMessageHandler( - new File("target/output")); + FileWritingMessageHandler writer = new FileWritingMessageHandler(new File("target/output")); writer.setExpectReply(false); return writer; } @Bean public IntegrationFlow integrationFlow(SampleEndpoint endpoint) { - return IntegrationFlows.from(fileReader(), new FixedRatePoller()) - .channel(inputChannel()).handle(endpoint).channel(outputChannel()) - .handle(fileWriter()).get(); + return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint) + .channel(outputChannel()).handle(fileWriter()).get(); } - private static class FixedRatePoller - implements Consumer<SourcePollingChannelAdapterSpec> { + private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> { @Override public void accept(SourcePollingChannelAdapterSpec spec) { diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java b/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java index 8a0adaa3c8..0b5dfe6ed2 100644 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,21 +81,18 @@ public class SampleIntegrationParentApplicationTests { } } } - fail("Timed out awaiting output containing '" + requiredContents - + "'. Output was '" + output + "'"); + fail("Timed out awaiting output containing '" + requiredContents + "'. Output was '" + output + "'"); } private Resource[] findResources() throws IOException { - return ResourcePatternUtils - .getResourcePatternResolver(new DefaultResourceLoader()) + return ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader()) .getResources("file:target/output/*.txt"); } private String readResources(Resource[] resources) throws IOException { StringBuilder builder = new StringBuilder(); for (Resource resource : resources) { - builder.append( - new String(StreamUtils.copyToByteArray(resource.getInputStream()))); + builder.append(new String(StreamUtils.copyToByteArray(resource.getInputStream()))); } return builder.toString(); } diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java b/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java index 0ff4287531..f85b446562 100644 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java +++ b/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,7 @@ public class ProducerApplication implements CommandLineRunner { public void run(String... args) throws Exception { new File("target/input").mkdirs(); if (args.length > 0) { - FileOutputStream stream = new FileOutputStream( - "target/input/data" + System.currentTimeMillis() + ".txt"); + FileOutputStream stream = new FileOutputStream("target/input/data" + System.currentTimeMillis() + ".txt"); for (String arg : args) { stream.write(arg.getBytes()); } diff --git a/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java b/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java index 1a65331114..a61b240e29 100644 --- a/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,8 +78,7 @@ public class SampleProfileApplicationTests { @Test public void testGoodbyeProfileFromCommandline() throws Exception { - SampleProfileApplication - .main(new String[] { "--spring.profiles.active=goodbye" }); + SampleProfileApplication.main(new String[] { "--spring.profiles.active=goodbye" }); String output = this.outputCapture.toString(); assertThat(output).contains("Goodbye Everyone"); } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java index d3132d8aff..277b1a9f13 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,7 @@ public class SamplePropertiesValidator implements Validator { ValidationUtils.rejectIfEmpty(errors, "host", "host.empty"); ValidationUtils.rejectIfEmpty(errors, "port", "port.empty"); SampleProperties properties = (SampleProperties) o; - if (properties.getHost() != null - && !this.pattern.matcher(properties.getHost()).matches()) { + if (properties.getHost() != null && !this.pattern.matcher(properties.getHost()).matches()) { errors.rejectValue("host", "Invalid host"); } } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java index 00ec4ce532..cfaedaaea5 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,7 @@ public class SamplePropertyValidationApplicationTests { @Test public void bindValidProperties() { this.context.register(SamplePropertyValidationApplication.class); - TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090") - .applyTo(this.context); + TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090").applyTo(this.context); this.context.refresh(); SampleProperties properties = this.context.getBean(SampleProperties.class); assertThat(properties.getHost()).isEqualTo("192.168.0.1"); @@ -60,8 +59,7 @@ public class SamplePropertyValidationApplicationTests { @Test public void bindInvalidHost() { this.context.register(SamplePropertyValidationApplication.class); - TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090") - .applyTo(this.context); + TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090").applyTo(this.context); this.thrown.expect(BeanCreationException.class); this.thrown.expectMessage("Failed to bind properties under 'sample'"); this.context.refresh(); @@ -79,8 +77,7 @@ public class SamplePropertyValidationApplicationTests { public void validatorOnlyCalledOnSupportedClass() { this.context.register(SamplePropertyValidationApplication.class); this.context.register(ServerProperties.class); // our validator will not apply - TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090") - .applyTo(this.context); + TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090").applyTo(this.context); this.context.refresh(); SampleProperties properties = this.context.getBean(SampleProperties.class); assertThat(properties.getHost()).isEqualTo("192.168.0.1"); diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java b/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java index 89b09de03c..a0449fe9bf 100644 --- a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java +++ b/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,7 @@ public class SampleJob extends QuartzJobBean { } @Override - protected void executeInternal(JobExecutionContext context) - throws JobExecutionException { + protected void executeInternal(JobExecutionContext context) throws JobExecutionException { System.out.println(String.format("Hello %s!", this.name)); } diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java b/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java index 9590d0667a..c6300b64f7 100644 --- a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java +++ b/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,17 +35,17 @@ public class SampleQuartzApplication { @Bean public JobDetail sampleJobDetail() { - return JobBuilder.newJob(SampleJob.class).withIdentity("sampleJob") - .usingJobData("name", "World").storeDurably().build(); + return JobBuilder.newJob(SampleJob.class).withIdentity("sampleJob").usingJobData("name", "World").storeDurably() + .build(); } @Bean public Trigger sampleJobTrigger() { - SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule() - .withIntervalInSeconds(2).repeatForever(); + SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2) + .repeatForever(); - return TriggerBuilder.newTrigger().forJob(sampleJobDetail()) - .withIdentity("sampleTrigger").withSchedule(scheduleBuilder).build(); + return TriggerBuilder.newTrigger().forJob(sampleJobDetail()).withIdentity("sampleTrigger") + .withSchedule(scheduleBuilder).build(); } } diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java b/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java index 976d74e308..5ad17a0d00 100644 --- a/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,11 +37,9 @@ public class SampleQuartzApplicationTests { @Test public void quartzJobIsTriggered() throws InterruptedException { - try (ConfigurableApplicationContext context = SpringApplication - .run(SampleQuartzApplication.class)) { + try (ConfigurableApplicationContext context = SpringApplication.run(SampleQuartzApplication.class)) { long end = System.currentTimeMillis() + 5000; - while ((!this.outputCapture.toString().contains("Hello World!")) - && System.currentTimeMillis() < end) { + while ((!this.outputCapture.toString().contains("Hello World!")) && System.currentTimeMillis() < end) { Thread.sleep(100); } assertThat(this.outputCapture.toString()).contains("Hello World!"); diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java index 2b45cb0741..34e446ef97 100644 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java @@ -43,28 +43,28 @@ public class SampleSecureWebFluxApplicationTests { @Test public void userDefinedMappingsSecureByDefault() { - this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange() - .expectStatus().isEqualTo(HttpStatus.UNAUTHORIZED); + this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void actuatorsSecureByDefault() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON) - .exchange().expectStatus().isUnauthorized(); + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isUnauthorized(); } @Test public void userDefinedMappingsAccessibleOnLogin() { this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange() - .expectBody(String.class).isEqualTo("Hello user"); + .header("Authorization", "basic " + getBasicAuth()).exchange().expectBody(String.class) + .isEqualTo("Hello user"); } @Test public void actuatorsAccessibleOnLogin() { this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange() - .expectBody(String.class).isEqualTo("{\"status\":\"UP\"}"); + .header("Authorization", "basic " + getBasicAuth()).exchange().expectBody(String.class) + .isEqualTo("{\"status\":\"UP\"}"); } private String getBasicAuth() { diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java index ec796fc0b1..893f7a3ba6 100644 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java @@ -43,9 +43,8 @@ import org.springframework.test.web.reactive.server.WebTestClient; * @author Madhura Bhave */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class, - SampleSecureWebFluxApplication.class }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class, SampleSecureWebFluxApplication.class }) public class SampleSecureWebFluxCustomSecurityTests { @Autowired @@ -53,52 +52,47 @@ public class SampleSecureWebFluxCustomSecurityTests { @Test public void userDefinedMappingsSecure() { - this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange() - .expectStatus().isEqualTo(HttpStatus.UNAUTHORIZED); + this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void healthAndInfoDoNotRequireAuthentication() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON) - .exchange().expectStatus().isOk(); - this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON) - .exchange().expectStatus().isOk(); + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isOk(); + this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk(); } @Test public void actuatorsSecuredByRole() { this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange() - .expectStatus().isForbidden(); + .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isForbidden(); } @Test public void actuatorsAccessibleOnCorrectLogin() { this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange() - .expectStatus().isOk(); + .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange().expectStatus().isOk(); } @Test public void actuatorExcludedFromEndpointRequestMatcher() { this.webClient.get().uri("/actuator/mappings").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange() - .expectStatus().isOk(); + .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isOk(); } @Test public void staticResourceShouldBeAccessible() { - this.webClient.get().uri("/css/bootstrap.min.css") - .accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk(); + this.webClient.get().uri("/css/bootstrap.min.css").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isOk(); } @Test public void actuatorLinksIsSecure() { + this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isUnauthorized(); this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON) - .exchange().expectStatus().isUnauthorized(); - this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange() - .expectStatus().isOk(); + .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange().expectStatus().isOk(); } private String getBasicAuth() { @@ -116,22 +110,18 @@ public class SampleSecureWebFluxCustomSecurityTests { @Bean public MapReactiveUserDetailsService userDetailsService() { return new MapReactiveUserDetailsService( - User.withDefaultPasswordEncoder().username("user") - .password("password").authorities("ROLE_USER").build(), + User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER") + .build(), User.withDefaultPasswordEncoder().username("admin").password("admin") .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); } @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - return http.authorizeExchange().matchers(EndpointRequest.to("health", "info")) - .permitAll() - .matchers(EndpointRequest.toAnyEndpoint() - .excluding(MappingsEndpoint.class)) - .hasRole("ACTUATOR") - .matchers(PathRequest.toStaticResources().atCommonLocations()) - .permitAll().pathMatchers("/login").permitAll().anyExchange() - .authenticated().and().httpBasic().and().build(); + return http.authorizeExchange().matchers(EndpointRequest.to("health", "info")).permitAll() + .matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") + .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll().pathMatchers("/login") + .permitAll().anyExchange().authenticated().and().httpBasic().and().build(); } } diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java index f6629c4be1..ec0afa4be3 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,8 @@ public class SampleSecureApplication implements CommandLineRunner { @Override public void run(String... args) throws Exception { - SecurityContextHolder.getContext() - .setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A", - AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"))); + SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A", + AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"))); try { System.out.println(this.service.secure()); } diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java index bfdfd2562f..e27a5914f5 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,8 +40,7 @@ public class SampleServletApplication extends SpringBootServletInitializer { public Servlet dispatcherServlet() { return new GenericServlet() { @Override - public void service(ServletRequest req, ServletResponse res) - throws ServletException, IOException { + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); res.getWriter().append("Hello World"); } diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java index a23f1b71cf..886d347e02 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java @@ -51,15 +51,15 @@ public class SampleServletApplicationTests { public void testHomeIsSecure() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHome() { - ResponseEntity<String> entity = this.restTemplate - .withBasicAuth("user", getPassword()).getForEntity("/", String.class); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("Hello World"); } diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java index 5ec39bba84..3f4ed7c5cc 100644 --- a/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java @@ -51,22 +51,17 @@ public class SampleSessionWebFluxApplicationTests { @Test public void userDefinedMappingsSecureByDefault() throws Exception { - WebClient webClient = this.webClientBuilder - .baseUrl("http://localhost:" + this.port + "/").build(); - ClientResponse response = webClient.get().header("Authorization", getBasicAuth()) - .exchange().block(Duration.ofSeconds(30)); + WebClient webClient = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build(); + ClientResponse response = webClient.get().header("Authorization", getBasicAuth()).exchange() + .block(Duration.ofSeconds(30)); assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); ResponseCookie sessionCookie = response.cookies().getFirst("SESSION"); - String sessionId = response.bodyToMono(String.class) - .block(Duration.ofSeconds(30)); - response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange() - .block(Duration.ofSeconds(30)); + String sessionId = response.bodyToMono(String.class).block(Duration.ofSeconds(30)); + response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))) - .isEqualTo(sessionId); + assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId); Thread.sleep(2000); - response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange() - .block(Duration.ofSeconds(30)); + response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } diff --git a/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java b/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java index 77e8f509fb..5f75b2a627 100644 --- a/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,8 +57,7 @@ public class SampleSessionApplicationTests { } private ConfigurableApplicationContext createContext() { - ConfigurableApplicationContext context = new SpringApplicationBuilder() - .sources(SampleSessionApplication.class) + ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(SampleSessionApplication.class) .properties("server.port:0", "server.servlet.session.timeout:1") .initializers(new ServerPortInfoApplicationContextInitializer()).run(); return context; @@ -66,14 +65,12 @@ public class SampleSessionApplicationTests { private ResponseEntity<String> firstRequest(RestTemplate restTemplate, URI uri) { HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", "Basic " - + Base64.getEncoder().encodeToString("user:password".getBytes())); + headers.set("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes())); RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri); return restTemplate.exchange(request, String.class); } - private ResponseEntity<String> nextRequest(RestTemplate restTemplate, URI uri, - String cookie) { + private ResponseEntity<String> nextRequest(RestTemplate restTemplate, URI uri, String cookie) { HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", cookie); RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri); diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java index 426f23d47c..51130b0c19 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java +++ b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java @@ -35,15 +35,12 @@ import org.springframework.web.client.RestTemplate; @Service public class RemoteVehicleDetailsService implements VehicleDetailsService { - private static final Logger logger = LoggerFactory - .getLogger(RemoteVehicleDetailsService.class); + private static final Logger logger = LoggerFactory.getLogger(RemoteVehicleDetailsService.class); private final RestTemplate restTemplate; - public RemoteVehicleDetailsService(ServiceProperties properties, - RestTemplateBuilder restTemplateBuilder) { - this.restTemplate = restTemplateBuilder - .rootUri(properties.getVehicleServiceRootUrl()).build(); + public RemoteVehicleDetailsService(ServiceProperties properties, RestTemplateBuilder restTemplateBuilder) { + this.restTemplate = restTemplateBuilder.rootUri(properties.getVehicleServiceRootUrl()).build(); } @Override @@ -52,8 +49,7 @@ public class RemoteVehicleDetailsService implements VehicleDetailsService { Assert.notNull(vin, "VIN must not be null"); logger.debug("Retrieving vehicle data for: " + vin); try { - return this.restTemplate.getForObject("/vehicle/{vin}/details", - VehicleDetails.class, vin); + return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin); } catch (HttpStatusCodeException ex) { if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) { diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java index df40635cb5..2dad1455f1 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java +++ b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java @@ -33,8 +33,7 @@ public class VehicleDetails { private final String model; @JsonCreator - public VehicleDetails(@JsonProperty("make") String make, - @JsonProperty("model") String model) { + public VehicleDetails(@JsonProperty("make") String make, @JsonProperty("model") String model) { Assert.notNull(make, "Make must not be null"); Assert.notNull(model, "Model must not be null"); this.make = make; diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java index 5243fefcd1..a7ee16f762 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java +++ b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java @@ -31,8 +31,7 @@ public class VehicleIdentificationNumberNotFoundException extends RuntimeExcepti this(vin, null); } - public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, - Throwable cause) { + public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, Throwable cause) { super("Unable to find VehicleIdentificationNumber " + vin, cause); this.vehicleIdentificationNumber = vin; } diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java index 2b68e7f258..8b22f4dd8d 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java +++ b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java @@ -37,15 +37,13 @@ public class UserVehicleService { private final VehicleDetailsService vehicleDetailsService; - public UserVehicleService(UserRepository userRepository, - VehicleDetailsService vehicleDetailsService) { + public UserVehicleService(UserRepository userRepository, VehicleDetailsService vehicleDetailsService) { this.userRepository = userRepository; this.vehicleDetailsService = vehicleDetailsService; } public VehicleDetails getVehicleDetails(String username) - throws UserNameNotFoundException, - VehicleIdentificationNumberNotFoundException { + throws UserNameNotFoundException, VehicleIdentificationNumberNotFoundException { Assert.notNull(username, "Username must not be null"); User user = this.userRepository.findByUsername(username); if (user == null) { diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java index 9f94c88201..3c99f63c4d 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java @@ -43,8 +43,7 @@ import static org.mockito.BDDMockito.given; @AutoConfigureTestDatabase public class SampleTestApplicationWebIntegrationTests { - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber( - "01234567890123456"); + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("01234567890123456"); @Autowired private TestRestTemplate restTemplate; @@ -54,8 +53,7 @@ public class SampleTestApplicationWebIntegrationTests { @Before public void setup() { - given(this.vehicleDetailsService.getVehicleDetails(VIN)) - .willReturn(new VehicleDetails("Honda", "Civic")); + given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(new VehicleDetails("Honda", "Civic")); } @Test diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java index 4c63f24df7..d19ffa4dbb 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest public class UserEntityTests { - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber( - "00000000000000000"); + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java index 1872dee541..25d6c630df 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest public class UserRepositoryTests { - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber( - "00000000000000000"); + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); @Autowired private TestEntityManager entityManager; diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java index 877651c1ee..45ccaad4a7 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,8 +68,7 @@ public class VehicleIdentificationNumberTests { public void equalsAndHashCodeShouldBeBasedOnVin() { VehicleIdentificationNumber vin1 = new VehicleIdentificationNumber(SAMPLE_VIN); VehicleIdentificationNumber vin2 = new VehicleIdentificationNumber(SAMPLE_VIN); - VehicleIdentificationNumber vin3 = new VehicleIdentificationNumber( - "00000000000000000"); + VehicleIdentificationNumber vin3 = new VehicleIdentificationNumber("00000000000000000"); assertThat(vin1.hashCode()).isEqualTo(vin2.hashCode()); assertThat(vin1).isEqualTo(vin1).isEqualTo(vin2).isNotEqualTo(vin3); } diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java index 64fa0adbbc..a9f9c16421 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,26 +67,22 @@ public class RemoteVehicleDetailsServiceTests { @Test public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() { this.server.expect(requestTo("/vehicle/" + VIN + "/details")) - .andRespond(withSuccess(getClassPathResource("vehicledetails.json"), - MediaType.APPLICATION_JSON)); - VehicleDetails details = this.service - .getVehicleDetails(new VehicleIdentificationNumber(VIN)); + .andRespond(withSuccess(getClassPathResource("vehicledetails.json"), MediaType.APPLICATION_JSON)); + VehicleDetails details = this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)); assertThat(details.getMake()).isEqualTo("Honda"); assertThat(details.getModel()).isEqualTo("Civic"); } @Test public void getVehicleDetailsWhenResultIsNotFoundShouldThrowException() { - this.server.expect(requestTo("/vehicle/" + VIN + "/details")) - .andRespond(withStatus(HttpStatus.NOT_FOUND)); + this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withStatus(HttpStatus.NOT_FOUND)); this.thrown.expect(VehicleIdentificationNumberNotFoundException.class); this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)); } @Test public void getVehicleDetailsWhenResultIServerErrorShouldThrowException() { - this.server.expect(requestTo("/vehicle/" + VIN + "/details")) - .andRespond(withServerError()); + this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withServerError()); this.thrown.expect(HttpServerErrorException.class); this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)); } diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java index dcb491c151..8edb329245 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,15 +44,13 @@ public class VehicleDetailsJsonTests { assertThat(this.json.write(details)).isEqualTo("vehicledetails.json"); assertThat(this.json.write(details)).isEqualToJson("vehicledetails.json"); assertThat(this.json.write(details)).hasJsonPathStringValue("@.make"); - assertThat(this.json.write(details)).extractingJsonPathStringValue("@.make") - .isEqualTo("Honda"); + assertThat(this.json.write(details)).extractingJsonPathStringValue("@.make").isEqualTo("Honda"); } @Test public void deserializeJson() throws Exception { String content = "{\"make\":\"Ford\",\"model\":\"Focus\"}"; - assertThat(this.json.parse(content)) - .isEqualTo(new VehicleDetails("Ford", "Focus")); + assertThat(this.json.parse(content)).isEqualTo(new VehicleDetails("Ford", "Focus")); assertThat(this.json.parseObject(content).getMake()).isEqualTo("Ford"); } diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java index 5ba10a1cce..265eabf60d 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,17 +59,15 @@ public class UserVehicleControllerApplicationTests { @Test public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)) - .andExpect(status().isOk()).andExpect(content().string("Honda Civic")); + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()) + .andExpect(content().string("Honda Civic")); } @Test public void welcomeCommandLineRunnerShouldBeAvailable() { // Since we're a @SpringBootTest all beans should be available. - assertThat(this.applicationContext.getBean(WelcomeCommandLineRunner.class)) - .isNotNull(); + assertThat(this.applicationContext.getBean(WelcomeCommandLineRunner.class)).isNotNull(); } } diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java index 21d3afa23d..5b960b3ea6 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,7 @@ public class UserVehicleControllerHtmlUnitTests { @Test public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willReturn(new VehicleDetails("Honda", "Civic")); + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); HtmlPage page = this.webClient.getPage("/sboot/vehicle.html"); assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic"); } diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java index ead59c0af6..b16d9420ee 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,7 @@ public class UserVehicleControllerSeleniumTests { @Test public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willReturn(new VehicleDetails("Honda", "Civic")); + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); this.webDriver.get("/sboot/vehicle.html"); WebElement element = this.webDriver.findElement(By.tagName("h1")); assertThat(element.getText()).isEqualTo("Honda Civic"); diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java index 59c59275f4..1260b1976f 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @WebMvcTest(UserVehicleController.class) public class UserVehicleControllerTests { - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber( - "00000000000000000"); + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); @Autowired private MockMvc mvc; @@ -61,34 +60,28 @@ public class UserVehicleControllerTests { @Test public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)) - .andExpect(status().isOk()).andExpect(content().string("Honda Civic")); + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()) + .andExpect(content().string("Honda Civic")); } @Test public void getVehicleWhenRequestingJsonShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(content().json("{'make':'Honda','model':'Civic'}")); } @Test public void getVehicleWhenRequestingHtmlShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML)) - .andExpect(status().isOk()) + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML)).andExpect(status().isOk()) .andExpect(content().string(containsString("<h1>Honda Civic</h1>"))); } @Test public void getVehicleWhenUserNotFoundShouldReturnNotFound() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willThrow(new UserNameNotFoundException("sboot")); + given(this.userVehicleService.getVehicleDetails("sboot")).willThrow(new UserNameNotFoundException("sboot")); this.mvc.perform(get("/sboot/vehicle")).andExpect(status().isNotFound()); } diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java index f01ac029ea..2f6a40d564 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,7 @@ import static org.mockito.BDDMockito.given; */ public class UserVehicleServiceTests { - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber( - "00000000000000000"); + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); @Rule public ExpectedException thrown = ExpectedException.none(); @@ -56,8 +55,7 @@ public class UserVehicleServiceTests { @Before public void setup() { MockitoAnnotations.initMocks(this); - this.service = new UserVehicleService(this.userRepository, - this.vehicleDetailsService); + this.service = new UserVehicleService(this.userRepository, this.vehicleDetailsService); } @Test @@ -76,8 +74,7 @@ public class UserVehicleServiceTests { @Test public void getVehicleDetailsShouldReturnMakeAndModel() { - given(this.userRepository.findByUsername(anyString())) - .willReturn(new User("sboot", VIN)); + given(this.userRepository.findByUsername(anyString())).willReturn(new User("sboot", VIN)); VehicleDetails details = new VehicleDetails("Honda", "Civic"); given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(details); VehicleDetails actual = this.service.getVehicleDetails("sboot"); diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java index 63bc16e77b..25194a9234 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,12 +71,12 @@ public class SampleTomcatTwoConnectorsApplicationTests { public void testHello() { assertThat(this.ports.getHttpsPort()).isEqualTo(this.port); assertThat(this.ports.getHttpPort()).isNotEqualTo(this.port); - ResponseEntity<String> entity = this.restTemplate.getForEntity( - "http://localhost:" + this.ports.getHttpPort() + "/hello", String.class); + ResponseEntity<String> entity = this.restTemplate + .getForEntity("http://localhost:" + this.ports.getHttpPort() + "/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("hello"); - ResponseEntity<String> httpsEntity = this.restTemplate - .getForEntity("https://localhost:" + this.port + "/hello", String.class); + ResponseEntity<String> httpsEntity = this.restTemplate.getForEntity("https://localhost:" + this.port + "/hello", + String.class); assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(httpsEntity.getBody()).isEqualTo("hello"); } @@ -90,8 +90,7 @@ public class SampleTomcatTwoConnectorsApplicationTests { @Override public void onApplicationEvent(WebServerInitializedEvent event) { - Service service = ((TomcatWebServer) event.getWebServer()).getTomcat() - .getService(); + Service service = ((TomcatWebServer) event.getWebServer()).getTomcat().getService(); for (Connector connector : service.findConnectors()) { if (connector.getSecure()) { this.httpsPort = connector.getLocalPort(); diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index dbe0ae95c7..a4cd65f20c 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -60,12 +60,10 @@ public class NonAutoConfigurationSampleTomcatApplicationTests { } @Configuration - @Import({ ServletWebServerFactoryAutoConfiguration.class, - DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, - HttpMessageConvertersAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, + WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) - @ComponentScan( - basePackageClasses = { SampleController.class, HelloWorldService.class }) + @ComponentScan(basePackageClasses = { SampleController.class, HelloWorldService.class }) public static class NonAutoConfigurationSampleTomcatApplication { public static void main(String[] args) { diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java index f3f68f17d3..36a592e551 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,23 +70,18 @@ public class SampleTomcatApplicationTests { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Accept-Encoding", "gzip"); HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, - requestEntity, byte[].class); + ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - try (GZIPInputStream inflater = new GZIPInputStream( - new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)) - .isEqualTo("Hello World"); + try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { + assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); } } @Test public void testTimeout() { ServletWebServerApplicationContext context = (ServletWebServerApplicationContext) this.applicationContext; - TomcatWebServer embeddedServletContainer = (TomcatWebServer) context - .getWebServer(); - ProtocolHandler protocolHandler = embeddedServletContainer.getTomcat() - .getConnector().getProtocolHandler(); + TomcatWebServer embeddedServletContainer = (TomcatWebServer) context.getWebServer(); + ProtocolHandler protocolHandler = embeddedServletContainer.getTomcat().getConnector().getProtocolHandler(); int timeout = ((AbstractProtocol<?>) protocolHandler).getConnectionTimeout(); assertThat(timeout).isEqualTo(5000); } diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java b/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java index 513bffb5cb..9ce6d7e2ff 100644 --- a/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java +++ b/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,8 +51,7 @@ public class WebConfig implements WebMvcConfigurer { } @Override - public void configureDefaultServletHandling( - DefaultServletHandlerConfigurer configurer) { + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); } diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java index 596504f8a7..42f9a991a6 100644 --- a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,8 +51,7 @@ public class SampleTraditionalApplicationTests { @Test public void testStaticPage() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/index.html", - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/index.html", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); String body = entity.getBody(); assertThat(body).contains("<html>").contains("<h1>Hello</h1>"); diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java index feaed38bba..9c0c4a1d8e 100644 --- a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,20 +65,16 @@ public class SampleUndertowApplicationTests { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Accept-Encoding", "gzip"); HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, - requestEntity, byte[].class); + ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - try (GZIPInputStream inflater = new GZIPInputStream( - new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)) - .isEqualTo("Hello World"); + try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { + assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); } } private void assertOkResponse(String path, String body) { - ResponseEntity<String> entity = this.restTemplate.getForEntity(path, - String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity(path, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo(body); } diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java index 42d0d29e5e..df8f9e49e1 100644 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,8 +50,7 @@ public class SampleWebFreeMarkerApplicationTests { @Test public void testFreeMarkerTemplate() { - ResponseEntity<String> entity = this.testRestTemplate.getForEntity("/", - String.class); + ResponseEntity<String> entity = this.testRestTemplate.getForEntity("/", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("Hello, Andy"); } @@ -62,12 +61,11 @@ public class SampleWebFreeMarkerApplicationTests { headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> responseEntity = this.testRestTemplate - .exchange("/does-not-exist", HttpMethod.GET, requestEntity, String.class); + ResponseEntity<String> responseEntity = this.testRestTemplate.exchange("/does-not-exist", HttpMethod.GET, + requestEntity, String.class); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - assertThat(responseEntity.getBody()) - .contains("Something went wrong: 404 Not Found"); + assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java index 1f36425117..c7a57071f9 100644 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,8 +63,7 @@ public class MessageController { } @PostMapping - public ModelAndView create(@Valid Message message, BindingResult result, - RedirectAttributes redirect) { + public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) { if (result.hasErrors()) { ModelAndView mav = new ModelAndView("messages/form"); mav.addObject("formErrors", result.getAllErrors()); diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java index ffcf6dd4ae..912d736c71 100755 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,15 +66,13 @@ public class MessageControllerWebTests { @Test public void testCreate() throws Exception { - this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")) - .andExpect(status().isFound()) + this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound()) .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); } @Test public void testCreateValidation() throws Exception { - this.mockMvc.perform(post("/").param("text", "").param("summary", "")) - .andExpect(status().isOk()) + this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk()) .andExpect(content().string(containsString("is required"))); } @@ -98,8 +96,7 @@ public class MessageControllerWebTests { @Override public void describeTo(Description description) { - description.appendText("a string that matches regex: ") - .appendText(this.regex); + description.appendText("a string that matches regex: ").appendText(this.regex); } public static org.hamcrest.Matcher<java.lang.String> matches(String regex) { diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java index 724a7ca56a..3788062a9e 100644 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,8 +68,7 @@ public class SampleGroovyTemplateApplicationTests { @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java index 9b60a9430a..3a293219a8 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,12 +59,10 @@ public class SampleWebJspApplicationTests { public void customErrorPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - RequestEntity<Void> request = new RequestEntity<>(headers, HttpMethod.GET, - URI.create("/foo")); + RequestEntity<Void> request = new RequestEntity<>(headers, HttpMethod.GET, URI.create("/foo")); ResponseEntity<String> entity = this.restTemplate.exchange(request, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assertThat(entity.getBody()) - .contains("Something went wrong: 500 Internal Server Error"); + assertThat(entity.getBody()).contains("Something went wrong: 500 Internal Server Error"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java index 76aef37716..e8b648bcfe 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,8 +62,7 @@ public class SampleMethodSecurityApplication implements WebMvcConfigurer { return new InMemoryUserDetailsManager( User.withDefaultPasswordEncoder().username("admin").password("admin") .roles("ADMIN", "USER", "ACTUATOR").build(), - User.withDefaultPasswordEncoder().username("user").password("user") - .roles("USER").build()); + User.withDefaultPasswordEncoder().username("user").password("user").roles("USER").build()); } } diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java index 29c1ab0a5e..bf9bbb242c 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,8 +60,8 @@ public class SampleMethodSecurityApplicationTests { public void testHome() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("<title>Login"); } @@ -74,11 +74,10 @@ public class SampleMethodSecurityApplicationTests { form.set("username", "admin"); form.set("password", "admin"); getCsrf(form, headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.POST, new HttpEntity<>(form, headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .isEqualTo("http://localhost:" + this.port + "/"); + assertThat(entity.getHeaders().getLocation().toString()).isEqualTo("http://localhost:" + this.port + "/"); } @Test @@ -89,13 +88,12 @@ public class SampleMethodSecurityApplicationTests { form.set("username", "user"); form.set("password", "user"); getCsrf(form, headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.POST, new HttpEntity<>(form, headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); String cookie = entity.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); - ResponseEntity<String> page = this.restTemplate.exchange( - entity.getHeaders().getLocation(), HttpMethod.GET, + ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); assertThat(page.getBody()).contains("Access denied"); @@ -105,35 +103,30 @@ public class SampleMethodSecurityApplicationTests { public void testManagementProtected() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); - ResponseEntity<String> entity = this.restTemplate.exchange("/actuator/beans", - HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/actuator/beans", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testManagementAuthorizedAccess() { - BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor( - "admin", "admin"); + BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor("admin", "admin"); this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor); try { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/actuator/beans", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/beans", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } finally { - this.restTemplate.getRestTemplate().getInterceptors() - .remove(basicAuthInterceptor); + this.restTemplate.getRestTemplate().getInterceptors().remove(basicAuthInterceptor); } } private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) { - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", - String.class); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); String cookie = page.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); String body = page.getBody(); - Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") - .matcher(body); + Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(body); matcher.find(); form.set("_csrf", matcher.group(1)); } diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java index 2412153026..a77d8f5d67 100644 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,11 +60,10 @@ public class SampleWebMustacheApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> responseEntity = this.restTemplate - .exchange("/does-not-exist", HttpMethod.GET, requestEntity, String.class); + ResponseEntity<String> responseEntity = this.restTemplate.exchange("/does-not-exist", HttpMethod.GET, + requestEntity, String.class); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - assertThat(responseEntity.getBody()) - .contains("Something went wrong: 404 Not Found"); + assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); } @Test @@ -72,8 +71,8 @@ public class SampleWebMustacheApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/serviceUnavailable", - HttpMethod.GET, requestEntity, String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/serviceUnavailable", HttpMethod.GET, requestEntity, + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); assertThat(entity.getBody()).contains("I'm a 503"); } @@ -83,8 +82,8 @@ public class SampleWebMustacheApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/bang", - HttpMethod.GET, requestEntity, String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/bang", HttpMethod.GET, requestEntity, + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getBody()).contains("I'm a 5xx"); } @@ -94,8 +93,8 @@ public class SampleWebMustacheApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/insufficientStorage", - HttpMethod.GET, requestEntity, String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/insufficientStorage", HttpMethod.GET, + requestEntity, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_STORAGE); assertThat(entity.getBody()).contains("I'm a 507"); } diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java index 1541d36373..2fb993ed28 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,9 +61,8 @@ public class SampleWebSecureCustomApplication implements WebMvcConfigurer { @Override protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest() - .fullyAuthenticated().and().formLogin().loginPage("/login") - .failureUrl("/login?error").permitAll().and().logout().permitAll(); + http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest().fullyAuthenticated().and() + .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and().logout().permitAll(); } } diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java index b7347dd8c4..eb9f18404e 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,19 +59,18 @@ public class SampleWebSecureCustomApplicationTests { public void testHome() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .endsWith(this.port + "/login"); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); } @Test public void testLoginPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("_csrf"); } @@ -84,18 +83,16 @@ public class SampleWebSecureCustomApplicationTests { MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); form.set("username", "user"); form.set("password", "password"); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.POST, new HttpEntity<>(form, headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .endsWith(this.port + "/"); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); } private HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", - String.class); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); String cookie = page.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); @@ -108,8 +105,7 @@ public class SampleWebSecureCustomApplicationTests { @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java index 65a1dc5ffa..97d8cd5ec9 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,9 +65,8 @@ public class SampleWebSecureJdbcApplication implements WebMvcConfigurer { @Override protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest() - .fullyAuthenticated().and().formLogin().loginPage("/login") - .failureUrl("/login?error").permitAll().and().logout().permitAll(); + http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest().fullyAuthenticated().and() + .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and().logout().permitAll(); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java index 6127b3b3e0..440dc701f0 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,19 +59,18 @@ public class SampleWebSecureJdbcApplicationTests { public void testHome() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .endsWith(this.port + "/login"); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); } @Test public void testLoginPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("_csrf"); } @@ -84,18 +83,16 @@ public class SampleWebSecureJdbcApplicationTests { MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); form.set("username", "user"); form.set("password", "user"); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.POST, new HttpEntity<>(form, headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .endsWith(this.port + "/"); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); } private HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", - String.class); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); String cookie = page.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); @@ -108,8 +105,7 @@ public class SampleWebSecureJdbcApplicationTests { @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java index 8cec5b7d12..941c922b8e 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,19 +59,18 @@ public class SampleSecureApplicationTests { public void testHome() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .endsWith(this.port + "/login"); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); } @Test public void testLoginPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("_csrf"); } @@ -84,18 +83,16 @@ public class SampleSecureApplicationTests { MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); form.set("username", "user"); form.set("password", "password"); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", - HttpMethod.POST, new HttpEntity<>(form, headers), String.class); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()) - .endsWith(this.port + "/"); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); } private HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", - String.class); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); String cookie = page.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); @@ -108,8 +105,7 @@ public class SampleSecureApplicationTests { @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java index ec8d40860c..1b8e31af41 100644 --- a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,12 +51,11 @@ public class SampleWebStaticApplicationTests { @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity( - "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate.getForEntity("/webjars/bootstrap/3.0.3/css/bootstrap.min.css", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); - assertThat(entity.getHeaders().getContentType()) - .isEqualTo(MediaType.valueOf("text/css")); + assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.valueOf("text/css")); } } diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java index 067feb5a85..bac99df9bb 100755 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,8 +58,7 @@ public class MessageController { } @PostMapping - public ModelAndView create(@Valid Message message, BindingResult result, - RedirectAttributes redirect) { + public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) { if (result.hasErrors()) { return new ModelAndView("messages/form", "formErrors", result.getAllErrors()); } diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java index 31610bad9c..813f1c3689 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,15 +68,13 @@ public class MessageControllerWebTests { @Test public void testCreate() throws Exception { - this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")) - .andExpect(status().isFound()) + this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound()) .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); } @Test public void testCreateValidation() throws Exception { - this.mockMvc.perform(post("/").param("text", "").param("summary", "")) - .andExpect(status().isOk()) + this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk()) .andExpect(content().string(containsString("is required"))); } @@ -100,8 +98,7 @@ public class MessageControllerWebTests { @Override public void describeTo(Description description) { - description.appendText("a string that matches regex: ") - .appendText(this.regex); + description.appendText("a string that matches regex: ").appendText(this.regex); } public static org.hamcrest.Matcher<java.lang.String> matches(String regex) { diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java index 562b250e11..d224af1791 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,8 +68,8 @@ public class SampleWebUiApplicationTests { @Test public void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); + ResponseEntity<String> entity = this.restTemplate + .getForEntity("http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); } diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java index a42266d67e..1b5062d6f6 100644 --- a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java +++ b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java @@ -23,10 +23,8 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class ExampleController { - @PostMapping(path = "/", - consumes = { MediaType.APPLICATION_JSON_VALUE, "!application/xml" }, - produces = MediaType.TEXT_PLAIN_VALUE, headers = "X-Custom=Foo", - params = "a!=alpha") + @PostMapping(path = "/", consumes = { MediaType.APPLICATION_JSON_VALUE, "!application/xml" }, + produces = MediaType.TEXT_PLAIN_VALUE, headers = "X-Custom=Foo", params = "a!=alpha") public String example() { return "Hello World"; } diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java index a991c4ada8..6ede9790bf 100644 --- a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,23 +41,21 @@ public class SampleWebFluxApplicationTests { @Test public void testWelcome() { - this.webClient.get().uri("/").accept(MediaType.TEXT_PLAIN).exchange() - .expectBody(String.class).isEqualTo("Hello World"); + this.webClient.get().uri("/").accept(MediaType.TEXT_PLAIN).exchange().expectBody(String.class) + .isEqualTo("Hello World"); } @Test public void testEcho() { - this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN) - .accept(MediaType.TEXT_PLAIN) - .body(Mono.just("Hello WebFlux!"), String.class).exchange() - .expectBody(String.class).isEqualTo("Hello WebFlux!"); + this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN) + .body(Mono.just("Hello WebFlux!"), String.class).exchange().expectBody(String.class) + .isEqualTo("Hello WebFlux!"); } @Test public void testActuatorStatus() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON) - .exchange().expectStatus().isOk().expectBody() - .json("{\"status\":\"UP\"}"); + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk() + .expectBody().json("{\"status\":\"UP\"}"); } } diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java index 1ebe83f207..e5be9211e4 100644 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java +++ b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,28 +48,21 @@ public class HolidayEndpoint { private HumanResourceService humanResourceService; public HolidayEndpoint(HumanResourceService humanResourceService) - throws JDOMException, XPathFactoryConfigurationException, - XPathExpressionException { + throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException { this.humanResourceService = humanResourceService; Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI); XPathFactory xPathFactory = XPathFactory.instance(); - this.startDateExpression = xPathFactory.compile("//hr:StartDate", - Filters.element(), null, namespace); - this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), - null, namespace); - this.nameExpression = xPathFactory.compile( - "concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, + this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace); + this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace); + this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, namespace); } @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest") - public void handleHolidayRequest(@RequestPayload Element holidayRequest) - throws Exception { + public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date startDate = dateFormat - .parse(this.startDateExpression.evaluateFirst(holidayRequest).getText()); - Date endDate = dateFormat - .parse(this.endDateExpression.evaluateFirst(holidayRequest).getText()); + Date startDate = dateFormat.parse(this.startDateExpression.evaluateFirst(holidayRequest).getText()); + Date endDate = dateFormat.parse(this.endDateExpression.evaluateFirst(holidayRequest).getText()); String name = this.nameExpression.evaluateFirst(holidayRequest); this.humanResourceService.bookHoliday(startDate, endDate, name); } diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java index 5a83f4f21c..624bba7ff6 100644 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java +++ b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,7 @@ public class StubHumanResourceService implements HumanResourceService { @Override public void bookHoliday(Date startDate, Date endDate, String name) { - this.logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate, - name); + this.logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate, name); } } diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java index 652817fa64..12d994297d 100644 --- a/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,19 +49,16 @@ public class SampleWsApplicationTests { @Before public void setUp() { - this.webServiceTemplate - .setDefaultUri("http://localhost:" + this.serverPort + "/services/"); + this.webServiceTemplate.setDefaultUri("http://localhost:" + this.serverPort + "/services/"); } @Test public void testSendingHolidayRequest() { final String request = "<hr:HolidayRequest xmlns:hr=\"https://company.example.com/hr/schemas\">" + " <hr:Holiday>" + " <hr:StartDate>2013-10-20</hr:StartDate>" - + " <hr:EndDate>2013-11-22</hr:EndDate>" + " </hr:Holiday>" - + " <hr:Employee>" + " <hr:Number>1</hr:Number>" - + " <hr:FirstName>John</hr:FirstName>" - + " <hr:LastName>Doe</hr:LastName>" + " </hr:Employee>" - + "</hr:HolidayRequest>"; + + " <hr:EndDate>2013-11-22</hr:EndDate>" + " </hr:Holiday>" + " <hr:Employee>" + + " <hr:Number>1</hr:Number>" + " <hr:FirstName>John</hr:FirstName>" + + " <hr:LastName>Doe</hr:LastName>" + " </hr:Employee>" + "</hr:HolidayRequest>"; StreamSource source = new StreamSource(new StringReader(request)); StreamResult result = new StreamResult(System.out); this.webServiceTemplate.sendSourceAndReceiveToResult(source, result); diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java index bc3ad3779a..39e2f51a04 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,8 +40,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter; @Configuration @EnableAutoConfiguration @EnableWebSocket -public class SampleJettyWebSocketsApplication extends SpringBootServletInitializer - implements WebSocketConfigurer { +public class SampleJettyWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java index 2d6ab32449..5f8be527b3 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ public class SimpleClientWebSocketHandler extends TextWebSocketHandler { private final AtomicReference<String> messagePayload; - public SimpleClientWebSocketHandler(GreetingService greetingService, - CountDownLatch latch, AtomicReference<String> message) { + public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, + AtomicReference<String> message) { this.greetingService = greetingService; this.latch = latch; this.messagePayload = message; @@ -50,8 +50,7 @@ public class SimpleClientWebSocketHandler extends TextWebSocketHandler { } @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); session.close(); this.messagePayload.set(message.getPayload()); diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java index 38609a73d0..7a24df974a 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,16 +44,14 @@ public class EchoWebSocketHandler extends TextWebSocketHandler { } @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String echoMessage = this.echoService.getMessage(message.getPayload()); logger.debug(echoMessage); session.sendMessage(new TextMessage(echoMessage)); } @Override - public void handleTransportError(WebSocketSession session, Throwable exception) - throws Exception { + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { session.close(CloseStatus.SERVER_ERROR); } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java index b0987832ef..857b3a5b14 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ public class ReverseWebSocketEndpoint { @OnMessage public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote() - .sendText("Reversed: " + new StringBuilder(message).reverse()); + session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java index ea8d837fcc..2d2bba68c2 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,8 +104,7 @@ public class Snake { private void handleCollisions(Collection<Snake> snakes) throws Exception { for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id - && snake.getHead().equals(this.head); + boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); boolean tailCollision = snake.getTail().contains(this.head); if (headCollision || tailCollision) { kill(); @@ -137,15 +136,12 @@ public class Snake { public String getLocationsJson() { synchronized (this.monitor) { StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), - Integer.valueOf(this.head.y))); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); for (Location location : this.tail) { sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), - Integer.valueOf(location.y))); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), - sb.toString()); + return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java index df0f215773..f0d0627b42 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,8 +69,7 @@ public final class SnakeTimer { public static void tick() throws Exception { StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { Snake snake = iterator.next(); snake.update(SnakeTimer.getSnakes()); sb.append(snake.getLocationsJson()); diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java index 0421c8c372..054a252d8a 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,7 @@ public final class SnakeUtils { float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); } public static Location getRandomLocation() { diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java index 3f97792b05..4023957bd4 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); } public static Location getRandomLocation() { @@ -68,22 +67,18 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { this.snake = new Snake(this.id, session); SnakeTimer.addSnake(this.snake); StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", - Integer.valueOf(snake.getId()), snake.getHexColor())); + sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); if (iterator.hasNext()) { sb.append(','); } } - SnakeTimer - .broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); + SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); } @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String payload = message.getPayload(); if ("west".equals(payload)) { this.snake.setDirection(Direction.WEST); @@ -100,11 +95,9 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { } @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) - throws Exception { + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast( - String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); + SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java index 3141227d4c..9cf815d1c2 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -45,8 +45,7 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SampleJettyWebSocketsApplication.class, - webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = SampleJettyWebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleWebSocketsApplicationTests { private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); @@ -56,30 +55,25 @@ public class SampleWebSocketsApplicationTests { @Test public void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/echo/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); } @Test public void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties( - "websocket.uri:ws://localhost:" + this.port + "/reverse") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); @@ -109,8 +103,7 @@ public class SampleWebSocketsApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; @@ -123,8 +116,7 @@ public class SampleWebSocketsApplicationTests { @Bean public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java index 50308d1a95..72b020f694 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java @@ -49,44 +49,36 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest( - classes = { SampleJettyWebSocketsApplication.class, - CustomContainerConfiguration.class }, +@SpringBootTest(classes = { SampleJettyWebSocketsApplication.class, CustomContainerConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT) public class CustomContainerWebSocketsApplicationTests { - private static Log logger = LogFactory - .getLog(CustomContainerWebSocketsApplicationTests.class); + private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); @LocalServerPort private int port; @Test public void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/ws/echo/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); } @Test public void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/ws/reverse") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); @@ -126,8 +118,7 @@ public class CustomContainerWebSocketsApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; @@ -140,8 +131,7 @@ public class CustomContainerWebSocketsApplicationTests { @Bean public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java index 75894228e4..e61e70ac77 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,8 +40,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter; @Configuration @EnableAutoConfiguration @EnableWebSocket -public class SampleTomcatWebSocketApplication extends SpringBootServletInitializer - implements WebSocketConfigurer { +public class SampleTomcatWebSocketApplication extends SpringBootServletInitializer implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java index 47630abf42..685c70924a 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ public class SimpleClientWebSocketHandler extends TextWebSocketHandler { private final AtomicReference<String> messagePayload; - public SimpleClientWebSocketHandler(GreetingService greetingService, - CountDownLatch latch, AtomicReference<String> message) { + public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, + AtomicReference<String> message) { this.greetingService = greetingService; this.latch = latch; this.messagePayload = message; @@ -50,8 +50,7 @@ public class SimpleClientWebSocketHandler extends TextWebSocketHandler { } @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); session.close(); this.messagePayload.set(message.getPayload()); diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java index f753e1442a..22eaf75381 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,16 +44,14 @@ public class EchoWebSocketHandler extends TextWebSocketHandler { } @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String echoMessage = this.echoService.getMessage(message.getPayload()); logger.debug(echoMessage); session.sendMessage(new TextMessage(echoMessage)); } @Override - public void handleTransportError(WebSocketSession session, Throwable exception) - throws Exception { + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { session.close(CloseStatus.SERVER_ERROR); } diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java index 094f421dd1..0d3e2245cc 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ public class ReverseWebSocketEndpoint { @OnMessage public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote() - .sendText("Reversed: " + new StringBuilder(message).reverse()); + session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java index 857679a58f..b576047e1e 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,8 +104,7 @@ public class Snake { private void handleCollisions(Collection<Snake> snakes) throws Exception { for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id - && snake.getHead().equals(this.head); + boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); boolean tailCollision = snake.getTail().contains(this.head); if (headCollision || tailCollision) { kill(); @@ -137,15 +136,12 @@ public class Snake { public String getLocationsJson() { synchronized (this.monitor) { StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), - Integer.valueOf(this.head.y))); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); for (Location location : this.tail) { sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), - Integer.valueOf(location.y))); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), - sb.toString()); + return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java index ede28f5db5..6e06614592 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,8 +69,7 @@ public final class SnakeTimer { public static void tick() throws Exception { StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { Snake snake = iterator.next(); snake.update(SnakeTimer.getSnakes()); sb.append(snake.getLocationsJson()); diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java index 3cd0c61d03..ff0e3764ef 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,7 @@ public final class SnakeUtils { float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); } public static Location getRandomLocation() { diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java index 84411f784a..c35a633eb6 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); } public static Location getRandomLocation() { @@ -68,22 +67,18 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { this.snake = new Snake(this.id, session); SnakeTimer.addSnake(this.snake); StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", - Integer.valueOf(snake.getId()), snake.getHexColor())); + sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); if (iterator.hasNext()) { sb.append(','); } } - SnakeTimer - .broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); + SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); } @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String payload = message.getPayload(); if ("west".equals(payload)) { this.snake.setDirection(Direction.WEST); @@ -100,11 +95,9 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { } @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) - throws Exception { + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast( - String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); + SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java index 121bd6b0bb..246e4b5949 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -45,8 +45,7 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SampleTomcatWebSocketApplication.class, - webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = SampleTomcatWebSocketApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleWebSocketsApplicationTests { private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); @@ -56,30 +55,25 @@ public class SampleWebSocketsApplicationTests { @Test public void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/echo/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); } @Test public void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties( - "websocket.uri:ws://localhost:" + this.port + "/reverse") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); @@ -109,8 +103,7 @@ public class SampleWebSocketsApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; @@ -123,8 +116,7 @@ public class SampleWebSocketsApplicationTests { @Bean public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java index 5fa9de394b..7a65e3864b 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java @@ -49,44 +49,36 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest( - classes = { SampleTomcatWebSocketApplication.class, - CustomContainerConfiguration.class }, +@SpringBootTest(classes = { SampleTomcatWebSocketApplication.class, CustomContainerConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT) public class CustomContainerWebSocketsApplicationTests { - private static Log logger = LogFactory - .getLog(CustomContainerWebSocketsApplicationTests.class); + private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); @LocalServerPort private int port; @Test public void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/ws/echo/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); } @Test public void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/ws/reverse") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); @@ -126,8 +118,7 @@ public class CustomContainerWebSocketsApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; @@ -140,8 +131,7 @@ public class CustomContainerWebSocketsApplicationTests { @Bean public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java index ee13acfd6b..f1ea97179e 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,15 +40,12 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter; @Configuration @EnableAutoConfiguration @EnableWebSocket -public class SampleUndertowWebSocketsApplication extends SpringBootServletInitializer - implements WebSocketConfigurer { +public class SampleUndertowWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").setAllowedOrigins("*") - .withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").setAllowedOrigins("*") - .withSockJS(); + registry.addHandler(echoWebSocketHandler(), "/echo").setAllowedOrigins("*").withSockJS(); + registry.addHandler(snakeWebSocketHandler(), "/snake").setAllowedOrigins("*").withSockJS(); } @Override diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java index 9f9b1dffa8..4ada967e84 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ public class SimpleClientWebSocketHandler extends TextWebSocketHandler { private final AtomicReference<String> messagePayload; - public SimpleClientWebSocketHandler(GreetingService greetingService, - CountDownLatch latch, AtomicReference<String> message) { + public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, + AtomicReference<String> message) { this.greetingService = greetingService; this.latch = latch; this.messagePayload = message; @@ -50,8 +50,7 @@ public class SimpleClientWebSocketHandler extends TextWebSocketHandler { } @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); session.close(); this.messagePayload.set(message.getPayload()); diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java index 466a3ee137..8fa9dd15a9 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,16 +44,14 @@ public class EchoWebSocketHandler extends TextWebSocketHandler { } @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String echoMessage = this.echoService.getMessage(message.getPayload()); logger.debug(echoMessage); session.sendMessage(new TextMessage(echoMessage)); } @Override - public void handleTransportError(WebSocketSession session, Throwable exception) - throws Exception { + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { session.close(CloseStatus.SERVER_ERROR); } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java index d114ab1f23..a5a9de3f07 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ public class ReverseWebSocketEndpoint { @OnMessage public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote() - .sendText("Reversed: " + new StringBuilder(message).reverse()); + session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java index bc5426e25e..8b7ea21b3e 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,8 +104,7 @@ public class Snake { private void handleCollisions(Collection<Snake> snakes) throws Exception { for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id - && snake.getHead().equals(this.head); + boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); boolean tailCollision = snake.getTail().contains(this.head); if (headCollision || tailCollision) { kill(); @@ -137,15 +136,12 @@ public class Snake { public String getLocationsJson() { synchronized (this.monitor) { StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), - Integer.valueOf(this.head.y))); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); for (Location location : this.tail) { sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), - Integer.valueOf(location.y))); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), - sb.toString()); + return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java index 9999cec193..71672f7c41 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,8 +69,7 @@ public final class SnakeTimer { public static void tick() throws Exception { StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { Snake snake = iterator.next(); snake.update(SnakeTimer.getSnakes()); sb.append(snake.getLocationsJson()); diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java index 2371246877..a41587c76c 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,7 @@ public final class SnakeUtils { float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); } public static Location getRandomLocation() { diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java index ee77bfa090..aefc5f2eab 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000) - .substring(1); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); } public static Location getRandomLocation() { @@ -68,22 +67,18 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { this.snake = new Snake(this.id, session); SnakeTimer.addSnake(this.snake); StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator - .hasNext();) { + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", - Integer.valueOf(snake.getId()), snake.getHexColor())); + sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); if (iterator.hasNext()) { sb.append(','); } } - SnakeTimer - .broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); + SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); } @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) - throws Exception { + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String payload = message.getPayload(); if ("west".equals(payload)) { this.snake.setDirection(Direction.WEST); @@ -100,11 +95,9 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler { } @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) - throws Exception { + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast( - String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); + SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java index 6c4c2b2627..78a25c5464 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -45,8 +45,7 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SampleUndertowWebSocketsApplication.class, - webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = SampleUndertowWebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleWebSocketsApplicationTests { private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); @@ -56,30 +55,25 @@ public class SampleWebSocketsApplicationTests { @Test public void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/echo/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); } @Test public void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties( - "websocket.uri:ws://localhost:" + this.port + "/reverse") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); @@ -109,8 +103,7 @@ public class SampleWebSocketsApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; @@ -123,8 +116,7 @@ public class SampleWebSocketsApplicationTests { @Bean public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java index 905fc52e64..fcacb41056 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java @@ -49,44 +49,36 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest( - classes = { SampleUndertowWebSocketsApplication.class, - CustomContainerConfiguration.class }, +@SpringBootTest(classes = { SampleUndertowWebSocketsApplication.class, CustomContainerConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT) public class CustomContainerWebSocketsApplicationTests { - private static Log logger = LogFactory - .getLog(CustomContainerWebSocketsApplicationTests.class); + private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); @LocalServerPort private int port; @Test public void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/ws/echo/websocket") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()) - .isEqualTo("Did you say \"Hello world!\"?"); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); } @Test public void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder( - ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port - + "/ws/reverse") + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") .run("--spring.main.web-application-type=none"); long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context - .getBean(ClientConfiguration.class).messagePayload; + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; context.close(); assertThat(count).isEqualTo(0); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); @@ -126,8 +118,7 @@ public class CustomContainerWebSocketsApplicationTests { @Bean public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), - handler(), this.webSocketUri); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); manager.setAutoStartup(true); return manager; @@ -140,8 +131,7 @@ public class CustomContainerWebSocketsApplicationTests { @Bean public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, - this.messagePayload); + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); } @Bean