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

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