Unify method visibility of private classes

Apply checkstyle rule to ensure that private and package private
classes do not have unnecessary public methods. Test classes have
also been unified as much as possible to use default scoped
inner-classes.

Closes gh-7316
This commit is contained in:
Phillip Webb
2019-07-01 12:29:51 -07:00
parent 0a02a3a19c
commit a66c4d3096
910 changed files with 3754 additions and 3945 deletions

View File

@@ -68,18 +68,18 @@ public class LocalDevToolsAutoConfiguration {
@Bean
@RestartScope
@ConditionalOnMissingBean
public LiveReloadServer liveReloadServer(DevToolsProperties properties) {
LiveReloadServer liveReloadServer(DevToolsProperties properties) {
return new LiveReloadServer(properties.getLivereload().getPort(),
Restarter.getInstance().getThreadFactory());
}
@Bean
public OptionalLiveReloadServer optionalLiveReloadServer(LiveReloadServer liveReloadServer) {
OptionalLiveReloadServer optionalLiveReloadServer(LiveReloadServer liveReloadServer) {
return new OptionalLiveReloadServer(liveReloadServer);
}
@Bean
public LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadServer liveReloadServer) {
LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadServer liveReloadServer) {
return new LiveReloadServerEventListener(liveReloadServer);
}
@@ -100,7 +100,7 @@ public class LocalDevToolsAutoConfiguration {
}
@Bean
public ApplicationListener<ClassPathChangedEvent> restartingClassPathChangedEventListener(
ApplicationListener<ClassPathChangedEvent> restartingClassPathChangedEventListener(
FileSystemWatcherFactory fileSystemWatcherFactory) {
return (event) -> {
if (event.isRestartRequired()) {
@@ -111,7 +111,7 @@ public class LocalDevToolsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public ClassPathFileSystemWatcher classPathFileSystemWatcher(FileSystemWatcherFactory fileSystemWatcherFactory,
ClassPathFileSystemWatcher classPathFileSystemWatcher(FileSystemWatcherFactory fileSystemWatcherFactory,
ClassPathRestartStrategy classPathRestartStrategy) {
URL[] urls = Restarter.getInstance().getInitialUrls();
ClassPathFileSystemWatcher watcher = new ClassPathFileSystemWatcher(fileSystemWatcherFactory,
@@ -122,19 +122,19 @@ public class LocalDevToolsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public ClassPathRestartStrategy classPathRestartStrategy() {
ClassPathRestartStrategy classPathRestartStrategy() {
return new PatternClassPathRestartStrategy(this.properties.getRestart().getAllExclude());
}
@Bean
public FileSystemWatcherFactory fileSystemWatcherFactory() {
FileSystemWatcherFactory fileSystemWatcherFactory() {
return this::newFileSystemWatcher;
}
@Bean
@ConditionalOnProperty(prefix = "spring.devtools.restart", name = "log-condition-evaluation-delta",
matchIfMissing = true)
public ConditionEvaluationDeltaLoggingListener conditionEvaluationDeltaLoggingListener() {
ConditionEvaluationDeltaLoggingListener conditionEvaluationDeltaLoggingListener() {
return new ConditionEvaluationDeltaLoggingListener();
}

View File

@@ -102,19 +102,19 @@ public class RemoteDevToolsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public SourceFolderUrlFilter remoteRestartSourceFolderUrlFilter() {
SourceFolderUrlFilter remoteRestartSourceFolderUrlFilter() {
return new DefaultSourceFolderUrlFilter();
}
@Bean
@ConditionalOnMissingBean
public HttpRestartServer remoteRestartHttpRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter) {
HttpRestartServer remoteRestartHttpRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter) {
return new HttpRestartServer(sourceFolderUrlFilter);
}
@Bean
@ConditionalOnMissingBean(name = "remoteRestartHandlerMapper")
public UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server, ServerProperties serverProperties,
UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server, ServerProperties serverProperties,
DevToolsProperties properties) {
Servlet servlet = serverProperties.getServlet();
RemoteDevToolsProperties remote = properties.getRemote();

View File

@@ -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.
@@ -44,7 +44,7 @@ class FileSnapshot {
this.lastModified = file.lastModified();
}
public File getFile() {
File getFile() {
return this.file;
}

View File

@@ -73,7 +73,7 @@ class FolderSnapshot {
}
}
public ChangedFiles getChangedFiles(FolderSnapshot snapshot, FileFilter triggerFilter) {
ChangedFiles getChangedFiles(FolderSnapshot snapshot, FileFilter triggerFilter) {
Assert.notNull(snapshot, "Snapshot must not be null");
File folder = this.folder;
Assert.isTrue(snapshot.folder.equals(folder), () -> "Snapshot source folder must be '" + folder + "'");
@@ -124,7 +124,7 @@ class FolderSnapshot {
return super.equals(obj);
}
public boolean equals(FolderSnapshot other, FileFilter filter) {
boolean equals(FolderSnapshot other, FileFilter filter) {
if (this.folder.equals(other.folder)) {
Set<FileSnapshot> ourFiles = filter(this.files, filter);
Set<FileSnapshot> otherFiles = filter(other.files, filter);
@@ -157,7 +157,7 @@ class FolderSnapshot {
* Return the source folder of this snapshot.
* @return the source folder
*/
public File getFolder() {
File getFolder() {
return this.folder;
}

View File

@@ -75,7 +75,7 @@ class Connection {
* Run the connection.
* @throws Exception in case of errors
*/
public void run() throws Exception {
void run() throws Exception {
if (this.header.contains("Upgrade: websocket") && this.header.contains("Sec-WebSocket-Version: 13")) {
runWebSocket();
}
@@ -126,7 +126,7 @@ class Connection {
* Trigger livereload for the client using this connection.
* @throws IOException in case of I/O errors
*/
public void triggerReload() throws IOException {
void triggerReload() throws IOException {
if (this.webSocket) {
logger.debug("Triggering LiveReload");
writeWebSocketFrame(new Frame("{\"command\":\"reload\",\"path\":\"/\"}"));
@@ -152,7 +152,7 @@ class Connection {
* Close the connection.
* @throws IOException in case of I/O errors
*/
public void close() throws IOException {
void close() throws IOException {
this.running = false;
this.socket.close();
}

View File

@@ -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,7 +42,7 @@ class ConnectionInputStream extends FilterInputStream {
* @return the HTTP header
* @throws IOException in case of I/O errors
*/
public String readHeader() throws IOException {
String readHeader() throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
StringBuilder content = new StringBuilder(BUFFER_SIZE);
while (content.indexOf(HEADER_END) == -1) {
@@ -60,7 +60,7 @@ class ConnectionInputStream extends FilterInputStream {
* @param length the amount of data to read
* @throws IOException in case of I/O errors
*/
public void readFully(byte[] buffer, int offset, int length) throws IOException {
void readFully(byte[] buffer, int offset, int length) throws IOException {
while (length > 0) {
int amountRead = checkedRead(buffer, offset, length);
offset += amountRead;
@@ -74,7 +74,7 @@ class ConnectionInputStream extends FilterInputStream {
* @return the content
* @throws IOException in case of I/O errors
*/
public int checkedRead() throws IOException {
int checkedRead() throws IOException {
int b = read();
if (b == -1) {
throw new IOException("End of stream");
@@ -91,7 +91,7 @@ class ConnectionInputStream extends FilterInputStream {
* @return the amount of data read
* @throws IOException in case of I/O errors
*/
public int checkedRead(byte[] buffer, int offset, int length) throws IOException {
int checkedRead(byte[] buffer, int offset, int length) throws IOException {
int amountRead = read(buffer, offset, length);
if (amountRead == -1) {
throw new IOException("End of stream");

View File

@@ -39,7 +39,7 @@ class ConnectionOutputStream extends FilterOutputStream {
this.out.write(b, off, len);
}
public void writeHttp(InputStream content, String contentType) throws IOException {
void writeHttp(InputStream content, String contentType) throws IOException {
byte[] bytes = FileCopyUtils.copyToByteArray(content);
writeHeaders("HTTP/1.1 200 OK", "Content-Type: " + contentType, "Content-Length: " + bytes.length,
"Connection: close");
@@ -47,7 +47,7 @@ class ConnectionOutputStream extends FilterOutputStream {
flush();
}
public void writeHeaders(String... headers) throws IOException {
void writeHeaders(String... headers) throws IOException {
StringBuilder response = new StringBuilder();
for (String header : headers) {
response.append(header).append("\r\n");

View File

@@ -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.
@@ -56,11 +56,11 @@ class Frame {
this.payload = payload;
}
public Type getType() {
Type getType() {
return this.type;
}
public byte[] getPayload() {
byte[] getPayload() {
return this.payload;
}
@@ -69,7 +69,7 @@ class Frame {
return new String(this.payload);
}
public void write(OutputStream outputStream) throws IOException {
void write(OutputStream outputStream) throws IOException {
outputStream.write(0x80 | this.type.code);
if (this.payload.length < 126) {
outputStream.write(0x00 | (this.payload.length & 0x7F));
@@ -83,7 +83,7 @@ class Frame {
outputStream.flush();
}
public static Frame read(ConnectionInputStream inputStream) throws IOException {
static Frame read(ConnectionInputStream inputStream) throws IOException {
int firstByte = inputStream.checkedRead();
Assert.state((firstByte & 0x80) != 0, "Fragmented frames are not supported");
int maskAndLength = inputStream.checkedRead();
@@ -110,7 +110,7 @@ class Frame {
/**
* Frame types.
*/
public enum Type {
enum Type {
/**
* Continuation frame.
@@ -148,7 +148,7 @@ class Frame {
this.code = code;
}
public static Type forCode(int code) {
static Type forCode(int code) {
for (Type type : values()) {
if (type.code == code) {
return type;

View File

@@ -148,13 +148,13 @@ public class RemoteClientConfiguration implements InitializingBean {
@Bean
@RestartScope
@ConditionalOnMissingBean
public LiveReloadServer liveReloadServer() {
LiveReloadServer liveReloadServer() {
return new LiveReloadServer(this.properties.getLivereload().getPort(),
Restarter.getInstance().getThreadFactory());
}
@Bean
public ApplicationListener<ClassPathChangedEvent> liveReloadTriggeringClassPathChangedEventListener(
ApplicationListener<ClassPathChangedEvent> liveReloadTriggeringClassPathChangedEventListener(
OptionalLiveReloadServer optionalLiveReloadServer) {
return (event) -> {
String url = this.remoteUrl + this.properties.getRemote().getContextPath();
@@ -164,7 +164,7 @@ public class RemoteClientConfiguration implements InitializingBean {
}
@Bean
public OptionalLiveReloadServer optionalLiveReloadServer() {
OptionalLiveReloadServer optionalLiveReloadServer() {
return new OptionalLiveReloadServer(this.liveReloadServer);
}
@@ -188,7 +188,7 @@ public class RemoteClientConfiguration implements InitializingBean {
private String remoteUrl;
@Bean
public ClassPathFileSystemWatcher classPathFileSystemWatcher(FileSystemWatcherFactory fileSystemWatcherFactory,
ClassPathFileSystemWatcher classPathFileSystemWatcher(FileSystemWatcherFactory fileSystemWatcherFactory,
ClassPathRestartStrategy classPathRestartStrategy) {
DefaultRestartInitializer restartInitializer = new DefaultRestartInitializer();
URL[] urls = restartInitializer.getInitialUrls(Thread.currentThread());
@@ -199,7 +199,7 @@ public class RemoteClientConfiguration implements InitializingBean {
}
@Bean
public FileSystemWatcherFactory getFileSystemWatcherFactory() {
FileSystemWatcherFactory getFileSystemWatcherFactory() {
return this::newFileSystemWatcher;
}
@@ -215,12 +215,12 @@ public class RemoteClientConfiguration implements InitializingBean {
}
@Bean
public ClassPathRestartStrategy classPathRestartStrategy() {
ClassPathRestartStrategy classPathRestartStrategy() {
return new PatternClassPathRestartStrategy(this.properties.getRestart().getAllExclude());
}
@Bean
public ClassPathChangeUploader classPathChangeUploader(ClientHttpRequestFactory requestFactory) {
ClassPathChangeUploader classPathChangeUploader(ClientHttpRequestFactory requestFactory) {
String url = this.remoteUrl + this.properties.getRemote().getContextPath() + "/restart";
return new ClassPathChangeUploader(url, requestFactory);
}

View File

@@ -73,15 +73,15 @@ final class ChangeableUrls implements Iterable<URL> {
return this.urls.iterator();
}
public int size() {
int size() {
return this.urls.size();
}
public URL[] toArray() {
URL[] toArray() {
return this.urls.toArray(new URL[0]);
}
public List<URL> toList() {
List<URL> toList() {
return Collections.unmodifiableList(this.urls);
}
@@ -90,7 +90,7 @@ final class ChangeableUrls implements Iterable<URL> {
return this.urls.toString();
}
public static ChangeableUrls fromClassLoader(ClassLoader classLoader) {
static ChangeableUrls fromClassLoader(ClassLoader classLoader) {
List<URL> urls = new ArrayList<>();
for (URL url : urlsFromClassLoader(classLoader)) {
urls.add(url);
@@ -171,11 +171,11 @@ final class ChangeableUrls implements Iterable<URL> {
return urls;
}
public static ChangeableUrls fromUrls(Collection<URL> urls) {
static ChangeableUrls fromUrls(Collection<URL> urls) {
return fromUrls(new ArrayList<>(urls).toArray(new URL[urls.size()]));
}
public static ChangeableUrls fromUrls(URL... urls) {
static ChangeableUrls fromUrls(URL... urls) {
return new ChangeableUrls(urls);
}

View File

@@ -195,7 +195,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
*/
private static class ResourcePatternResolverFactory {
public ResourcePatternResolver getResourcePatternResolver(ApplicationContext applicationContext,
ResourcePatternResolver getResourcePatternResolver(ApplicationContext applicationContext,
ResourceLoader resourceLoader) {
if (resourceLoader == null) {
resourceLoader = new DefaultResourceLoader();

View File

@@ -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.
@@ -69,7 +69,7 @@ class MainMethod {
* Returns the actual main method.
* @return the main method
*/
public Method getMethod() {
Method getMethod() {
return this.method;
}
@@ -77,7 +77,7 @@ class MainMethod {
* Return the name of the declaring class.
* @return the declaring class name
*/
public String getDeclaringClassName() {
String getDeclaringClassName() {
return this.method.getDeclaringClass().getName();
}

View File

@@ -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.
@@ -54,7 +54,7 @@ class RestartLauncher extends Thread {
}
}
public Throwable getError() {
Throwable getError() {
return this.error;
}

View File

@@ -600,13 +600,13 @@ public class Restarter {
setDaemon(false);
}
public void call(Callable<?> callable) {
void call(Callable<?> callable) {
this.callable = callable;
start();
}
@SuppressWarnings("unchecked")
public <V> V callAndWait(Callable<V> callable) {
<V> V callAndWait(Callable<V> callable) {
this.callable = callable;
start();
try {

View File

@@ -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.
@@ -78,7 +78,7 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
System.exit(0);
}
public static void setup(Thread thread) {
static void setup(Thread thread) {
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
if (!(handler instanceof SilentExitExceptionHandler)) {
handler = new SilentExitExceptionHandler(handler);
@@ -86,7 +86,7 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
}
}
public static void exitCurrentThread() {
static void exitCurrentThread() {
throw new SilentExitException();
}

View File

@@ -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.
@@ -31,23 +31,23 @@ class TunnelClientListeners {
private final List<TunnelClientListener> listeners = new CopyOnWriteArrayList<>();
public void addListener(TunnelClientListener listener) {
void addListener(TunnelClientListener listener) {
Assert.notNull(listener, "Listener must not be null");
this.listeners.add(listener);
}
public void removeListener(TunnelClientListener listener) {
void removeListener(TunnelClientListener listener) {
Assert.notNull(listener, "Listener must not be null");
this.listeners.remove(listener);
}
public void fireOpenEvent(SocketChannel socket) {
void fireOpenEvent(SocketChannel socket) {
for (TunnelClientListener listener : this.listeners) {
listener.onOpen(socket);
}
}
public void fireCloseEvent(SocketChannel socket) {
void fireCloseEvent(SocketChannel socket) {
for (TunnelClientListener listener : this.listeners) {
listener.onClose(socket);
}

View File

@@ -127,7 +127,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
static class SingleDataSourceConfiguration {
@Bean
public DataSource dataSource() {
DataSource dataSource() {
return mock(DataSource.class);
}
@@ -137,12 +137,12 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
static class MultipleDataSourcesConfiguration {
@Bean
public DataSource dataSourceOne() {
DataSource dataSourceOne() {
return mock(DataSource.class);
}
@Bean
public DataSource dataSourceTwo() {
DataSource dataSourceTwo() {
return mock(DataSource.class);
}
@@ -152,13 +152,13 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
static class DataSourceSpyConfiguration {
@Bean
public DataSourceSpyBeanPostProcessor dataSourceSpyBeanPostProcessor() {
DataSourceSpyBeanPostProcessor dataSourceSpyBeanPostProcessor() {
return new DataSourceSpyBeanPostProcessor();
}
}
private static class DataSourceSpyBeanPostProcessor implements BeanPostProcessor {
static class DataSourceSpyBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

View File

@@ -268,17 +268,17 @@ class LocalDevToolsAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
@Import({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
ThymeleafAutoConfiguration.class })
public static class Config {
static class Config {
}
@Configuration(proxyBeanMethods = false)
@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
ThymeleafAutoConfiguration.class })
public static class ConfigWithMockLiveReload {
static class ConfigWithMockLiveReload {
@Bean
public LiveReloadServer liveReloadServer() {
LiveReloadServer liveReloadServer() {
return mock(LiveReloadServer.class);
}
@@ -287,15 +287,15 @@ class LocalDevToolsAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
@Import({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
ResourceProperties.class })
public static class WebResourcesConfig {
static class WebResourcesConfig {
}
@Configuration(proxyBeanMethods = false)
public static class SessionRedisTemplateConfig {
static class SessionRedisTemplateConfig {
@Bean
public RedisTemplate<Object, Object> sessionRedisTemplate() {
RedisTemplate<Object, Object> sessionRedisTemplate() {
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(mock(RedisConnectionFactory.class));
return redisTemplate;

View File

@@ -66,7 +66,7 @@ class OnEnabledDevToolsConditionTests {
@Bean
@Conditional(OnEnabledDevToolsCondition.class)
public String test() {
String test() {
return "hello";
}

View File

@@ -199,7 +199,7 @@ class RemoteDevToolsAutoConfigurationTests {
static class Config {
@Bean
public HttpRestartServer remoteRestartHttpRestartServer() {
HttpRestartServer remoteRestartHttpRestartServer() {
SourceFolderUrlFilter sourceFolderUrlFilter = mock(SourceFolderUrlFilter.class);
return new MockHttpRestartServer(sourceFolderUrlFilter);
}

View File

@@ -86,7 +86,7 @@ class ClassPathFileSystemWatcherTests {
}
@Configuration(proxyBeanMethods = false)
public static class Config {
static class Config {
public final Environment environment;
@@ -95,25 +95,25 @@ class ClassPathFileSystemWatcherTests {
}
@Bean
public ClassPathFileSystemWatcher watcher(ClassPathRestartStrategy restartStrategy) {
ClassPathFileSystemWatcher watcher(ClassPathRestartStrategy restartStrategy) {
FileSystemWatcher watcher = new FileSystemWatcher(false, Duration.ofMillis(100), Duration.ofMillis(10));
URL[] urls = this.environment.getProperty("urls", URL[].class);
return new ClassPathFileSystemWatcher(new MockFileSystemWatcherFactory(watcher), restartStrategy, urls);
}
@Bean
public ClassPathRestartStrategy restartStrategy() {
ClassPathRestartStrategy restartStrategy() {
return (file) -> false;
}
@Bean
public Listener listener() {
Listener listener() {
return new Listener();
}
}
public static class Listener implements ApplicationListener<ClassPathChangedEvent> {
static class Listener implements ApplicationListener<ClassPathChangedEvent> {
private List<ClassPathChangedEvent> events = new ArrayList<>();
@@ -122,13 +122,13 @@ class ClassPathFileSystemWatcherTests {
this.events.add(event);
}
public List<ClassPathChangedEvent> getEvents() {
List<ClassPathChangedEvent> getEvents() {
return this.events;
}
}
private static class MockFileSystemWatcherFactory implements FileSystemWatcherFactory {
static class MockFileSystemWatcherFactory implements FileSystemWatcherFactory {
private final FileSystemWatcher watcher;

View File

@@ -138,7 +138,7 @@ class DevToolPropertiesIntegrationTests {
@Bean
@ConditionalOnProperty("spring.h2.console.enabled")
public MyBean myBean() {
MyBean myBean() {
return new MyBean();
}

View File

@@ -95,22 +95,22 @@ class HttpTunnelIntegrationTests {
static class ServerConfiguration {
@Bean
public ServletWebServerFactory container() {
ServletWebServerFactory container() {
return new TomcatServletWebServerFactory(0);
}
@Bean
public DispatcherServlet dispatcherServlet() {
DispatcherServlet dispatcherServlet() {
return new DispatcherServlet();
}
@Bean
public MyController myController() {
MyController myController() {
return new MyController();
}
@Bean
public DispatcherFilter filter(AnnotationConfigServletWebServerApplicationContext context) {
DispatcherFilter filter(AnnotationConfigServletWebServerApplicationContext context) {
TargetServerConnection connection = new SocketTargetServerConnection(
() -> context.getWebServer().getPort());
HttpTunnelServer server = new HttpTunnelServer(connection);
@@ -126,7 +126,7 @@ class HttpTunnelIntegrationTests {
static class TunnelConfiguration {
@Bean
public TunnelClient tunnelClient(@Value("${server.port}") int serverPort) {
TunnelClient tunnelClient(@Value("${server.port}") int serverPort) {
String url = "http://localhost:" + serverPort + "/httptunnel";
TunnelConnection connection = new HttpTunnelConnection(url, new SimpleClientHttpRequestFactory());
return new TestTunnelClient(0, connection);
@@ -154,7 +154,7 @@ class HttpTunnelIntegrationTests {
static class MyController {
@RequestMapping("/hello")
public String hello() {
String hello() {
return "Hello World";
}

View File

@@ -71,7 +71,7 @@ class ConnectionInputStreamTests {
.withMessageContaining("End of stream");
}
private static class LimitedInputStream extends FilterInputStream {
static class LimitedInputStream extends FilterInputStream {
private final int max;

View File

@@ -129,29 +129,10 @@ class LiveReloadServerTests {
return handler;
}
/**
* Useful main method for manual testing against a real browser.
* @param args main args
* @throws IOException in case of I/O errors
*/
public static void main(String[] args) throws IOException {
LiveReloadServer server = new LiveReloadServer();
server.start();
while (true) {
try {
Thread.sleep(1000);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
server.triggerReload();
}
}
/**
* {@link LiveReloadServer} with additional monitoring.
*/
private static class MonitoredLiveReloadServer extends LiveReloadServer {
static class MonitoredLiveReloadServer extends LiveReloadServer {
private final List<ConnectionClosedException> closedExceptions = new ArrayList<>();
@@ -167,7 +148,7 @@ class LiveReloadServerTests {
return new MonitoredConnection(socket, inputStream, outputStream);
}
public List<ConnectionClosedException> getClosedExceptions() {
List<ConnectionClosedException> getClosedExceptions() {
synchronized (this.monitor) {
return new ArrayList<>(this.closedExceptions);
}
@@ -197,7 +178,7 @@ class LiveReloadServerTests {
}
private static class LiveReloadWebSocketHandler extends TextWebSocketHandler {
static class LiveReloadWebSocketHandler extends TextWebSocketHandler {
private WebSocketSession session;
@@ -216,7 +197,7 @@ class LiveReloadServerTests {
this.helloLatch.countDown();
}
public void awaitHello() throws InterruptedException {
void awaitHello() throws InterruptedException {
this.helloLatch.await(1, TimeUnit.MINUTES);
Thread.sleep(200);
}
@@ -239,23 +220,23 @@ class LiveReloadServerTests {
this.closeStatus = status;
}
public void sendMessage(WebSocketMessage<?> message) throws IOException {
void sendMessage(WebSocketMessage<?> message) throws IOException {
this.session.sendMessage(message);
}
public void close() throws IOException {
void close() throws IOException {
this.session.close();
}
public List<String> getMessages() {
List<String> getMessages() {
return this.messages;
}
public int getPongCount() {
int getPongCount() {
return this.pongCount;
}
public CloseStatus getCloseStatus() {
CloseStatus getCloseStatus() {
return this.closeStatus;
}

View File

@@ -155,16 +155,16 @@ class RemoteClientConfigurationTests {
static class Config {
@Bean
public TomcatServletWebServerFactory tomcat() {
TomcatServletWebServerFactory tomcat() {
return new TomcatServletWebServerFactory(0);
}
@Bean
public DispatcherFilter dispatcherFilter() throws IOException {
DispatcherFilter dispatcherFilter() throws IOException {
return new DispatcherFilter(dispatcher());
}
public Dispatcher dispatcher() throws IOException {
Dispatcher dispatcher() throws IOException {
Dispatcher dispatcher = mock(Dispatcher.class);
ServerHttpRequest anyRequest = any(ServerHttpRequest.class);
ServerHttpResponse anyResponse = any(ServerHttpResponse.class);
@@ -178,7 +178,7 @@ class RemoteClientConfigurationTests {
static class ClientConfig {
@Bean
public LiveReloadServer liveReloadServer() {
LiveReloadServer liveReloadServer() {
return mock(LiveReloadServer.class);
}

View File

@@ -97,7 +97,7 @@ class DefaultRestartInitializerTests {
assertThat(initializer.getInitialUrls(thread)).isEqualTo(null);
}
private static class MockAppClassLoader extends ClassLoader {
static class MockAppClassLoader extends ClassLoader {
MockAppClassLoader(ClassLoader parent) {
super(parent);
@@ -105,7 +105,7 @@ class DefaultRestartInitializerTests {
}
private static class MockLauncherClassLoader extends ClassLoader {
static class MockLauncherClassLoader extends ClassLoader {
MockLauncherClassLoader(ClassLoader parent) {
super(parent);

View File

@@ -68,7 +68,7 @@ class MainMethodTests {
.withMessageContaining("Unable to find main method");
}
private static class TestThread extends Thread {
static class TestThread extends Thread {
private final Runnable runnable;
@@ -80,7 +80,7 @@ class MainMethodTests {
this.runnable = runnable;
}
public MainMethod test() throws InterruptedException {
MainMethod test() throws InterruptedException {
start();
join();
if (this.exception != null) {
@@ -122,9 +122,9 @@ class MainMethodTests {
}
private static class NonStaticMain {
public static class NonStaticMain {
public void main(String... args) {
void main(String... args) {
mainMethod.set(new MainMethod());
}

View File

@@ -72,9 +72,9 @@ class OnInitializedRestarterConditionTests {
}
}
public static class TestInitialized {
static class TestInitialized {
public static void main(String... args) {
static void main(String... args) {
RestartInitializer initializer = mock(RestartInitializer.class);
given(initializer.getInitialUrls(any(Thread.class))).willReturn(new URL[0]);
Restarter.initialize(new String[0], false, initializer);
@@ -89,11 +89,11 @@ class OnInitializedRestarterConditionTests {
}
@Configuration(proxyBeanMethods = false)
public static class Config {
static class Config {
@Bean
@ConditionalOnInitializedRestarter
public String bean() {
String bean() {
return "bean";
}

View File

@@ -60,17 +60,17 @@ class RestartScopeInitializerTests {
}
@Configuration(proxyBeanMethods = false)
public static class Config {
static class Config {
@Bean
@RestartScope
public ScopeTestBean scopeTestBean() {
ScopeTestBean scopeTestBean() {
return new ScopeTestBean();
}
}
public static class ScopeTestBean implements ApplicationListener<ContextRefreshedEvent> {
static class ScopeTestBean implements ApplicationListener<ContextRefreshedEvent> {
ScopeTestBean() {
createCount.incrementAndGet();

View File

@@ -171,26 +171,26 @@ class RestarterTests {
@Component
@EnableScheduling
public static class SampleApplication {
static class SampleApplication {
private int count = 0;
private static volatile boolean quit = false;
@Scheduled(fixedDelay = 200)
public void tickBean() {
void tickBean() {
System.out.println("Tick " + this.count++ + " " + Thread.currentThread());
}
@Scheduled(initialDelay = 500, fixedDelay = 500)
public void restart() {
void restart() {
System.out.println("Restart " + Thread.currentThread());
if (!SampleApplication.quit) {
Restarter.getInstance().restart();
}
}
public static void main(String... args) {
static void main(String... args) {
Restarter.initialize(args, false, new MockRestartInitializer(), true);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
SampleApplication.class);
@@ -212,7 +212,7 @@ class RestarterTests {
}
private static class CloseCountingApplicationListener implements ApplicationListener<ContextClosedEvent> {
static class CloseCountingApplicationListener implements ApplicationListener<ContextClosedEvent> {
static int closed = 0;
@@ -223,7 +223,7 @@ class RestarterTests {
}
private static class TestableRestarter extends Restarter {
static class TestableRestarter extends Restarter {
private ClassLoader relaunchClassLoader;
@@ -257,7 +257,7 @@ class RestarterTests {
protected void stop() {
}
public ClassLoader getRelaunchClassLoader() {
ClassLoader getRelaunchClassLoader() {
return this.relaunchClassLoader;
}

View File

@@ -76,7 +76,7 @@ class SilentExitExceptionHandlerTests {
}
private abstract static class TestThread extends Thread {
static class TestThread extends Thread {
private Throwable thrown;
@@ -84,18 +84,18 @@ class SilentExitExceptionHandlerTests {
setUncaughtExceptionHandler((thread, exception) -> TestThread.this.thrown = exception);
}
public Throwable getThrown() {
Throwable getThrown() {
return this.thrown;
}
public void startAndJoin() throws InterruptedException {
void startAndJoin() throws InterruptedException {
start();
join();
}
}
private static class TestSilentExitExceptionHandler extends SilentExitExceptionHandler {
static class TestSilentExitExceptionHandler extends SilentExitExceptionHandler {
private boolean nonZeroExitCodePrevented;

View File

@@ -104,7 +104,7 @@ class RestartServerTests {
assertThat(FileCopyUtils.copyToByteArray(classFile)).isEqualTo("def".getBytes());
}
private static class MockRestartServer extends RestartServer {
static class MockRestartServer extends RestartServer {
MockRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter, ClassLoader classLoader) {
super(sourceFolderUrlFilter, classLoader);

View File

@@ -115,7 +115,7 @@ public class MockClientHttpRequestFactory implements ClientHttpRequestFactory {
this.status = status;
}
public ClientHttpResponse asHttpResponse(AtomicLong seq) {
ClientHttpResponse asHttpResponse(AtomicLong seq) {
MockClientHttpResponse httpResponse = new MockClientHttpResponse(
(this.payload != null) ? this.payload : NO_DATA, this.status);
waitForDelay();

View File

@@ -156,7 +156,7 @@ class HttpTunnelConnectionTests {
return connection.open(this.incomingChannel, this.closeable);
}
private static class CurrentThreadExecutor implements Executor {
static class CurrentThreadExecutor implements Executor {
@Override
public void execute(Runnable command) {

View File

@@ -107,7 +107,7 @@ class TunnelClientTests {
verify(listener).onClose(any(SocketChannel.class));
}
private static class MockTunnelConnection implements TunnelConnection {
static class MockTunnelConnection implements TunnelConnection {
private final ByteArrayOutputStream written = new ByteArrayOutputStream();
@@ -122,22 +122,22 @@ class TunnelClientTests {
return new TunnelChannel(incomingChannel, closeable);
}
public void verifyWritten(String expected) {
void verifyWritten(String expected) {
verifyWritten(expected.getBytes());
}
public void verifyWritten(byte[] expected) {
void verifyWritten(byte[] expected) {
synchronized (this.written) {
assertThat(this.written.toByteArray()).isEqualTo(expected);
this.written.reset();
}
}
public boolean isOpen() {
boolean isOpen() {
return this.open;
}
public int getOpenedTimes() {
int getOpenedTimes() {
return this.openedTimes;
}

View File

@@ -320,7 +320,7 @@ class HttpTunnelServerTests {
/**
* Mock {@link ByteChannel} used to simulate the server connection.
*/
private static class MockServerChannel implements ByteChannel {
static class MockServerChannel implements ByteChannel {
private static final ByteBuffer DISCONNECT = ByteBuffer.wrap(NO_DATA);
@@ -332,27 +332,27 @@ class HttpTunnelServerTests {
private AtomicBoolean open = new AtomicBoolean(true);
public void setTimeout(int timeout) {
void setTimeout(int timeout) {
this.timeout = timeout;
}
public void send(String content) {
void send(String content) {
send(content.getBytes());
}
public void send(byte[] bytes) {
void send(byte[] bytes) {
this.outgoing.addLast(ByteBuffer.wrap(bytes));
}
public void disconnect() {
void disconnect() {
this.outgoing.addLast(DISCONNECT);
}
public void verifyReceived(String expected) {
void verifyReceived(String expected) {
verifyReceived(expected.getBytes());
}
public void verifyReceived(byte[] expected) {
void verifyReceived(byte[] expected) {
synchronized (this.written) {
assertThat(this.written.toByteArray()).isEqualTo(expected);
this.written.reset();
@@ -405,7 +405,7 @@ class HttpTunnelServerTests {
/**
* Mock {@link HttpConnection}.
*/
private static class MockHttpConnection extends HttpConnection {
static class MockHttpConnection extends HttpConnection {
MockHttpConnection() {
super(new ServletServerHttpRequest(new MockHttpServletRequest()),
@@ -431,22 +431,22 @@ class HttpTunnelServerTests {
getServletResponse().setCommitted(true);
}
public MockHttpServletRequest getServletRequest() {
MockHttpServletRequest getServletRequest() {
return (MockHttpServletRequest) ((ServletServerHttpRequest) getRequest()).getServletRequest();
}
public MockHttpServletResponse getServletResponse() {
MockHttpServletResponse getServletResponse() {
return (MockHttpServletResponse) ((ServletServerHttpResponse) getResponse()).getServletResponse();
}
public void verifyReceived(String expectedContent, int expectedSeq) throws Exception {
void verifyReceived(String expectedContent, int expectedSeq) throws Exception {
waitForServletResponse();
MockHttpServletResponse resp = getServletResponse();
assertThat(resp.getContentAsString()).isEqualTo(expectedContent);
assertThat(resp.getHeader(SEQ_HEADER)).isEqualTo(String.valueOf(expectedSeq));
}
public void waitForServletResponse() throws InterruptedException {
void waitForServletResponse() throws InterruptedException {
while (!getServletResponse().isCommitted()) {
Thread.sleep(10);
}

View File

@@ -83,7 +83,7 @@ class SocketTargetServerConnectionTests {
});
}
private static class MockServer {
static class MockServer {
private ServerSocketChannel serverSocket;
@@ -106,29 +106,29 @@ class SocketTargetServerConnectionTests {
return this.serverSocket.socket().getLocalPort();
}
public void delay(int delay) {
void delay(int delay) {
this.delay = delay;
}
public void willSend(byte[] send) {
void willSend(byte[] send) {
this.send = send;
}
public void expect(byte[] expect) {
void expect(byte[] expect) {
this.expect = expect;
}
public void start() {
void start() {
this.thread = new ServerThread();
this.thread.start();
}
public void closeAndVerify() throws InterruptedException {
void closeAndVerify() throws InterruptedException {
close();
assertThat(this.actualRead.array()).isEqualTo(this.expect);
}
public void close() throws InterruptedException {
void close() throws InterruptedException {
while (this.thread.isAlive()) {
Thread.sleep(10);
}