Upgrade to spring-javaformat 0.0.11

This commit is contained in:
Andy Wilkinson
2019-06-07 09:44:58 +01:00
parent d548c5ed31
commit 8f1be4cded
1940 changed files with 16814 additions and 28498 deletions

View File

@@ -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) {

View File

@@ -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());

View File

@@ -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);
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());

View File

@@ -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() {

View File

@@ -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)));
}
}

View File

@@ -46,8 +46,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)
@DirtiesContext
public class SampleWebSocketsApplicationTests {
@@ -58,30 +57,25 @@ public class SampleWebSocketsApplicationTests {
@Test
public void echoEndpoint() throws Exception {
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_environment=false");
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() throws Exception {
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_environment=false");
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");
@@ -111,8 +105,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;
@@ -125,8 +118,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

View File

@@ -50,44 +50,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.DEFINED_PORT)
@DirtiesContext
public class CustomContainerWebSocketsApplicationTests {
private static Log logger = LogFactory
.getLog(CustomContainerWebSocketsApplicationTests.class);
private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class);
private static int PORT = SocketUtils.findAvailableTcpPort();
@Test
public void echoEndpoint() throws Exception {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + PORT
+ "/ws/echo/websocket")
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + PORT + "/ws/echo/websocket")
.run("--spring.main.web_environment=false");
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() throws Exception {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class)
.properties(
"websocket.uri:ws://localhost:" + PORT + "/ws/reverse")
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + PORT + "/ws/reverse")
.run("--spring.main.web_environment=false");
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");
@@ -127,8 +119,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;
@@ -141,8 +132,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