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
@@ -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.
@@ -41,8 +41,8 @@ public class RemoteUrlPropertyExtractorTests {
@After
public void preventRunFailuresFromPollutingLoggerContext() {
((Logger) LoggerFactory.getLogger(RemoteUrlPropertyExtractorTests.class))
.getLoggerContext().getTurboFilterList().clear();
((Logger) LoggerFactory.getLogger(RemoteUrlPropertyExtractorTests.class)).getLoggerContext()
.getTurboFilterList().clear();
}
@Test
@@ -70,17 +70,14 @@ public class RemoteUrlPropertyExtractorTests {
@Test
public void validUrl() throws Exception {
ApplicationContext context = doTest("http://localhost:8080");
assertThat(context.getEnvironment().getProperty("remoteUrl"))
.isEqualTo("http://localhost:8080");
assertThat(context.getEnvironment().getProperty("spring.thymeleaf.cache"))
.isNull();
assertThat(context.getEnvironment().getProperty("remoteUrl")).isEqualTo("http://localhost:8080");
assertThat(context.getEnvironment().getProperty("spring.thymeleaf.cache")).isNull();
}
@Test
public void cleanValidUrl() throws Exception {
ApplicationContext context = doTest("http://localhost:8080/");
assertThat(context.getEnvironment().getProperty("remoteUrl"))
.isEqualTo("http://localhost:8080");
assertThat(context.getEnvironment().getProperty("remoteUrl")).isEqualTo("http://localhost:8080");
}
private ApplicationContext doTest(String... args) {
@@ -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,8 +52,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
@Test
public void singleManuallyConfiguredDataSourceIsNotClosed() throws SQLException {
ConfigurableApplicationContext context = createContext(
DataSourcePropertiesConfiguration.class,
ConfigurableApplicationContext context = createContext(DataSourcePropertiesConfiguration.class,
SingleDataSourceConfiguration.class);
DataSource dataSource = context.getBean(DataSource.class);
Statement statement = configureDataSourceBehaviour(dataSource);
@@ -62,11 +61,9 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
@Test
public void multipleDataSourcesAreIgnored() throws SQLException {
ConfigurableApplicationContext context = createContext(
DataSourcePropertiesConfiguration.class,
ConfigurableApplicationContext context = createContext(DataSourcePropertiesConfiguration.class,
MultipleDataSourcesConfiguration.class);
Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class)
.values();
Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class).values();
for (DataSource dataSource : dataSources) {
Statement statement = configureDataSourceBehaviour(dataSource);
verify(statement, times(0)).execute("SHUTDOWN");
@@ -77,8 +74,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
public void emptyFactoryMethodMetadataIgnored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
DataSource dataSource = mock(DataSource.class);
AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
dataSource.getClass());
AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(dataSource.getClass());
context.registerBeanDefinition("dataSource", beanDefinition);
context.register(DataSourcePropertiesConfiguration.class);
context.register(DevToolsDataSourceAutoConfiguration.class);
@@ -86,8 +82,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
context.close();
}
protected final Statement configureDataSourceBehaviour(DataSource dataSource)
throws SQLException {
protected final Statement configureDataSourceBehaviour(DataSource dataSource) throws SQLException {
Connection connection = mock(Connection.class);
Statement statement = mock(Statement.class);
doReturn(connection).when(dataSource).getConnection();
@@ -99,19 +94,17 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
return this.createContext(null, classes);
}
protected final ConfigurableApplicationContext createContext(String driverClassName,
Class<?>... classes) {
protected final ConfigurableApplicationContext createContext(String driverClassName, Class<?>... classes) {
return this.createContext(driverClassName, null, classes);
}
protected final ConfigurableApplicationContext createContext(String driverClassName,
String url, Class<?>... classes) {
protected final ConfigurableApplicationContext createContext(String driverClassName, String url,
Class<?>... classes) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(classes);
context.register(DevToolsDataSourceAutoConfiguration.class);
if (driverClassName != null) {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.driver-class-name:" + driverClassName);
EnvironmentTestUtils.addEnvironment(context, "spring.datasource.driver-class-name:" + driverClassName);
}
if (url != null) {
EnvironmentTestUtils.addEnvironment(context, "spring.datasource.url:" + url);
@@ -164,8 +157,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
private static class DataSourceSpyBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof DataSource) {
bean = spy(bean);
}
@@ -173,8 +165,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@@ -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.
@@ -39,15 +39,13 @@ import static org.mockito.Mockito.verify;
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("tomcat-jdbc-*.jar")
public class DevToolsEmbeddedDataSourceAutoConfigurationTests
extends AbstractDevToolsDataSourceAutoConfigurationTests {
public class DevToolsEmbeddedDataSourceAutoConfigurationTests extends AbstractDevToolsDataSourceAutoConfigurationTests {
@Test
public void autoConfiguredDataSourceIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext(
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext(DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@@ -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,15 +34,13 @@ import static org.mockito.Mockito.verify;
*
* @author Andy Wilkinson
*/
public class DevToolsPooledDataSourceAutoConfigurationTests
extends AbstractDevToolsDataSourceAutoConfigurationTests {
public class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDataSourceAutoConfigurationTests {
@Test
public void autoConfiguredInMemoryDataSourceIsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext(
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext(DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement).execute("SHUTDOWN");
}
@@ -51,74 +49,61 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
public void autoConfiguredExternalDataSourceIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.postgresql.Driver",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void h2ServerIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.h2.Driver",
"jdbc:h2:hsql://localhost", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext("org.h2.Driver", "jdbc:h2:hsql://localhost",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void inMemoryH2IsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.h2.Driver",
"jdbc:h2:mem:test", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext("org.h2.Driver", "jdbc:h2:mem:test",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
}
@Test
public void hsqlServerIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:hsql://localhost", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext("org.hsqldb.jdbcDriver", "jdbc:hsqldb:hsql://localhost",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void inMemoryHsqlIsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:mem:test", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:test",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
}
@Test
public void derbyClientIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext(
"org.apache.derby.jdbc.ClientDriver", "jdbc:derby://localhost",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext("org.apache.derby.jdbc.ClientDriver",
"jdbc:derby://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void inMemoryDerbyIsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext(
"org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:test",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
ConfigurableApplicationContext context = createContext("org.apache.derby.jdbc.EmbeddedDriver",
"jdbc:derby:memory:test", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
}
@@ -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.
@@ -33,9 +33,8 @@ public class DevToolsPropertiesTests {
public void additionalExcludeKeepsDefaults() {
DevToolsProperties.Restart restart = this.devToolsProperties.getRestart();
restart.setAdditionalExclude("foo/**,bar/**");
assertThat(restart.getAllExclude()).containsOnly("META-INF/maven/**",
"META-INF/resources/**", "resources/**", "static/**", "public/**",
"templates/**", "**/*Test.class", "**/*Tests.class", "git.properties",
assertThat(restart.getAllExclude()).containsOnly("META-INF/maven/**", "META-INF/resources/**", "resources/**",
"static/**", "public/**", "templates/**", "**/*Test.class", "**/*Tests.class", "git.properties",
"META-INF/build-info.properties", "foo/**", "bar/**");
}
@@ -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,10 +41,8 @@ public class HateoasObjenesisCacheDisablerTests {
@Before
@After
public void resetCacheField() {
this.objenesis = (ObjenesisStd) ReflectionTestUtils
.getField(DummyInvocationUtils.class, "OBJENESIS");
ReflectionTestUtils.setField(this.objenesis, "cache",
new ConcurrentHashMap<String, ObjectInstantiator<?>>());
this.objenesis = (ObjenesisStd) ReflectionTestUtils.getField(DummyInvocationUtils.class, "OBJENESIS");
ReflectionTestUtils.setField(this.objenesis, "cache", new ConcurrentHashMap<String, ObjectInstantiator<?>>());
}
@Test
@@ -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.
@@ -109,8 +109,7 @@ public class LocalDevToolsAutoConfigurationTests {
@Test
public void defaultPropertyCanBeOverriddenFromUserHomeProperties() throws Exception {
String userHome = System.getProperty("user.home");
System.setProperty("user.home",
new File("src/test/resources/user-home").getAbsolutePath());
System.setProperty("user.home", new File("src/test/resources/user-home").getAbsolutePath());
try {
this.context = initializeAndRun(Config.class);
TemplateResolver resolver = this.context.getBean(TemplateResolver.class);
@@ -150,8 +149,8 @@ public class LocalDevToolsAutoConfigurationTests {
this.context = initializeAndRun(ConfigWithMockLiveReload.class);
LiveReloadServer server = this.context.getBean(LiveReloadServer.class);
reset(server);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context,
Collections.<ChangedFiles>emptySet(), false);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(),
false);
this.context.publishEvent(event);
verify(server).triggerReload();
}
@@ -161,8 +160,8 @@ public class LocalDevToolsAutoConfigurationTests {
this.context = initializeAndRun(ConfigWithMockLiveReload.class);
LiveReloadServer server = this.context.getBean(LiveReloadServer.class);
reset(server);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context,
Collections.<ChangedFiles>emptySet(), true);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(),
true);
this.context.publishEvent(event);
verify(server, never()).triggerReload();
}
@@ -179,8 +178,8 @@ public class LocalDevToolsAutoConfigurationTests {
@Test
public void restartTriggeredOnClassPathChangeWithRestart() throws Exception {
this.context = initializeAndRun(Config.class);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context,
Collections.<ChangedFiles>emptySet(), true);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(),
true);
this.context.publishEvent(event);
verify(this.mockRestarter.getMock()).restart(any(FailureHandler.class));
}
@@ -188,8 +187,8 @@ public class LocalDevToolsAutoConfigurationTests {
@Test
public void restartNotTriggeredOnClassPathChangeWithRestart() throws Exception {
this.context = initializeAndRun(Config.class);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context,
Collections.<ChangedFiles>emptySet(), false);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(),
false);
this.context.publishEvent(event);
verify(this.mockRestarter.getMock(), never()).restart();
}
@@ -197,8 +196,7 @@ public class LocalDevToolsAutoConfigurationTests {
@Test
public void restartWatchingClassPath() throws Exception {
this.context = initializeAndRun(Config.class);
ClassPathFileSystemWatcher watcher = this.context
.getBean(ClassPathFileSystemWatcher.class);
ClassPathFileSystemWatcher watcher = this.context.getBean(ClassPathFileSystemWatcher.class);
assertThat(watcher).isNotNull();
}
@@ -216,10 +214,8 @@ public class LocalDevToolsAutoConfigurationTests {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("spring.devtools.restart.trigger-file", "somefile.txt");
this.context = initializeAndRun(Config.class, properties);
ClassPathFileSystemWatcher classPathWatcher = this.context
.getBean(ClassPathFileSystemWatcher.class);
Object watcher = ReflectionTestUtils.getField(classPathWatcher,
"fileSystemWatcher");
ClassPathFileSystemWatcher classPathWatcher = this.context.getBean(ClassPathFileSystemWatcher.class);
Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher");
Object filter = ReflectionTestUtils.getField(watcher, "triggerFilter");
assertThat(filter).isInstanceOf(TriggerFileFilter.class);
}
@@ -227,18 +223,13 @@ public class LocalDevToolsAutoConfigurationTests {
@Test
public void watchingAdditionalPaths() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("spring.devtools.restart.additional-paths",
"src/main/java,src/test/java");
properties.put("spring.devtools.restart.additional-paths", "src/main/java,src/test/java");
this.context = initializeAndRun(Config.class, properties);
ClassPathFileSystemWatcher classPathWatcher = this.context
.getBean(ClassPathFileSystemWatcher.class);
Object watcher = ReflectionTestUtils.getField(classPathWatcher,
"fileSystemWatcher");
ClassPathFileSystemWatcher classPathWatcher = this.context.getBean(ClassPathFileSystemWatcher.class);
Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher");
@SuppressWarnings("unchecked")
Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils
.getField(watcher, "folders");
assertThat(folders).hasSize(2)
.containsKey(new File("src/main/java").getAbsoluteFile())
Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils.getField(watcher, "folders");
assertThat(folders).hasSize(2).containsKey(new File("src/main/java").getAbsoluteFile())
.containsKey(new File("src/test/java").getAbsoluteFile());
}
@@ -254,13 +245,12 @@ public class LocalDevToolsAutoConfigurationTests {
assertThat(options.getDevelopment()).isEqualTo(true);
}
private ConfigurableApplicationContext initializeAndRun(Class<?> config,
String... args) {
private ConfigurableApplicationContext initializeAndRun(Class<?> config, String... args) {
return initializeAndRun(config, Collections.<String, Object>emptyMap(), args);
}
private ConfigurableApplicationContext initializeAndRun(Class<?> config,
Map<String, Object> properties, String... args) {
private ConfigurableApplicationContext initializeAndRun(Class<?> config, Map<String, Object> properties,
String... args) {
Restarter.initialize(new String[0], false, new MockRestartInitializer(), false);
SpringApplication application = new SpringApplication(config);
application.setDefaultProperties(getDefaultProperties(properties));
@@ -268,8 +258,7 @@ public class LocalDevToolsAutoConfigurationTests {
return context;
}
private Map<String, Object> getDefaultProperties(
Map<String, Object> specifiedProperties) {
private Map<String, Object> getDefaultProperties(Map<String, Object> specifiedProperties) {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("spring.thymeleaf.check-template-location", false);
properties.put("spring.devtools.livereload.port", this.liveReloadPort);
@@ -279,16 +268,16 @@ public class LocalDevToolsAutoConfigurationTests {
}
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
LocalDevToolsAutoConfiguration.class, ThymeleafAutoConfiguration.class })
@Import({ EmbeddedServletContainerAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
ThymeleafAutoConfiguration.class })
@EnableConfigurationProperties(ServerProperties.class)
public static class Config {
}
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
LocalDevToolsAutoConfiguration.class, ThymeleafAutoConfiguration.class })
@Import({ EmbeddedServletContainerAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
ThymeleafAutoConfiguration.class })
@EnableConfigurationProperties(ServerProperties.class)
public static class ConfigWithMockLiveReload {
@@ -300,8 +289,8 @@ public class LocalDevToolsAutoConfigurationTests {
}
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
LocalDevToolsAutoConfiguration.class, ResourceProperties.class })
@Import({ EmbeddedServletContainerAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
ResourceProperties.class })
@EnableConfigurationProperties(ServerProperties.class)
public static class WebResourcesConfig {
@@ -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.
@@ -138,8 +138,7 @@ public class RemoteDevToolsAutoConfigurationTests {
@Test
public void invokeRestartWithCustomServerContextPath() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"server.context-path:/test");
loadContext("spring.devtools.remote.secret:supersecret", "server.context-path:/test");
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/restart");
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
@@ -149,8 +148,7 @@ public class RemoteDevToolsAutoConfigurationTests {
@Test
public void disableRestart() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"spring.devtools.remote.restart.enabled:false");
loadContext("spring.devtools.remote.secret:supersecret", "spring.devtools.remote.restart.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean("remoteRestartHandlerMapper");
}
@@ -167,8 +165,7 @@ public class RemoteDevToolsAutoConfigurationTests {
@Test
public void invokeTunnelWithCustomServerContextPath() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"server.context-path:/test");
loadContext("spring.devtools.remote.secret:supersecret", "server.context-path:/test");
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/debug");
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
@@ -189,8 +186,7 @@ public class RemoteDevToolsAutoConfigurationTests {
@Test
public void disableRemoteDebug() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"spring.devtools.remote.debug.enabled:false");
loadContext("spring.devtools.remote.secret:supersecret", "spring.devtools.remote.debug.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean("remoteDebugHandlerMapper");
}
@@ -208,8 +204,7 @@ public class RemoteDevToolsAutoConfigurationTests {
@Test
public void devToolsHealthWithCustomServerContextPathReturns200() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"server.context-path:/test");
loadContext("spring.devtools.remote.secret:supersecret", "server.context-path:/test");
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH);
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
@@ -219,13 +214,11 @@ public class RemoteDevToolsAutoConfigurationTests {
}
private void assertTunnelInvoked(boolean value) {
assertThat(this.context.getBean(MockHttpTunnelServer.class).invoked)
.isEqualTo(value);
assertThat(this.context.getBean(MockHttpTunnelServer.class).invoked).isEqualTo(value);
}
private void assertRestartInvoked(boolean value) {
assertThat(this.context.getBean(MockHttpRestartServer.class).invoked)
.isEqualTo(value);
assertThat(this.context.getBean(MockHttpRestartServer.class).invoked).isEqualTo(value);
}
private void loadContext(String... properties) {
@@ -243,14 +236,12 @@ public class RemoteDevToolsAutoConfigurationTests {
@Bean
public HttpTunnelServer remoteDebugHttpTunnelServer() {
return new MockHttpTunnelServer(
new SocketTargetServerConnection(new RemoteDebugPortProvider()));
return new MockHttpTunnelServer(new SocketTargetServerConnection(new RemoteDebugPortProvider()));
}
@Bean
public HttpRestartServer remoteRestartHttpRestartServer() {
SourceFolderUrlFilter sourceFolderUrlFilter = mock(
SourceFolderUrlFilter.class);
SourceFolderUrlFilter sourceFolderUrlFilter = mock(SourceFolderUrlFilter.class);
return new MockHttpRestartServer(sourceFolderUrlFilter);
}
@@ -268,8 +259,7 @@ public class RemoteDevToolsAutoConfigurationTests {
}
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response)
throws IOException {
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
this.invoked = true;
}
@@ -287,8 +277,7 @@ public class RemoteDevToolsAutoConfigurationTests {
}
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response)
throws IOException {
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
this.invoked = true;
}
@@ -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,8 +49,7 @@ public class ClassPathChangedEventTests {
@Test
public void getChangeSet() throws Exception {
Set<ChangedFiles> changeSet = new LinkedHashSet<ChangedFiles>();
ClassPathChangedEvent event = new ClassPathChangedEvent(this.source, changeSet,
false);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.source, changeSet, false);
assertThat(event.getChangeSet()).isSameAs(changeSet);
}
@@ -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.
@@ -72,16 +72,14 @@ public class ClassPathFileChangeListenerTests {
public void eventPublisherMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("EventPublisher must not be null");
new ClassPathFileChangeListener(null, this.restartStrategy,
this.fileSystemWatcher);
new ClassPathFileChangeListener(null, this.restartStrategy, this.fileSystemWatcher);
}
@Test
public void restartStrategyMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("RestartStrategy must not be null");
new ClassPathFileChangeListener(this.eventPublisher, null,
this.fileSystemWatcher);
new ClassPathFileChangeListener(this.eventPublisher, null, this.fileSystemWatcher);
}
@Test
@@ -97,8 +95,8 @@ public class ClassPathFileChangeListenerTests {
}
private void testSendsEvent(boolean restart) {
ClassPathFileChangeListener listener = new ClassPathFileChangeListener(
this.eventPublisher, this.restartStrategy, this.fileSystemWatcher);
ClassPathFileChangeListener listener = new ClassPathFileChangeListener(this.eventPublisher,
this.restartStrategy, this.fileSystemWatcher);
File folder = new File("s1");
File file = new File("f1");
ChangedFile file1 = new ChangedFile(folder, file, ChangedFile.Type.ADD);
@@ -113,8 +111,7 @@ public class ClassPathFileChangeListenerTests {
}
listener.onChange(changeSet);
verify(this.eventPublisher).publishEvent(this.eventCaptor.capture());
ClassPathChangedEvent actualEvent = (ClassPathChangedEvent) this.eventCaptor
.getValue();
ClassPathChangedEvent actualEvent = (ClassPathChangedEvent) this.eventCaptor.getValue();
assertThat(actualEvent.getChangeSet()).isEqualTo(changeSet);
assertThat(actualEvent.isRestartRequired()).isEqualTo(restart);
}
@@ -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.
@@ -60,8 +60,8 @@ public class ClassPathFileSystemWatcherTests {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Urls must not be null");
URL[] urls = null;
new ClassPathFileSystemWatcher(mock(FileSystemWatcherFactory.class),
mock(ClassPathRestartStrategy.class), urls);
new ClassPathFileSystemWatcher(mock(FileSystemWatcherFactory.class), mock(ClassPathRestartStrategy.class),
urls);
}
@Test
@@ -89,8 +89,8 @@ public class ClassPathFileSystemWatcherTests {
Thread.sleep(500);
}
assertThat(events.size()).isEqualTo(1);
assertThat(events.get(0).getChangeSet().iterator().next().getFiles().iterator()
.next().getFile()).isEqualTo(classFile);
assertThat(events.get(0).getChangeSet().iterator().next().getFiles().iterator().next().getFile())
.isEqualTo(classFile);
context.close();
}
@@ -107,8 +107,7 @@ public class ClassPathFileSystemWatcherTests {
public ClassPathFileSystemWatcher watcher() {
FileSystemWatcher watcher = new FileSystemWatcher(false, 100, 10);
URL[] urls = this.environment.getProperty("urls", URL[].class);
return new ClassPathFileSystemWatcher(
new MockFileSystemWatcherFactory(watcher), restartStrategy(), urls);
return new ClassPathFileSystemWatcher(new MockFileSystemWatcherFactory(watcher), restartStrategy(), urls);
}
@Bean
@@ -145,8 +144,7 @@ public class ClassPathFileSystemWatcherTests {
}
private static class MockFileSystemWatcherFactory
implements FileSystemWatcherFactory {
private static class MockFileSystemWatcherFactory implements FileSystemWatcherFactory {
private final FileSystemWatcher watcher;
@@ -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.
@@ -76,8 +76,7 @@ public class PatternClassPathRestartStrategyTests {
@Test
public void testChange() {
ClassPathRestartStrategy strategy = createStrategy(
"**/*Test.class,**/*Tests.class");
ClassPathRestartStrategy strategy = createStrategy("**/*Test.class,**/*Tests.class");
assertRestartRequired(strategy, "com/example/ExampleTests.class", false);
assertRestartRequired(strategy, "com/example/ExampleTest.class", false);
assertRestartRequired(strategy, "com/example/Example.class", true);
@@ -87,10 +86,8 @@ public class PatternClassPathRestartStrategyTests {
return new PatternClassPathRestartStrategy(pattern);
}
private void assertRestartRequired(ClassPathRestartStrategy strategy,
String relativeName, boolean expected) {
assertThat(strategy.isRestartRequired(mockFile(relativeName)))
.isEqualTo(expected);
private void assertRestartRequired(ClassPathRestartStrategy strategy, String relativeName, boolean expected) {
assertThat(strategy.isRestartRequired(mockFile(relativeName))).isEqualTo(expected);
}
private ChangedFile mockFile(String relativeName) {
@@ -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.
@@ -61,8 +61,7 @@ public class DevToolPropertiesIntegrationTests {
@Test
public void classPropertyConditionIsAffectedByDevToolProperties() {
SpringApplication application = new SpringApplication(
ClassConditionConfiguration.class);
SpringApplication application = new SpringApplication(ClassConditionConfiguration.class);
application.setWebEnvironment(false);
this.context = application.run();
this.context.getBean(ClassConditionConfiguration.class);
@@ -70,20 +69,17 @@ public class DevToolPropertiesIntegrationTests {
@Test
public void beanMethodPropertyConditionIsAffectedByDevToolProperties() {
SpringApplication application = new SpringApplication(
BeanConditionConfiguration.class);
SpringApplication application = new SpringApplication(BeanConditionConfiguration.class);
application.setWebEnvironment(false);
this.context = application.run();
this.context.getBean(MyBean.class);
}
@Test
public void postProcessWhenRestarterDisabledAndRemoteSecretNotSetShouldNotAddPropertySource()
throws Exception {
public void postProcessWhenRestarterDisabledAndRemoteSecretNotSetShouldNotAddPropertySource() throws Exception {
Restarter.clearInstance();
Restarter.disable();
SpringApplication application = new SpringApplication(
BeanConditionConfiguration.class);
SpringApplication application = new SpringApplication(BeanConditionConfiguration.class);
application.setWebEnvironment(false);
this.context = application.run();
this.thrown.expect(NoSuchBeanDefinitionException.class);
@@ -91,15 +87,13 @@ public class DevToolPropertiesIntegrationTests {
}
@Test
public void postProcessWhenRestarterDisabledAndRemoteSecretSetShouldAddPropertySource()
throws Exception {
public void postProcessWhenRestarterDisabledAndRemoteSecretSetShouldAddPropertySource() throws Exception {
Restarter.clearInstance();
Restarter.disable();
SpringApplication application = new SpringApplication(
BeanConditionConfiguration.class);
SpringApplication application = new SpringApplication(BeanConditionConfiguration.class);
application.setWebEnvironment(false);
application.setDefaultProperties(Collections.<String, Object>singletonMap(
"spring.devtools.remote.secret", "donttell"));
application.setDefaultProperties(
Collections.<String, Object>singletonMap("spring.devtools.remote.secret", "donttell"));
this.context = application.run();
this.context.getBean(MyBean.class);
}
@@ -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.
@@ -54,8 +54,7 @@ public class DevToolsHomePropertiesPostProcessorTests {
public void loadsHomeProperties() throws Exception {
Properties properties = new Properties();
properties.put("abc", "def");
OutputStream out = new FileOutputStream(
new File(this.home, ".spring-boot-devtools.properties"));
OutputStream out = new FileOutputStream(new File(this.home, ".spring-boot-devtools.properties"));
properties.store(out, null);
out.close();
ConfigurableEnvironment environment = new MockEnvironment();
@@ -72,8 +71,7 @@ public class DevToolsHomePropertiesPostProcessorTests {
assertThat(environment.getProperty("abc")).isNull();
}
private class MockDevToolHomePropertiesPostProcessor
extends DevToolsHomePropertiesPostProcessor {
private class MockDevToolHomePropertiesPostProcessor extends DevToolsHomePropertiesPostProcessor {
@Override
protected File getHomeFolder() {
@@ -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.
@@ -70,8 +70,7 @@ public class ChangedFileTests {
@Test
public void getType() throws Exception {
ChangedFile changedFile = new ChangedFile(this.temp.newFolder(),
this.temp.newFile(), Type.DELETE);
ChangedFile changedFile = new ChangedFile(this.temp.newFolder(), this.temp.newFile(), Type.DELETE);
assertThat(changedFile.getType()).isEqualTo(Type.DELETE);
}
@@ -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.
@@ -39,8 +39,7 @@ public class FileSnapshotTests {
private static final long TWO_MINS = TimeUnit.MINUTES.toMillis(2);
private static final long MODIFIED = new Date().getTime()
- TimeUnit.DAYS.toMillis(10);
private static final long MODIFIED = new Date().getTime() - TimeUnit.DAYS.toMillis(10);
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -102,8 +101,7 @@ public class FileSnapshotTests {
return file;
}
private void setupFile(File file, String content, long lastModified)
throws IOException {
private void setupFile(File file, String content, long lastModified) throws IOException {
FileCopyUtils.copy(content.getBytes(), file);
file.setLastModified(lastModified);
}
@@ -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,8 +52,7 @@ public class FileSystemWatcherTests {
private FileSystemWatcher watcher;
private List<Set<ChangedFiles>> changes = Collections
.synchronizedList(new ArrayList<Set<ChangedFiles>>());
private List<Set<ChangedFiles>> changes = Collections.synchronizedList(new ArrayList<Set<ChangedFiles>>());
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -111,8 +110,7 @@ public class FileSystemWatcherTests {
File folder = new File("does/not/exist");
assertThat(folder.exists()).isFalse();
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage(
"Folder '" + folder + "' must exist and must be a directory");
this.thrown.expectMessage("Folder '" + folder + "' must exist and must be a directory");
this.watcher.addSourceFolder(folder);
}
@@ -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.
@@ -107,8 +107,7 @@ public class FolderSnapshotTests {
public void getChangedFilesSnapshotMustBeTheSameSourceFolder() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Snapshot source folder must be '" + this.folder + "'");
this.initialSnapshot
.getChangedFiles(new FolderSnapshot(createTestFolderStructure()), null);
this.initialSnapshot.getChangedFiles(new FolderSnapshot(createTestFolderStructure()), null);
}
@Test
@@ -127,8 +126,7 @@ public class FolderSnapshotTests {
file2.delete();
newFile.createNewFile();
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
ChangedFiles changedFiles = this.initialSnapshot.getChangedFiles(updatedSnapshot,
null);
ChangedFiles changedFiles = this.initialSnapshot.getChangedFiles(updatedSnapshot, null);
assertThat(changedFiles.getSourceFolder()).isEqualTo(this.folder);
assertThat(getChangedFile(changedFiles, file1).getType()).isEqualTo(Type.MODIFY);
assertThat(getChangedFile(changedFiles, file2).getType()).isEqualTo(Type.DELETE);
@@ -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.
@@ -71,8 +71,7 @@ public class HttpTunnelIntegrationTests {
@Test
public void httpServerDirect() throws Exception {
String url = "http://localhost:" + this.config.httpServerPort + "/hello";
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url,
String.class);
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("Hello World");
}
@@ -80,8 +79,7 @@ public class HttpTunnelIntegrationTests {
@Test
public void viaTunnel() throws Exception {
String url = "http://localhost:" + this.config.clientPort + "/hello";
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url,
String.class);
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("Hello World");
}
@@ -104,8 +102,7 @@ public class HttpTunnelIntegrationTests {
PortProvider port = new StaticPortProvider(this.httpServerPort);
TargetServerConnection connection = new SocketTargetServerConnection(port);
HttpTunnelServer server = new HttpTunnelServer(connection);
HandlerMapper mapper = new UrlHandlerMapper("/httptunnel",
new HttpTunnelServerHandler(server));
HandlerMapper mapper = new UrlHandlerMapper("/httptunnel", new HttpTunnelServerHandler(server));
Collection<HandlerMapper> mappers = Collections.singleton(mapper);
Dispatcher dispatcher = new Dispatcher(AccessManager.PERMIT_ALL, mappers);
return new DispatcherFilter(dispatcher);
@@ -114,8 +111,7 @@ public class HttpTunnelIntegrationTests {
@Bean
public TunnelClient tunnelClient() {
String url = "http://localhost:" + this.httpServerPort + "/httptunnel";
TunnelConnection connection = new HttpTunnelConnection(url,
new SimpleClientHttpRequestFactory());
TunnelConnection connection = new HttpTunnelConnection(url, new SimpleClientHttpRequestFactory());
return new TunnelClient(this.clientPort, connection);
}
@@ -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,20 +44,17 @@ public class ConnectionInputStreamTests {
public void readHeader() throws Exception {
String header = "";
for (int i = 0; i < 100; i++) {
header += "x-something-" + i
+ ": xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
header += "x-something-" + i + ": xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
}
String data = header + "\r\n\r\n" + "content\r\n";
ConnectionInputStream inputStream = new ConnectionInputStream(
new ByteArrayInputStream(data.getBytes()));
ConnectionInputStream inputStream = new ConnectionInputStream(new ByteArrayInputStream(data.getBytes()));
assertThat(inputStream.readHeader()).isEqualTo(header);
}
@Test
public void readFully() throws Exception {
byte[] bytes = "the data that we want to read fully".getBytes();
LimitedInputStream source = new LimitedInputStream(
new ByteArrayInputStream(bytes), 2);
LimitedInputStream source = new LimitedInputStream(new ByteArrayInputStream(bytes), 2);
ConnectionInputStream inputStream = new ConnectionInputStream(source);
byte[] buffer = new byte[bytes.length];
inputStream.readFully(buffer, 0, buffer.length);
@@ -66,8 +63,7 @@ public class ConnectionInputStreamTests {
@Test
public void checkedRead() throws Exception {
ConnectionInputStream inputStream = new ConnectionInputStream(
new ByteArrayInputStream(NO_BYTES));
ConnectionInputStream inputStream = new ConnectionInputStream(new ByteArrayInputStream(NO_BYTES));
this.thrown.expect(IOException.class);
this.thrown.expectMessage("End of stream");
inputStream.checkedRead();
@@ -75,8 +71,7 @@ public class ConnectionInputStreamTests {
@Test
public void checkedReadArray() throws Exception {
ConnectionInputStream inputStream = new ConnectionInputStream(
new ByteArrayInputStream(NO_BYTES));
ConnectionInputStream inputStream = new ConnectionInputStream(new ByteArrayInputStream(NO_BYTES));
this.thrown.expect(IOException.class);
this.thrown.expectMessage("End of stream");
byte[] buffer = new byte[100];
@@ -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.
@@ -115,8 +115,7 @@ public class FrameTests {
@Test
public void readMaskedTextFrame() throws Exception {
byte[] bytes = new byte[] { (byte) 0x81, (byte) 0x82, 0x0F, 0x0F, 0x0F, 0x0F,
0x4E, 0x4E };
byte[] bytes = new byte[] { (byte) 0x81, (byte) 0x82, 0x0F, 0x0F, 0x0F, 0x0F, 0x4E, 0x4E };
Frame frame = Frame.read(newConnectionInputStream(bytes));
assertThat(frame.getType()).isEqualTo(Frame.Type.TEXT);
assertThat(frame.getPayload()).isEqualTo(new byte[] { 0x41, 0x41 });
@@ -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.
@@ -86,8 +86,7 @@ public class LiveReloadServerTests {
this.server.triggerReload();
Thread.sleep(200);
this.server.stop();
assertThat(handler.getMessages().get(0))
.contains("http://livereload.com/protocols/official-7");
assertThat(handler.getMessages().get(0)).contains("http://livereload.com/protocols/official-7");
assertThat(handler.getMessages().get(1)).contains("command\":\"reload\"");
}
@@ -110,8 +109,7 @@ public class LiveReloadServerTests {
private void awaitClosedException() throws InterruptedException {
long startTime = System.currentTimeMillis();
while (this.server.getClosedExceptions().isEmpty()
&& System.currentTimeMillis() - startTime < 10000) {
while (this.server.getClosedExceptions().isEmpty() && System.currentTimeMillis() - startTime < 10000) {
Thread.sleep(100);
}
}
@@ -165,8 +163,8 @@ public class LiveReloadServerTests {
}
@Override
protected Connection createConnection(java.net.Socket socket,
InputStream inputStream, OutputStream outputStream) throws IOException {
protected Connection createConnection(java.net.Socket socket, InputStream inputStream,
OutputStream outputStream) throws IOException {
return new MonitoredConnection(socket, inputStream, outputStream);
}
@@ -178,8 +176,8 @@ public class LiveReloadServerTests {
private class MonitoredConnection extends Connection {
MonitoredConnection(java.net.Socket socket, InputStream inputStream,
OutputStream outputStream) throws IOException {
MonitoredConnection(java.net.Socket socket, InputStream inputStream, OutputStream outputStream)
throws IOException {
super(socket, inputStream, outputStream);
}
@@ -214,8 +212,7 @@ public class LiveReloadServerTests {
private CloseStatus closeStatus;
@Override
public void afterConnectionEstablished(WebSocketSession session)
throws Exception {
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
this.session = session;
session.sendMessage(new TextMessage(HANDSHAKE));
this.helloLatch.countDown();
@@ -227,8 +224,7 @@ public class LiveReloadServerTests {
}
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message)
throws Exception {
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
if (message.getPayload().contains("hello")) {
this.helloLatch.countDown();
}
@@ -236,14 +232,12 @@ public class LiveReloadServerTests {
}
@Override
protected void handlePongMessage(WebSocketSession session, PongMessage message)
throws Exception {
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
this.pongCount++;
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status)
throws Exception {
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
this.closeStatus = status;
}
@@ -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,8 +68,7 @@ public class ClassPathChangeUploaderTests {
@Before
public void setup() {
this.requestFactory = new MockClientHttpRequestFactory();
this.uploader = new ClassPathChangeUploader("http://localhost/upload",
this.requestFactory);
this.uploader = new ClassPathChangeUploader("http://localhost/upload", this.requestFactory);
}
@Test
@@ -119,8 +118,7 @@ public class ClassPathChangeUploaderTests {
this.requestFactory.willRespond(HttpStatus.OK);
this.uploader.onApplicationEvent(event);
assertThat(this.requestFactory.getExecutedRequests()).hasSize(2);
verifyUploadRequest(sourceFolder,
this.requestFactory.getExecutedRequests().get(1));
verifyUploadRequest(sourceFolder, this.requestFactory.getExecutedRequests().get(1));
}
private void verifyUploadRequest(File sourceFolder, MockClientHttpRequest request)
@@ -138,13 +136,11 @@ public class ClassPathChangeUploaderTests {
}
private void assertClassFile(ClassLoaderFile file, String content, Kind kind) {
assertThat(file.getContents())
.isEqualTo((content != null) ? content.getBytes() : null);
assertThat(file.getContents()).isEqualTo((content != null) ? content.getBytes() : null);
assertThat(file.getKind()).isEqualTo(kind);
}
private ClassPathChangedEvent createClassPathChangedEvent(File sourceFolder)
throws IOException {
private ClassPathChangedEvent createClassPathChangedEvent(File sourceFolder) throws IOException {
Set<ChangedFile> files = new LinkedHashSet<ChangedFile>();
File file1 = createFile(sourceFolder, "File1");
File file2 = createFile(sourceFolder, "File2");
@@ -164,10 +160,8 @@ public class ClassPathChangeUploaderTests {
return file;
}
private ClassLoaderFiles deserialize(byte[] bytes)
throws IOException, ClassNotFoundException {
ObjectInputStream objectInputStream = new ObjectInputStream(
new ByteArrayInputStream(bytes));
private ClassLoaderFiles deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes));
return (ClassLoaderFiles) objectInputStream.readObject();
}
@@ -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.
@@ -75,11 +75,9 @@ public class DelayedLiveReloadTriggerTests {
MockitoAnnotations.initMocks(this);
given(this.errorRequest.execute()).willReturn(this.errorResponse);
given(this.okRequest.execute()).willReturn(this.okResponse);
given(this.errorResponse.getStatusCode())
.willReturn(HttpStatus.INTERNAL_SERVER_ERROR);
given(this.errorResponse.getStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR);
given(this.okResponse.getStatusCode()).willReturn(HttpStatus.OK);
this.trigger = new DelayedLiveReloadTrigger(this.liveReloadServer,
this.requestFactory, URL);
this.trigger = new DelayedLiveReloadTrigger(this.liveReloadServer, this.requestFactory, URL);
}
@Test
@@ -112,8 +110,7 @@ public class DelayedLiveReloadTriggerTests {
@Test
public void triggerReloadOnStatus() throws Exception {
given(this.requestFactory.createRequest(new URI(URL), HttpMethod.GET))
.willThrow(new IOException())
given(this.requestFactory.createRequest(new URI(URL), HttpMethod.GET)).willThrow(new IOException())
.willReturn(this.errorRequest, this.okRequest);
long startTime = System.currentTimeMillis();
this.trigger.setTimings(10, 200, 30000);
@@ -124,8 +121,7 @@ public class DelayedLiveReloadTriggerTests {
@Test
public void timeout() throws Exception {
given(this.requestFactory.createRequest(new URI(URL), HttpMethod.GET))
.willThrow(new IOException());
given(this.requestFactory.createRequest(new URI(URL), HttpMethod.GET)).willThrow(new IOException());
this.trigger.setTimings(10, 0, 10);
this.trigger.run();
verify(this.liveReloadServer, never()).triggerReload();
@@ -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.
@@ -105,8 +105,7 @@ public class HttpHeaderInterceptorTests {
@Test
public void intercept() throws IOException {
ClientHttpResponse result = this.interceptor.intercept(this.request, this.body,
this.execution);
ClientHttpResponse result = this.interceptor.intercept(this.request, this.body, this.execution);
assertThat(this.request.getHeaders().getFirst(this.name)).isEqualTo(this.value);
assertThat(result).isEqualTo(this.response);
}
@@ -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,25 +47,21 @@ public class LocalDebugPortAvailableConditionTests {
public void portAvailable() throws Exception {
ConditionOutcome outcome = getOutcome();
assertThat(outcome.isMatch()).isTrue();
assertThat(outcome.getMessage())
.isEqualTo("Local Debug Port Condition found local debug port");
assertThat(outcome.getMessage()).isEqualTo("Local Debug Port Condition found local debug port");
}
@Test
public void portInUse() throws Exception {
final ServerSocket serverSocket = ServerSocketFactory.getDefault()
.createServerSocket(this.port);
final ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(this.port);
ConditionOutcome outcome = getOutcome();
serverSocket.close();
assertThat(outcome.isMatch()).isFalse();
assertThat(outcome.getMessage())
.isEqualTo("Local Debug Port Condition did not find local debug port");
assertThat(outcome.getMessage()).isEqualTo("Local Debug Port Condition did not find local debug port");
}
private ConditionOutcome getOutcome() {
MockEnvironment environment = new MockEnvironment();
EnvironmentTestUtils.addEnvironment(environment,
"spring.devtools.remote.debug.local-port:" + this.port);
EnvironmentTestUtils.addEnvironment(environment, "spring.devtools.remote.debug.local-port:" + this.port);
ConditionContext context = mock(ConditionContext.class);
given(context.getEnvironment()).willReturn(environment);
ConditionOutcome outcome = this.condition.getMatchOutcome(context, null);
@@ -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.
@@ -84,10 +84,8 @@ public class RemoteClientConfigurationTests {
@Test
public void warnIfDebugAndRestartDisabled() throws Exception {
configure("spring.devtools.remote.debug.enabled:false",
"spring.devtools.remote.restart.enabled:false");
assertThat(this.output.toString())
.contains("Remote restart and debug are both disabled");
configure("spring.devtools.remote.debug.enabled:false", "spring.devtools.remote.restart.enabled:false");
assertThat(this.output.toString()).contains("Remote restart and debug are both disabled");
}
@Test
@@ -115,8 +113,7 @@ public class RemoteClientConfigurationTests {
Set<ChangedFiles> changeSet = new HashSet<ChangedFiles>();
ClassPathChangedEvent event = new ClassPathChangedEvent(this, changeSet, false);
this.context.publishEvent(event);
LiveReloadConfiguration configuration = this.context
.getBean(LiveReloadConfiguration.class);
LiveReloadConfiguration configuration = this.context.getBean(LiveReloadConfiguration.class);
configuration.getExecutor().shutdown();
configuration.getExecutor().awaitTermination(2, TimeUnit.SECONDS);
LiveReloadServer server = this.context.getBean(LiveReloadServer.class);
@@ -152,13 +149,11 @@ public class RemoteClientConfigurationTests {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
new RestartScopeInitializer().initialize(this.context);
this.context.register(Config.class, RemoteClientConfiguration.class);
String remoteUrlProperty = "remoteUrl:" + remoteUrl + ":"
+ RemoteClientConfigurationTests.remotePort;
String remoteUrlProperty = "remoteUrl:" + remoteUrl + ":" + RemoteClientConfigurationTests.remotePort;
EnvironmentTestUtils.addEnvironment(this.context, remoteUrlProperty);
EnvironmentTestUtils.addEnvironment(this.context, pairs);
if (setSecret) {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.devtools.remote.secret:secret");
EnvironmentTestUtils.addEnvironment(this.context, "spring.devtools.remote.secret:secret");
}
this.context.refresh();
}
@@ -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.
@@ -103,12 +103,10 @@ public class DispatcherFilterTests {
public void handledByDispatcher() throws Exception {
HttpServletRequest request = new MockHttpServletRequest("GET", "/hello");
HttpServletResponse response = new MockHttpServletResponse();
willReturn(true).given(this.dispatcher).handle(any(ServerHttpRequest.class),
any(ServerHttpResponse.class));
willReturn(true).given(this.dispatcher).handle(any(ServerHttpRequest.class), any(ServerHttpResponse.class));
this.filter.doFilter(request, response, this.chain);
verifyZeroInteractions(this.chain);
verify(this.dispatcher).handle(this.serverRequestCaptor.capture(),
this.serverResponseCaptor.capture());
verify(this.dispatcher).handle(this.serverRequestCaptor.capture(), this.serverResponseCaptor.capture());
ServerHttpRequest dispatcherRequest = this.serverRequestCaptor.getValue();
ServletServerHttpRequest actualRequest = (ServletServerHttpRequest) dispatcherRequest;
ServerHttpResponse dispatcherResponse = this.serverResponseCaptor.getValue();
@@ -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.
@@ -91,13 +91,11 @@ public class DispatcherTests {
@Test
public void accessManagerVetoRequest() throws Exception {
given(this.accessManager.isAllowed(any(ServerHttpRequest.class)))
.willReturn(false);
given(this.accessManager.isAllowed(any(ServerHttpRequest.class))).willReturn(false);
HandlerMapper mapper = mock(HandlerMapper.class);
Handler handler = mock(Handler.class);
given(mapper.getHandler(any(ServerHttpRequest.class))).willReturn(handler);
Dispatcher dispatcher = new Dispatcher(this.accessManager,
Collections.singleton(mapper));
Dispatcher dispatcher = new Dispatcher(this.accessManager, Collections.singleton(mapper));
dispatcher.handle(this.serverRequest, this.serverResponse);
verifyZeroInteractions(handler);
assertThat(this.response.getStatus()).isEqualTo(403);
@@ -105,23 +103,19 @@ public class DispatcherTests {
@Test
public void accessManagerAllowRequest() throws Exception {
given(this.accessManager.isAllowed(any(ServerHttpRequest.class)))
.willReturn(true);
given(this.accessManager.isAllowed(any(ServerHttpRequest.class))).willReturn(true);
HandlerMapper mapper = mock(HandlerMapper.class);
Handler handler = mock(Handler.class);
given(mapper.getHandler(any(ServerHttpRequest.class))).willReturn(handler);
Dispatcher dispatcher = new Dispatcher(this.accessManager,
Collections.singleton(mapper));
Dispatcher dispatcher = new Dispatcher(this.accessManager, Collections.singleton(mapper));
dispatcher.handle(this.serverRequest, this.serverResponse);
verify(handler).handle(this.serverRequest, this.serverResponse);
}
@Test
public void ordersMappers() throws Exception {
HandlerMapper mapper1 = mock(HandlerMapper.class,
withSettings().extraInterfaces(Ordered.class));
HandlerMapper mapper2 = mock(HandlerMapper.class,
withSettings().extraInterfaces(Ordered.class));
HandlerMapper mapper1 = mock(HandlerMapper.class, withSettings().extraInterfaces(Ordered.class));
HandlerMapper mapper2 = mock(HandlerMapper.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) mapper1).getOrder()).willReturn(1);
given(((Ordered) mapper2).getOrder()).willReturn(2);
List<HandlerMapper> mappers = Arrays.asList(mapper2, mapper1);
@@ -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.
@@ -74,8 +74,7 @@ public class UrlHandlerMapperTests {
@Test
public void ignoresDifferentUrl() throws Exception {
UrlHandlerMapper mapper = new UrlHandlerMapper("/tunnel", this.handler);
HttpServletRequest servletRequest = new MockHttpServletRequest("GET",
"/tunnel/other");
HttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/tunnel/other");
ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
assertThat(mapper.getHandler(request)).isNull();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 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 ChangeableUrlsTests {
@Test
public void skipsUrls() throws Exception {
ChangeableUrls urls = ChangeableUrls.fromUrls(makeUrl("spring-boot"),
makeUrl("spring-boot-autoconfigure"), makeUrl("spring-boot-actuator"),
makeUrl("spring-boot-starter"),
ChangeableUrls urls = ChangeableUrls.fromUrls(makeUrl("spring-boot"), makeUrl("spring-boot-autoconfigure"),
makeUrl("spring-boot-actuator"), makeUrl("spring-boot-starter"),
makeUrl("spring-boot-starter-some-thing"));
assertThat(urls.size()).isEqualTo(0);
}
@@ -76,19 +75,16 @@ public class ChangeableUrlsTests {
public void urlsFromJarClassPathAreConsidered() throws Exception {
File relative = this.temporaryFolder.newFolder();
URL absoluteUrl = this.temporaryFolder.newFolder().toURI().toURL();
File jarWithClassPath = makeJarFileWithUrlsInManifestClassPath(
"project-core/target/classes/", "project-web/target/classes/",
"does-not-exist/target/classes", relative.getName() + "/", absoluteUrl);
new File(jarWithClassPath.getParentFile(), "project-core/target/classes")
.mkdirs();
File jarWithClassPath = makeJarFileWithUrlsInManifestClassPath("project-core/target/classes/",
"project-web/target/classes/", "does-not-exist/target/classes", relative.getName() + "/", absoluteUrl);
new File(jarWithClassPath.getParentFile(), "project-core/target/classes").mkdirs();
new File(jarWithClassPath.getParentFile(), "project-web/target/classes").mkdirs();
ChangeableUrls urls = ChangeableUrls
.fromUrlClassLoader(new URLClassLoader(new URL[] {
jarWithClassPath.toURI().toURL(), makeJarFileWithNoManifest() }));
ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(
new URLClassLoader(new URL[] { jarWithClassPath.toURI().toURL(), makeJarFileWithNoManifest() }));
assertThat(urls.toList()).containsExactly(
new URL(jarWithClassPath.toURI().toURL(), "project-core/target/classes/"),
new URL(jarWithClassPath.toURI().toURL(), "project-web/target/classes/"),
relative.toURI().toURL(), absoluteUrl);
new URL(jarWithClassPath.toURI().toURL(), "project-web/target/classes/"), relative.toURI().toURL(),
absoluteUrl);
}
private URL makeUrl(String name) throws IOException {
@@ -103,8 +99,7 @@ public class ChangeableUrlsTests {
private File makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Exception {
File classpathJar = this.temporaryFolder.newFile("classpath.jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),
"1.0");
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
manifest.getMainAttributes().putValue(Attributes.Name.CLASS_PATH.toString(),
StringUtils.arrayToDelimitedString(urls, " "));
new JarOutputStream(new FileOutputStream(classpathJar), manifest).close();
@@ -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.
@@ -64,8 +64,7 @@ public class ClassLoaderFilesResourcePatternResolverTests {
@Before
public void setup() {
this.files = new ClassLoaderFiles();
this.resolver = new ClassLoaderFilesResourcePatternResolver(
new GenericApplicationContext(), this.files);
this.resolver = new ClassLoaderFilesResourcePatternResolver(new GenericApplicationContext(), this.files);
}
@Test
@@ -80,10 +79,8 @@ public class ClassLoaderFilesResourcePatternResolverTests {
}
@Test
public void getResourceWhenHasServletContextShouldReturnServletResource()
throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext(
new MockServletContext());
public void getResourceWhenHasServletContextShouldReturnServletResource() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
Resource resource = this.resolver.getResource("index.html");
assertThat(resource).isNotNull().isInstanceOf(ServletContextResource.class);
@@ -93,19 +90,16 @@ public class ClassLoaderFilesResourcePatternResolverTests {
public void getResourceWhenDeletedShouldReturnDeletedResource() throws Exception {
File folder = this.temp.newFolder();
File file = createFile(folder, "name.class");
this.files.addFile(folder.getName(), "name.class",
new ClassLoaderFile(Kind.DELETED, null));
this.files.addFile(folder.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
Resource resource = this.resolver.getResource("file:" + file.getAbsolutePath());
assertThat(resource).isNotNull()
.isInstanceOf(DeletedClassLoaderFileResource.class);
assertThat(resource).isNotNull().isInstanceOf(DeletedClassLoaderFileResource.class);
}
@Test
public void getResourcesShouldReturnResources() throws Exception {
File folder = this.temp.newFolder();
createFile(folder, "name.class");
Resource[] resources = this.resolver
.getResources("file:" + folder.getAbsolutePath() + "/**");
Resource[] resources = this.resolver.getResources("file:" + folder.getAbsolutePath() + "/**");
assertThat(resources).isNotEmpty();
}
@@ -113,10 +107,8 @@ public class ClassLoaderFilesResourcePatternResolverTests {
public void getResourcesWhenDeletedShouldFilterDeleted() throws Exception {
File folder = this.temp.newFolder();
createFile(folder, "name.class");
this.files.addFile(folder.getName(), "name.class",
new ClassLoaderFile(Kind.DELETED, null));
Resource[] resources = this.resolver
.getResources("file:" + folder.getAbsolutePath() + "/**");
this.files.addFile(folder.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
Resource[] resources = this.resolver.getResources("file:" + folder.getAbsolutePath() + "/**");
assertThat(resources).isEmpty();
}
@@ -144,8 +136,7 @@ public class ClassLoaderFilesResourcePatternResolverTests {
@Test
public void customResourceLoaderIsUsedInWebApplication() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext(
new MockServletContext());
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
ResourceLoader resourceLoader = mock(ResourceLoader.class);
context.setResourceLoader(resourceLoader);
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
@@ -155,8 +146,7 @@ public class ClassLoaderFilesResourcePatternResolverTests {
@Test
public void customProtocolResolverIsUsedInWebApplication() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext(
new MockServletContext());
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
Resource resource = mock(Resource.class);
ProtocolResolver resolver = mockProtocolResolver("foo:some-file.txt", resource);
context.addProtocolResolver(resolver);
@@ -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.
@@ -62,8 +62,7 @@ public class DefaultRestartInitializerTests {
@Test
public void threadNotUsingAppClassLoader() throws Exception {
MockRestartInitializer initializer = new MockRestartInitializer(false);
ClassLoader classLoader = new MockLauncherClassLoader(
getClass().getClassLoader());
ClassLoader classLoader = new MockLauncherClassLoader(getClass().getClassLoader());
Thread thread = new Thread();
thread.setName("main");
thread.setContextClassLoader(classLoader);
@@ -88,8 +87,7 @@ public class DefaultRestartInitializerTests {
private void testSkipStack(String className, boolean expected) {
MockRestartInitializer initializer = new MockRestartInitializer(true);
StackTraceElement element = new StackTraceElement(className, "someMethod",
"someFile", 123);
StackTraceElement element = new StackTraceElement(className, "someMethod", "someFile", 123);
assertThat(initializer.isSkippedStackElement(element)).isEqualTo(expected);
}
@@ -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.
@@ -62,8 +62,7 @@ public class MainMethodTests {
}
}).test();
assertThat(method.getMethod()).isEqualTo(this.actualMain);
assertThat(method.getDeclaringClassName())
.isEqualTo(this.actualMain.getDeclaringClass().getName());
assertThat(method.getDeclaringClassName()).isEqualTo(this.actualMain.getDeclaringClass().getName());
}
@Test
@@ -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.
@@ -63,23 +63,21 @@ public class MockRestarter implements TestRule {
private void setup() {
Restarter.setInstance(this.mock);
given(this.mock.getInitialUrls()).willReturn(new URL[] {});
given(this.mock.getOrAddAttribute(anyString(), (ObjectFactory) any()))
.willAnswer(new Answer<Object>() {
given(this.mock.getOrAddAttribute(anyString(), (ObjectFactory) any())).willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String name = (String) invocation.getArguments()[0];
ObjectFactory factory = (ObjectFactory) invocation
.getArguments()[1];
Object attribute = MockRestarter.this.attributes.get(name);
if (attribute == null) {
attribute = factory.getObject();
MockRestarter.this.attributes.put(name, attribute);
}
return attribute;
}
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String name = (String) invocation.getArguments()[0];
ObjectFactory factory = (ObjectFactory) invocation.getArguments()[1];
Object attribute = MockRestarter.this.attributes.get(name);
if (attribute == null) {
attribute = factory.getObject();
MockRestarter.this.attributes.put(name, attribute);
}
return attribute;
}
});
});
given(this.mock.getThreadFactory()).willReturn(new ThreadFactory() {
@Override
@@ -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.
@@ -50,8 +50,7 @@ public class OnInitializedRestarterConditionTests {
@Test
public void noInstance() throws Exception {
Restarter.clearInstance();
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
Config.class);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
assertThat(context.containsBean("bean")).isFalse();
context.close();
}
@@ -59,8 +58,7 @@ public class OnInitializedRestarterConditionTests {
@Test
public void noInitialization() throws Exception {
Restarter.initialize(new String[0], false, RestartInitializer.NONE);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
Config.class);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
assertThat(context.containsBean("bean")).isFalse();
context.close();
}
@@ -87,8 +85,7 @@ public class OnInitializedRestarterConditionTests {
RestartInitializer initializer = mock(RestartInitializer.class);
given(initializer.getInitialUrls((Thread) any())).willReturn(new URL[0]);
Restarter.initialize(new String[0], false, initializer);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
Config.class);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
assertThat(context.containsBean("bean")).isTrue();
context.close();
synchronized (wait) {
@@ -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.
@@ -56,56 +56,46 @@ public class RestartApplicationListenerTests {
@Test
public void isHighestPriority() throws Exception {
assertThat(new RestartApplicationListener().getOrder())
.isEqualTo(Ordered.HIGHEST_PRECEDENCE);
assertThat(new RestartApplicationListener().getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE);
}
@Test
public void initializeWithReady() throws Exception {
testInitialize(false);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args"))
.isEqualTo(ARGS);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args")).isEqualTo(ARGS);
assertThat(Restarter.getInstance().isFinished()).isTrue();
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(),
"rootContexts")).isNotEmpty();
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(), "rootContexts")).isNotEmpty();
}
@Test
public void initializeWithFail() throws Exception {
testInitialize(true);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args"))
.isEqualTo(ARGS);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args")).isEqualTo(ARGS);
assertThat(Restarter.getInstance().isFinished()).isTrue();
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(),
"rootContexts")).isEmpty();
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(), "rootContexts")).isEmpty();
}
@Test
public void disableWithSystemProperty() throws Exception {
System.setProperty(ENABLED_PROPERTY, "false");
testInitialize(false);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "enabled"))
.isEqualTo(false);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "enabled")).isEqualTo(false);
}
private void testInitialize(boolean failed) {
Restarter.clearInstance();
RestartApplicationListener listener = new RestartApplicationListener();
SpringApplication application = new SpringApplication();
ConfigurableApplicationContext context = mock(
ConfigurableApplicationContext.class);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
listener.onApplicationEvent(new ApplicationStartingEvent(application, ARGS));
assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
assertThat(Restarter.getInstance().isFinished()).isFalse();
listener.onApplicationEvent(
new ApplicationPreparedEvent(application, ARGS, context));
listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context));
if (failed) {
listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
context, new RuntimeException()));
listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS, context, new RuntimeException()));
}
else {
listener.onApplicationEvent(
new ApplicationReadyEvent(application, ARGS, context));
listener.onApplicationEvent(new ApplicationReadyEvent(application, ARGS, context));
}
}
@@ -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.
@@ -69,8 +69,7 @@ public class RestartScopeInitializerTests {
}
public static class ScopeTestBean
implements ApplicationListener<ContextRefreshedEvent> {
public static class ScopeTestBean implements ApplicationListener<ContextRefreshedEvent> {
public ScopeTestBean() {
createCount.incrementAndGet();
@@ -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.
@@ -123,8 +123,7 @@ public class RestarterTests {
Restarter restarter = Restarter.getInstance();
restarter.addUrls(urls);
restarter.restart();
ClassLoader classLoader = ((TestableRestarter) restarter)
.getRelaunchClassLoader();
ClassLoader classLoader = ((TestableRestarter) restarter).getRelaunchClassLoader();
assertThat(((URLClassLoader) classLoader).getURLs()[0]).isEqualTo(url);
}
@@ -142,10 +141,8 @@ public class RestarterTests {
Restarter restarter = Restarter.getInstance();
restarter.addClassLoaderFiles(classLoaderFiles);
restarter.restart();
ClassLoader classLoader = ((TestableRestarter) restarter)
.getRelaunchClassLoader();
assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f")))
.isEqualTo("abc".getBytes());
ClassLoader classLoader = ((TestableRestarter) restarter).getRelaunchClassLoader();
assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f"))).isEqualTo("abc".getBytes());
}
@Test
@@ -238,8 +235,7 @@ public class RestarterTests {
}
private static class CloseCountingApplicationListener
implements ApplicationListener<ContextClosedEvent> {
private static class CloseCountingApplicationListener implements ApplicationListener<ContextClosedEvent> {
static int closed = 0;
@@ -255,12 +251,11 @@ public class RestarterTests {
private ClassLoader relaunchClassLoader;
TestableRestarter() {
this(Thread.currentThread(), new String[] {}, false,
new MockRestartInitializer());
this(Thread.currentThread(), new String[] {}, false, new MockRestartInitializer());
}
protected TestableRestarter(Thread thread, String[] args,
boolean forceReferenceCleanup, RestartInitializer initializer) {
protected TestableRestarter(Thread thread, String[] args, boolean forceReferenceCleanup,
RestartInitializer initializer) {
super(thread, args, forceReferenceCleanup, initializer);
}
@@ -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.
@@ -100,8 +100,7 @@ public class SilentExitExceptionHandlerTests {
}
private static class TestSilentExitExceptionHandler
extends SilentExitExceptionHandler {
private static class TestSilentExitExceptionHandler extends SilentExitExceptionHandler {
private boolean nonZeroExitCodePrevented;
@@ -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.
@@ -91,10 +91,8 @@ public class ClassLoaderFilesTests {
this.files.addFile("a", "myfile", file1);
this.files.addFile("b", "myfile", file2);
assertThat(this.files.getFile("myfile")).isEqualTo(file2);
assertThat(this.files.getOrCreateSourceFolder("a").getFiles().size())
.isEqualTo(0);
assertThat(this.files.getOrCreateSourceFolder("b").getFiles().size())
.isEqualTo(1);
assertThat(this.files.getOrCreateSourceFolder("a").getFiles().size()).isEqualTo(0);
assertThat(this.files.getOrCreateSourceFolder("b").getFiles().size()).isEqualTo(1);
}
@Test
@@ -125,8 +123,7 @@ public class ClassLoaderFilesTests {
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(this.files);
oos.close();
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray()));
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
ClassLoaderFiles readObject = (ClassLoaderFiles) ois.readObject();
assertThat(readObject.getFile("myfile")).isNotNull();
}
@@ -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.
@@ -49,8 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("resource")
public class RestartClassLoaderTests {
private static final String PACKAGE = RestartClassLoaderTests.class.getPackage()
.getName();
private static final String PACKAGE = RestartClassLoaderTests.class.getPackage().getName();
private static final String PACKAGE_PATH = PACKAGE.replace('.', '/');
@@ -78,8 +77,7 @@ public class RestartClassLoaderTests {
URL[] urls = new URL[] { url };
this.parentClassLoader = new URLClassLoader(urls, classLoader);
this.updatedFiles = new ClassLoaderFiles();
this.reloadClassLoader = new RestartClassLoader(this.parentClassLoader, urls,
this.updatedFiles);
this.reloadClassLoader = new RestartClassLoader(this.parentClassLoader, urls, this.updatedFiles);
}
private File createSampleJarFile() throws IOException {
@@ -111,22 +109,19 @@ public class RestartClassLoaderTests {
@Test
public void getResourceFromReloadableUrl() throws Exception {
String content = readString(
this.reloadClassLoader.getResourceAsStream(PACKAGE_PATH + "/Sample.txt"));
String content = readString(this.reloadClassLoader.getResourceAsStream(PACKAGE_PATH + "/Sample.txt"));
assertThat(content).startsWith("fromchild");
}
@Test
public void getResourceFromParent() throws Exception {
String content = readString(
this.reloadClassLoader.getResourceAsStream(PACKAGE_PATH + "/Parent.txt"));
String content = readString(this.reloadClassLoader.getResourceAsStream(PACKAGE_PATH + "/Parent.txt"));
assertThat(content).startsWith("fromparent");
}
@Test
public void getResourcesFiltersDuplicates() throws Exception {
List<URL> resources = toList(
this.reloadClassLoader.getResources(PACKAGE_PATH + "/Sample.txt"));
List<URL> resources = toList(this.reloadClassLoader.getResources(PACKAGE_PATH + "/Sample.txt"));
assertThat(resources.size()).isEqualTo(1);
}
@@ -179,8 +174,7 @@ public class RestartClassLoaderTests {
byte[] bytes = "abc".getBytes();
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.MODIFIED, bytes));
List<URL> resources = toList(this.reloadClassLoader.getResources(name));
assertThat(FileCopyUtils.copyToByteArray(resources.get(0).openStream()))
.isEqualTo(bytes);
assertThat(FileCopyUtils.copyToByteArray(resources.get(0).openStream())).isEqualTo(bytes);
}
@Test
@@ -202,8 +196,7 @@ public class RestartClassLoaderTests {
@Test
public void getAddedClass() throws Exception {
String name = PACKAGE_PATH + "/SampleParent.class";
byte[] bytes = FileCopyUtils
.copyToByteArray(getClass().getResourceAsStream("SampleParent.class"));
byte[] bytes = FileCopyUtils.copyToByteArray(getClass().getResourceAsStream("SampleParent.class"));
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.ADDED, bytes));
Class<?> loaded = this.reloadClassLoader.loadClass(PACKAGE + ".SampleParent");
assertThat(loaded.getClassLoader()).isEqualTo(this.reloadClassLoader);
@@ -214,8 +207,7 @@ public class RestartClassLoaderTests {
}
private <T> List<T> toList(Enumeration<T> enumeration) {
return (enumeration != null) ? Collections.list(enumeration)
: Collections.<T>emptyList();
return (enumeration != null) ? Collections.list(enumeration) : Collections.<T>emptyList();
}
}
@@ -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.
@@ -71,17 +71,13 @@ public class DefaultSourceFolderUrlFilterTests {
@Test
public void skippedProjects() throws Exception {
String sourceFolder = "/Users/me/code/spring-boot-samples/"
+ "spring-boot-sample-devtools";
URL jarUrl = new URL("jar:file:/Users/me/tmp/"
+ "spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar!/");
String sourceFolder = "/Users/me/code/spring-boot-samples/" + "spring-boot-sample-devtools";
URL jarUrl = new URL("jar:file:/Users/me/tmp/" + "spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar!/");
assertThat(this.filter.isMatch(sourceFolder, jarUrl)).isTrue();
URL nestedJarUrl = new URL("jar:file:/Users/me/tmp/"
+ "spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar!/"
URL nestedJarUrl = new URL("jar:file:/Users/me/tmp/" + "spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar!/"
+ "lib/spring-boot-1.3.0.BUILD-SNAPSHOT.jar!/");
assertThat(this.filter.isMatch(sourceFolder, nestedJarUrl)).isFalse();
URL fileUrl = new URL("file:/Users/me/tmp/"
+ "spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar");
URL fileUrl = new URL("file:/Users/me/tmp/" + "spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar");
assertThat(this.filter.isMatch(sourceFolder, fileUrl)).isTrue();
}
@@ -92,14 +88,12 @@ public class DefaultSourceFolderUrlFilterTests {
doTest(sourcePostfix, "my-module.other", false);
}
private void doTest(String sourcePostfix, String moduleRoot, boolean expected)
throws MalformedURLException {
private void doTest(String sourcePostfix, String moduleRoot, boolean expected) throws MalformedURLException {
String sourceFolder = SOURCE_ROOT + sourcePostfix;
for (String postfix : COMMON_POSTFIXES) {
for (URL url : getUrls(moduleRoot + postfix)) {
boolean match = this.filter.isMatch(sourceFolder, url);
assertThat(match).as(url + " against " + sourceFolder)
.isEqualTo(expected);
assertThat(match).as(url + " against " + sourceFolder).isEqualTo(expected);
}
}
}
@@ -109,10 +103,8 @@ public class DefaultSourceFolderUrlFilterTests {
urls.add(new URL("file:/some/path/" + name));
urls.add(new URL("file:/some/path/" + name + "!/"));
for (String postfix : COMMON_POSTFIXES) {
urls.add(new URL(
"jar:file:/some/path/lib-module" + postfix + "!/lib/" + name));
urls.add(new URL(
"jar:file:/some/path/lib-module" + postfix + "!/lib/" + name + "!/"));
urls.add(new URL("jar:file:/some/path/lib-module" + postfix + "!/lib/" + name));
urls.add(new URL("jar:file:/some/path/lib-module" + postfix + "!/lib/" + name + "!/"));
}
return urls;
}
@@ -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.
@@ -87,8 +87,7 @@ public class HttpRestartServerTests {
files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
byte[] bytes = serialize(files);
request.setContent(bytes);
this.server.handle(new ServletServerHttpRequest(request),
new ServletServerHttpResponse(response));
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
@@ -98,8 +97,7 @@ public class HttpRestartServerTests {
public void sendNoContent() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
this.server.handle(new ServletServerHttpRequest(request),
new ServletServerHttpResponse(response));
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verifyZeroInteractions(this.delegate);
assertThat(response.getStatus()).isEqualTo(500);
@@ -110,8 +108,7 @@ public class HttpRestartServerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setContent(new byte[] { 0, 0, 0 });
this.server.handle(new ServletServerHttpRequest(request),
new ServletServerHttpResponse(response));
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verifyZeroInteractions(this.delegate);
assertThat(response.getStatus()).isEqualTo(500);
}
@@ -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.
@@ -63,8 +63,7 @@ public class RestartServerTests {
URL url3 = new URL("file:/proj/module-c.jar!/");
URL url4 = new URL("file:/proj/module-d.jar!/");
URLClassLoader classLoaderA = new URLClassLoader(new URL[] { url1, url2 });
URLClassLoader classLoaderB = new URLClassLoader(new URL[] { url3, url4 },
classLoaderA);
URLClassLoader classLoaderB = new URLClassLoader(new URL[] { url3, url4 }, classLoaderA);
SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
MockRestartServer server = new MockRestartServer(filter, classLoaderB);
ClassLoaderFiles files = new ClassLoaderFiles();
@@ -117,8 +116,7 @@ public class RestartServerTests {
private static class MockRestartServer extends RestartServer {
MockRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter,
ClassLoader classLoader) {
MockRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter, ClassLoader classLoader) {
super(sourceFolderUrlFilter, classLoader);
}
@@ -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.
@@ -36,13 +36,11 @@ public class DevToolsSettingsTests {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private static final String ROOT = DevToolsSettingsTests.class.getPackage().getName()
.replace('.', '/') + "/";
private static final String ROOT = DevToolsSettingsTests.class.getPackage().getName().replace('.', '/') + "/";
@Test
public void includePatterns() throws Exception {
DevToolsSettings settings = DevToolsSettings
.load(ROOT + "spring-devtools-include.properties");
DevToolsSettings settings = DevToolsSettings.load(ROOT + "spring-devtools-include.properties");
assertThat(settings.isRestartInclude(new URL("file://test/a"))).isTrue();
assertThat(settings.isRestartInclude(new URL("file://test/b"))).isTrue();
assertThat(settings.isRestartInclude(new URL("file://test/c"))).isFalse();
@@ -50,8 +48,7 @@ public class DevToolsSettingsTests {
@Test
public void excludePatterns() throws Exception {
DevToolsSettings settings = DevToolsSettings
.load(ROOT + "spring-devtools-exclude.properties");
DevToolsSettings settings = DevToolsSettings.load(ROOT + "spring-devtools-exclude.properties");
assertThat(settings.isRestartExclude(new URL("file://test/a"))).isTrue();
assertThat(settings.isRestartExclude(new URL("file://test/b"))).isTrue();
assertThat(settings.isRestartExclude(new URL("file://test/c"))).isFalse();
@@ -61,12 +58,10 @@ public class DevToolsSettingsTests {
public void defaultIncludePatterns() throws Exception {
DevToolsSettings settings = DevToolsSettings.get();
assertThat(settings.isRestartExclude(makeUrl("spring-boot"))).isTrue();
assertThat(settings.isRestartExclude(makeUrl("spring-boot-autoconfigure")))
.isTrue();
assertThat(settings.isRestartExclude(makeUrl("spring-boot-autoconfigure"))).isTrue();
assertThat(settings.isRestartExclude(makeUrl("spring-boot-actuator"))).isTrue();
assertThat(settings.isRestartExclude(makeUrl("spring-boot-starter"))).isTrue();
assertThat(settings.isRestartExclude(makeUrl("spring-boot-starter-some-thing")))
.isTrue();
assertThat(settings.isRestartExclude(makeUrl("spring-boot-starter-some-thing"))).isTrue();
}
private URL makeUrl(String name) throws IOException {
@@ -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 MockClientHttpRequestFactory implements ClientHttpRequestFactory {
private List<MockClientHttpRequest> executedRequests = new ArrayList<MockClientHttpRequest>();
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod)
throws IOException {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new MockRequest(uri, httpMethod);
}
@@ -95,8 +94,7 @@ public class MockClientHttpRequestFactory implements ClientHttpRequestFactory {
if (response == null) {
response = new Response(0, null, HttpStatus.GONE);
}
return ((Response) response)
.asHttpResponse(MockClientHttpRequestFactory.this.seq);
return ((Response) response).asHttpResponse(MockClientHttpRequestFactory.this.seq);
}
}
@@ -116,15 +114,12 @@ public class MockClientHttpRequestFactory implements ClientHttpRequestFactory {
}
public ClientHttpResponse asHttpResponse(AtomicLong seq) {
MockClientHttpResponse httpResponse = new MockClientHttpResponse(this.payload,
this.status);
MockClientHttpResponse httpResponse = new MockClientHttpResponse(this.payload, this.status);
waitForDelay();
if (this.payload != null) {
httpResponse.getHeaders().setContentLength(this.payload.length);
httpResponse.getHeaders()
.setContentType(MediaType.APPLICATION_OCTET_STREAM);
httpResponse.getHeaders().add("x-seq",
Long.toString(seq.incrementAndGet()));
httpResponse.getHeaders().setContentType(MediaType.APPLICATION_OCTET_STREAM);
httpResponse.getHeaders().add("x-seq", Long.toString(seq.incrementAndGet()));
}
return httpResponse;
}
@@ -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.
@@ -154,8 +154,7 @@ public class HttpTunnelConnectionTests {
this.requestFactory.willRespond(HttpStatus.SERVICE_UNAVAILABLE);
TunnelChannel tunnel = openTunnel(true);
assertThat(tunnel.isOpen()).isFalse();
this.outputCapture.expect(containsString(
"Did you forget to start it with remote debugging enabled?"));
this.outputCapture.expect(containsString("Did you forget to start it with remote debugging enabled?"));
}
@Test
@@ -163,9 +162,8 @@ public class HttpTunnelConnectionTests {
this.requestFactory.willRespond(new ConnectException());
TunnelChannel tunnel = openTunnel(true);
assertThat(tunnel.isOpen()).isFalse();
this.outputCapture.expect(containsString(
"Failed to connect to remote application at http://localhost:"
+ this.port));
this.outputCapture
.expect(containsString("Failed to connect to remote application at http://localhost:" + this.port));
}
private void write(TunnelChannel channel, String string) throws IOException {
@@ -173,8 +171,7 @@ public class HttpTunnelConnectionTests {
}
private TunnelChannel openTunnel(boolean singleThreaded) throws Exception {
HttpTunnelConnection connection = new HttpTunnelConnection(this.url,
this.requestFactory,
HttpTunnelConnection connection = new HttpTunnelConnection(this.url, this.requestFactory,
(singleThreaded ? new CurrentThreadExecutor() : null));
return connection.open(this.incomingChannel, this.closeable);
}
@@ -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 TunnelClientTests {
public void typicalTraffic() throws Exception {
TunnelClient client = new TunnelClient(this.listenPort, this.tunnelConnection);
client.start();
SocketChannel channel = SocketChannel
.open(new InetSocketAddress(this.listenPort));
SocketChannel channel = SocketChannel.open(new InetSocketAddress(this.listenPort));
channel.write(ByteBuffer.wrap("hello".getBytes()));
ByteBuffer buffer = ByteBuffer.allocate(5);
channel.read(buffer);
@@ -82,8 +81,7 @@ public class TunnelClientTests {
public void socketChannelClosedTriggersTunnelClose() throws Exception {
TunnelClient client = new TunnelClient(this.listenPort, this.tunnelConnection);
client.start();
SocketChannel channel = SocketChannel
.open(new InetSocketAddress(this.listenPort));
SocketChannel channel = SocketChannel.open(new InetSocketAddress(this.listenPort));
Thread.sleep(200);
channel.close();
client.getServerThread().stopAcceptingConnections();
@@ -96,8 +94,7 @@ public class TunnelClientTests {
public void stopTriggersTunnelClose() throws Exception {
TunnelClient client = new TunnelClient(this.listenPort, this.tunnelConnection);
client.start();
SocketChannel channel = SocketChannel
.open(new InetSocketAddress(this.listenPort));
SocketChannel channel = SocketChannel.open(new InetSocketAddress(this.listenPort));
Thread.sleep(200);
client.stop();
assertThat(this.tunnelConnection.getOpenedTimes()).isEqualTo(1);
@@ -111,8 +108,7 @@ public class TunnelClientTests {
TunnelClientListener listener = mock(TunnelClientListener.class);
client.addListener(listener);
client.start();
SocketChannel channel = SocketChannel
.open(new InetSocketAddress(this.listenPort));
SocketChannel channel = SocketChannel.open(new InetSocketAddress(this.listenPort));
Thread.sleep(200);
channel.close();
client.getServerThread().stopAcceptingConnections();
@@ -130,8 +126,7 @@ public class TunnelClientTests {
private int openedTimes;
@Override
public WritableByteChannel open(WritableByteChannel incomingChannel,
Closeable closeable) throws Exception {
public WritableByteChannel open(WritableByteChannel incomingChannel, Closeable closeable) throws Exception {
this.openedTimes++;
this.open = true;
return new TunnelChannel(incomingChannel, closeable);
@@ -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.
@@ -120,8 +120,7 @@ public class HttpTunnelPayloadTests {
@Test
public void getPayloadData() throws Exception {
ReadableByteChannel channel = Channels
.newChannel(new ByteArrayInputStream("hello".getBytes()));
ReadableByteChannel channel = Channels.newChannel(new ByteArrayInputStream("hello".getBytes()));
ByteBuffer payloadData = HttpTunnelPayload.getPayloadData(channel);
ByteArrayOutputStream out = new ByteArrayOutputStream();
WritableByteChannel writeChannel = Channels.newChannel(out);
@@ -134,8 +133,7 @@ public class HttpTunnelPayloadTests {
@Test
public void getPayloadDataWithTimeout() throws Exception {
ReadableByteChannel channel = mock(ReadableByteChannel.class);
given(channel.read(any(ByteBuffer.class)))
.willThrow(new SocketTimeoutException());
given(channel.read(any(ByteBuffer.class))).willThrow(new SocketTimeoutException());
ByteBuffer payload = HttpTunnelPayload.getPayloadData(channel);
assertThat(payload).isNull();
}
@@ -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.
@@ -304,11 +304,9 @@ public class HttpTunnelServerTests {
testHttpConnectionNonAsync(100);
}
private void testHttpConnectionNonAsync(long sleepBeforeResponse)
throws IOException, InterruptedException {
private void testHttpConnectionNonAsync(long sleepBeforeResponse) throws IOException, InterruptedException {
ServerHttpRequest request = mock(ServerHttpRequest.class);
given(request.getAsyncRequestControl(this.response))
.willThrow(new IllegalArgumentException());
given(request.getAsyncRequestControl(this.response)).willThrow(new IllegalArgumentException());
final HttpConnection connection = new HttpConnection(request, this.response);
final AtomicBoolean responded = new AtomicBoolean();
Thread connectionThread = new Thread() {
@@ -381,8 +379,7 @@ public class HttpTunnelServerTests {
@Override
public int read(ByteBuffer dst) throws IOException {
try {
ByteBuffer bytes = this.outgoing.pollFirst(this.timeout,
TimeUnit.MILLISECONDS);
ByteBuffer bytes = this.outgoing.pollFirst(this.timeout, TimeUnit.MILLISECONDS);
if (bytes == null) {
throw new SocketTimeoutException();
}
@@ -452,17 +449,14 @@ public class HttpTunnelServerTests {
}
public MockHttpServletRequest getServletRequest() {
return (MockHttpServletRequest) ((ServletServerHttpRequest) getRequest())
.getServletRequest();
return (MockHttpServletRequest) ((ServletServerHttpRequest) getRequest()).getServletRequest();
}
public MockHttpServletResponse getServletResponse() {
return (MockHttpServletResponse) ((ServletServerHttpResponse) getResponse())
.getServletResponse();
return (MockHttpServletResponse) ((ServletServerHttpResponse) getResponse()).getServletResponse();
}
public void verifyReceived(String expectedContent, int expectedSeq)
throws Exception {
public void verifyReceived(String expectedContent, int expectedSeq) throws Exception {
waitForServletResponse();
MockHttpServletResponse resp = getServletResponse();
assertThat(resp.getContentAsString()).isEqualTo(expectedContent);
@@ -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.
@@ -154,8 +154,7 @@ public class SocketTargetServerConnectionTests {
}
}
if (MockServer.this.expect != null) {
ByteBuffer buffer = ByteBuffer
.allocate(MockServer.this.expect.length);
ByteBuffer buffer = ByteBuffer.allocate(MockServer.this.expect.length);
while (buffer.hasRemaining()) {
channel.read(buffer);
}