Apply source formatting to samples

This commit is contained in:
Phillip Webb
2013-10-08 20:25:10 -07:00
parent efe102bd51
commit 1a9ce42da9
16 changed files with 389 additions and 329 deletions

View File

@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.samples.websocket.echo;
import static org.junit.Assert.assertEquals;
package org.springframework.boot.samples.websocket.echo;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@@ -40,6 +39,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.endpoint.StandardWebSocketClient;
import static org.junit.Assert.assertEquals;
public class SampleWebSocketsApplicationTests {
private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class);
@@ -55,7 +56,7 @@ public class SampleWebSocketsApplicationTests {
new Callable<ConfigurableApplicationContext>() {
@Override
public ConfigurableApplicationContext call() throws Exception {
return (ConfigurableApplicationContext) SpringApplication
return SpringApplication
.run(SampleWebSocketsApplication.class);
}
});
@@ -71,7 +72,8 @@ public class SampleWebSocketsApplicationTests {
@Test
public void runAndWait() throws Exception {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) SpringApplication.run(ClientConfiguration.class, "--spring.main.web_environment=false");
ConfigurableApplicationContext context = SpringApplication.run(
ClientConfiguration.class, "--spring.main.web_environment=false");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
context.close();
assertEquals(0, count);
@@ -84,15 +86,16 @@ public class SampleWebSocketsApplicationTests {
@Override
public void run(String... args) throws Exception {
logger.info("Waiting for response: latch=" + latch.getCount());
latch.await(10, TimeUnit.SECONDS);
logger.info("Got response: latch=" + latch.getCount());
logger.info("Waiting for response: latch=" + this.latch.getCount());
this.latch.await(10, TimeUnit.SECONDS);
logger.info("Got response: latch=" + this.latch.getCount());
}
@Bean
public WebSocketConnectionManager wsConnectionManager() {
WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), WS_URI);
WebSocketConnectionManager manager = new WebSocketConnectionManager(client(),
handler(), WS_URI);
manager.setAutoStartup(true);
return manager;
@@ -105,7 +108,7 @@ public class SampleWebSocketsApplicationTests {
@Bean
public SimpleClientWebSocketHandler handler() {
return new SimpleClientWebSocketHandler(greetingService(), latch);
return new SimpleClientWebSocketHandler(greetingService(), this.latch);
}
@Bean

View File

@@ -1,9 +1,25 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.samples.websocket.snake;
import org.junit.Test;
import java.io.IOException;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
@@ -12,13 +28,13 @@ import static org.mockito.Mockito.mock;
public class SnakeTimerTests {
@Test
public void removeDysfunctionalSnakes() throws Exception {
Snake snake = mock(Snake.class);
doThrow(new IOException()).when(snake).sendMessage(anyString());
SnakeTimer.addSnake(snake);
@Test
public void removeDysfunctionalSnakes() throws Exception {
Snake snake = mock(Snake.class);
doThrow(new IOException()).when(snake).sendMessage(anyString());
SnakeTimer.addSnake(snake);
SnakeTimer.broadcast("");
assertThat(SnakeTimer.getSnakes().size(), is(0));
}
SnakeTimer.broadcast("");
assertThat(SnakeTimer.getSnakes().size(), is(0));
}
}