Use AssertJ in spring-boot-devtools
See gh-5083
This commit is contained in:
@@ -27,10 +27,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RemoteUrlPropertyExtractor}.
|
||||
@@ -73,17 +70,17 @@ public class RemoteUrlPropertyExtractorTests {
|
||||
@Test
|
||||
public void validUrl() throws Exception {
|
||||
ApplicationContext context = doTest("http://localhost:8080");
|
||||
assertThat(context.getEnvironment().getProperty("remoteUrl"),
|
||||
equalTo("http://localhost:8080"));
|
||||
assertThat(context.getEnvironment().getProperty("spring.thymeleaf.cache"),
|
||||
is(nullValue()));
|
||||
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"),
|
||||
equalTo("http://localhost:8080"));
|
||||
assertThat(context.getEnvironment().getProperty("remoteUrl"))
|
||||
.isEqualTo("http://localhost:8080");
|
||||
}
|
||||
|
||||
private ApplicationContext doTest(String... args) {
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.boot.devtools.autoconfigure;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DevToolsProperties}.
|
||||
@@ -34,11 +33,10 @@ public class DevToolsPropertiesTests {
|
||||
public void additionalExcludeKeepsDefaults() {
|
||||
DevToolsProperties.Restart restart = this.devToolsProperties.getRestart();
|
||||
restart.setAdditionalExclude("foo/**,bar/**");
|
||||
assertThat(restart.getAllExclude(),
|
||||
arrayContaining("META-INF/maven/**", "META-INF/resources/**",
|
||||
"resources/**", "static/**", "public/**", "templates/**",
|
||||
"**/*Test.class", "**/*Tests.class", "git.properties", "foo/**",
|
||||
"bar/**"));
|
||||
assertThat(restart.getAllExclude()).containsOnly("META-INF/maven/**",
|
||||
"META-INF/resources/**", "resources/**", "static/**", "public/**",
|
||||
"templates/**", "**/*Test.class", "**/*Tests.class", "git.properties",
|
||||
"foo/**", "bar/**");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +44,7 @@ public class DevToolsPropertiesTests {
|
||||
DevToolsProperties.Restart restart = this.devToolsProperties.getRestart();
|
||||
restart.setExclude("");
|
||||
restart.setAdditionalExclude("foo/**,bar/**");
|
||||
assertThat(restart.getAllExclude(), arrayContaining("foo/**", "bar/**"));
|
||||
assertThat(restart.getAllExclude()).containsOnly("foo/**", "bar/**");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,8 +52,7 @@ public class DevToolsPropertiesTests {
|
||||
DevToolsProperties.Restart restart = this.devToolsProperties.getRestart();
|
||||
restart.setExclude("biz/**");
|
||||
restart.setAdditionalExclude("foo/**,bar/**");
|
||||
assertThat(restart.getAllExclude(),
|
||||
arrayContaining("biz/**", "foo/**", "bar/**"));
|
||||
assertThat(restart.getAllExclude()).containsOnly("biz/**", "foo/**", "bar/**");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
43
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java
Executable file → Normal file
43
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java
Executable file → Normal file
@@ -51,12 +51,7 @@ import org.springframework.session.ExpiringSession;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -94,7 +89,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
this.context = initializeAndRun(Config.class);
|
||||
TemplateResolver resolver = this.context.getBean(TemplateResolver.class);
|
||||
resolver.initialize();
|
||||
assertThat(resolver.isCacheable(), equalTo(false));
|
||||
assertThat(resolver.isCacheable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,7 +97,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
this.context = initializeAndRun(Config.class, "--spring.thymeleaf.cache=true");
|
||||
TemplateResolver resolver = this.context.getBean(TemplateResolver.class);
|
||||
resolver.initialize();
|
||||
assertThat(resolver.isCacheable(), equalTo(true));
|
||||
assertThat(resolver.isCacheable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +109,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
this.context = initializeAndRun(Config.class);
|
||||
TemplateResolver resolver = this.context.getBean(TemplateResolver.class);
|
||||
resolver.initialize();
|
||||
assertThat(resolver.isCacheable(), equalTo(true));
|
||||
assertThat(resolver.isCacheable()).isTrue();
|
||||
}
|
||||
finally {
|
||||
System.setProperty("user.home", userHome);
|
||||
@@ -125,14 +120,14 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
public void resourceCachePeriodIsZero() throws Exception {
|
||||
this.context = initializeAndRun(WebResourcesConfig.class);
|
||||
ResourceProperties properties = this.context.getBean(ResourceProperties.class);
|
||||
assertThat(properties.getCachePeriod(), equalTo(0));
|
||||
assertThat(properties.getCachePeriod()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liveReloadServer() throws Exception {
|
||||
this.context = initializeAndRun(Config.class);
|
||||
LiveReloadServer server = this.context.getBean(LiveReloadServer.class);
|
||||
assertThat(server.isStarted(), equalTo(true));
|
||||
assertThat(server.isStarted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -198,7 +193,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
this.context = initializeAndRun(Config.class);
|
||||
ClassPathFileSystemWatcher watcher = this.context
|
||||
.getBean(ClassPathFileSystemWatcher.class);
|
||||
assertThat(watcher, notNullValue());
|
||||
assertThat(watcher).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,7 +215,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
Object watcher = ReflectionTestUtils.getField(classPathWatcher,
|
||||
"fileSystemWatcher");
|
||||
Object filter = ReflectionTestUtils.getField(watcher, "triggerFilter");
|
||||
assertThat(filter, instanceOf(TriggerFileFilter.class));
|
||||
assertThat(filter).isInstanceOf(TriggerFileFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,9 +231,9 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils
|
||||
.getField(watcher, "folders");
|
||||
assertThat(folders.size(), is(equalTo(2)));
|
||||
assertThat(folders, hasKey(new File("src/main/java").getAbsoluteFile()));
|
||||
assertThat(folders, hasKey(new File("src/test/java").getAbsoluteFile()));
|
||||
assertThat(folders).hasSize(2)
|
||||
.containsKey(new File("src/main/java").getAbsoluteFile())
|
||||
.containsKey(new File("src/test/java").getAbsoluteFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -263,14 +258,14 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
this.context = application.run();
|
||||
RedisTemplate<?, ?> redisTemplate = this.context.getBean("sessionRedisTemplate",
|
||||
RedisTemplate.class);
|
||||
assertThat(redisTemplate.getHashKeySerializer(),
|
||||
is(instanceOf(RestartCompatibleRedisSerializer.class)));
|
||||
assertThat(redisTemplate.getHashValueSerializer(),
|
||||
is(instanceOf(RestartCompatibleRedisSerializer.class)));
|
||||
assertThat(redisTemplate.getKeySerializer(),
|
||||
is(instanceOf(RestartCompatibleRedisSerializer.class)));
|
||||
assertThat(redisTemplate.getValueSerializer(),
|
||||
is(instanceOf(RestartCompatibleRedisSerializer.class)));
|
||||
assertThat(redisTemplate.getHashKeySerializer())
|
||||
.isInstanceOf(RestartCompatibleRedisSerializer.class);
|
||||
assertThat(redisTemplate.getHashValueSerializer())
|
||||
.isInstanceOf(RestartCompatibleRedisSerializer.class);
|
||||
assertThat(redisTemplate.getKeySerializer())
|
||||
.isInstanceOf(RestartCompatibleRedisSerializer.class);
|
||||
assertThat(redisTemplate.getValueSerializer())
|
||||
.isInstanceOf(RestartCompatibleRedisSerializer.class);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext initializeAndRun(Class<?> config,
|
||||
|
||||
@@ -47,8 +47,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -204,7 +203,7 @@ public class RemoteDevToolsAutoConfigurationTests {
|
||||
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
|
||||
this.response.setStatus(500);
|
||||
filter.doFilter(this.request, this.response, this.chain);
|
||||
assertThat(this.response.getStatus(), equalTo(200));
|
||||
assertThat(this.response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,17 +215,17 @@ public class RemoteDevToolsAutoConfigurationTests {
|
||||
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
|
||||
this.response.setStatus(500);
|
||||
filter.doFilter(this.request, this.response, this.chain);
|
||||
assertThat(this.response.getStatus(), equalTo(200));
|
||||
assertThat(this.response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
private void assertTunnelInvoked(boolean value) {
|
||||
assertThat(this.context.getBean(MockHttpTunnelServer.class).invoked,
|
||||
equalTo(value));
|
||||
assertThat(this.context.getBean(MockHttpTunnelServer.class).invoked)
|
||||
.isEqualTo(value);
|
||||
}
|
||||
|
||||
private void assertRestartInvoked(boolean value) {
|
||||
assertThat(this.context.getBean(MockHttpRestartServer.class).invoked,
|
||||
equalTo(value));
|
||||
assertThat(this.context.getBean(MockHttpRestartServer.class).invoked)
|
||||
.isEqualTo(value);
|
||||
}
|
||||
|
||||
private void loadContext(String... properties) {
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link TriggerFileFilter}.
|
||||
@@ -49,13 +48,13 @@ public class TriggerFileFilterTests {
|
||||
@Test
|
||||
public void acceptNameMatch() throws Exception {
|
||||
File file = this.temp.newFile("thefile.txt");
|
||||
assertThat(new TriggerFileFilter("thefile.txt").accept(file), equalTo(true));
|
||||
assertThat(new TriggerFileFilter("thefile.txt").accept(file)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotAcceptNameMismatch() throws Exception {
|
||||
File file = this.temp.newFile("notthefile.txt");
|
||||
assertThat(new TriggerFileFilter("thefile.txt").accept(file), equalTo(false));
|
||||
assertThat(new TriggerFileFilter("thefile.txt").accept(file)).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFiles;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ClassPathChangedEvent}.
|
||||
@@ -53,7 +51,7 @@ public class ClassPathChangedEventTests {
|
||||
Set<ChangedFiles> changeSet = new LinkedHashSet<ChangedFiles>();
|
||||
ClassPathChangedEvent event = new ClassPathChangedEvent(this.source, changeSet,
|
||||
false);
|
||||
assertThat(event.getChangeSet(), sameInstance(changeSet));
|
||||
assertThat(event.getChangeSet()).isSameAs(changeSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,9 +59,9 @@ public class ClassPathChangedEventTests {
|
||||
Set<ChangedFiles> changeSet = new LinkedHashSet<ChangedFiles>();
|
||||
ClassPathChangedEvent event;
|
||||
event = new ClassPathChangedEvent(this.source, changeSet, false);
|
||||
assertThat(event.isRestartRequired(), equalTo(false));
|
||||
assertThat(event.isRestartRequired()).isFalse();
|
||||
event = new ClassPathChangedEvent(this.source, changeSet, true);
|
||||
assertThat(event.isRestartRequired(), equalTo(true));
|
||||
assertThat(event.isRestartRequired()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.boot.devtools.filewatch.FileSystemWatcher;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -116,8 +115,8 @@ public class ClassPathFileChangeListenerTests {
|
||||
verify(this.eventPublisher).publishEvent(this.eventCaptor.capture());
|
||||
ClassPathChangedEvent actualEvent = (ClassPathChangedEvent) this.eventCaptor
|
||||
.getValue();
|
||||
assertThat(actualEvent.getChangeSet(), equalTo(changeSet));
|
||||
assertThat(actualEvent.isRestartRequired(), equalTo(restart));
|
||||
assertThat(actualEvent.getChangeSet()).isEqualTo(changeSet);
|
||||
assertThat(actualEvent.isRestartRequired()).isEqualTo(restart);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -84,9 +83,9 @@ public class ClassPathFileSystemWatcherTests {
|
||||
FileCopyUtils.copy("file".getBytes(), classFile);
|
||||
Thread.sleep(1100);
|
||||
List<ClassPathChangedEvent> events = context.getBean(Listener.class).getEvents();
|
||||
assertThat(events.size(), equalTo(1));
|
||||
assertThat(events.size()).isEqualTo(1);
|
||||
assertThat(events.get(0).getChangeSet().iterator().next().getFiles().iterator()
|
||||
.next().getFile(), equalTo(classFile));
|
||||
.next().getFile()).isEqualTo(classFile);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFile;
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link PatternClassPathRestartStrategy}.
|
||||
@@ -90,7 +89,8 @@ public class PatternClassPathRestartStrategyTests {
|
||||
|
||||
private void assertRestartRequired(ClassPathRestartStrategy strategy,
|
||||
String relativeName, boolean expected) {
|
||||
assertThat(strategy.isRestartRequired(mockFile(relativeName)), equalTo(expected));
|
||||
assertThat(strategy.isRestartRequired(mockFile(relativeName)))
|
||||
.isEqualTo(expected);
|
||||
}
|
||||
|
||||
private ChangedFile mockFile(String relativeName) {
|
||||
|
||||
@@ -30,9 +30,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DevToolsHomePropertiesPostProcessor}.
|
||||
@@ -63,7 +61,7 @@ public class DevToolsHomePropertiesPostProcessorTests {
|
||||
ConfigurableEnvironment environment = new MockEnvironment();
|
||||
MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor();
|
||||
postProcessor.postProcessEnvironment(environment, null);
|
||||
assertThat(environment.getProperty("abc"), equalTo("def"));
|
||||
assertThat(environment.getProperty("abc")).isEqualTo("def");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +69,7 @@ public class DevToolsHomePropertiesPostProcessorTests {
|
||||
ConfigurableEnvironment environment = new MockEnvironment();
|
||||
MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor();
|
||||
postProcessor.postProcessEnvironment(environment, null);
|
||||
assertThat(environment.getProperty("abc"), nullValue());
|
||||
assertThat(environment.getProperty("abc")).isNull();
|
||||
}
|
||||
|
||||
private class MockDevToolHomePropertiesPostProcessor
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ChangedFile}.
|
||||
@@ -66,14 +65,14 @@ public class ChangedFileTests {
|
||||
public void getFile() throws Exception {
|
||||
File file = this.temp.newFile();
|
||||
ChangedFile changedFile = new ChangedFile(this.temp.newFolder(), file, Type.ADD);
|
||||
assertThat(changedFile.getFile(), equalTo(file));
|
||||
assertThat(changedFile.getFile()).isEqualTo(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getType() throws Exception {
|
||||
ChangedFile changedFile = new ChangedFile(this.temp.newFolder(),
|
||||
this.temp.newFile(), Type.DELETE);
|
||||
assertThat(changedFile.getType(), equalTo(Type.DELETE));
|
||||
assertThat(changedFile.getType()).isEqualTo(Type.DELETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +81,7 @@ public class ChangedFileTests {
|
||||
File subFolder = new File(folder, "A");
|
||||
File file = new File(subFolder, "B.txt");
|
||||
ChangedFile changedFile = new ChangedFile(folder, file, Type.ADD);
|
||||
assertThat(changedFile.getRelativeName(), equalTo("A/B.txt"));
|
||||
assertThat(changedFile.getRelativeName()).isEqualTo("A/B.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FileSnapshot}.
|
||||
@@ -70,8 +68,8 @@ public class FileSnapshotTests {
|
||||
File fileCopy = new File(file, "x").getParentFile();
|
||||
FileSnapshot snapshot1 = new FileSnapshot(file);
|
||||
FileSnapshot snapshot2 = new FileSnapshot(fileCopy);
|
||||
assertThat(snapshot1, equalTo(snapshot2));
|
||||
assertThat(snapshot1.hashCode(), equalTo(snapshot2.hashCode()));
|
||||
assertThat(snapshot1).isEqualTo(snapshot2);
|
||||
assertThat(snapshot1.hashCode()).isEqualTo(snapshot2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +77,7 @@ public class FileSnapshotTests {
|
||||
File file = createNewFile("abc", MODIFIED);
|
||||
FileSnapshot snapshot1 = new FileSnapshot(file);
|
||||
file.delete();
|
||||
assertThat(snapshot1, not(equalTo(new FileSnapshot(file))));
|
||||
assertThat(snapshot1).isNotEqualTo(new FileSnapshot(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +85,7 @@ public class FileSnapshotTests {
|
||||
File file = createNewFile("abc", MODIFIED);
|
||||
FileSnapshot snapshot1 = new FileSnapshot(file);
|
||||
setupFile(file, "abcd", MODIFIED);
|
||||
assertThat(snapshot1, not(equalTo(new FileSnapshot(file))));
|
||||
assertThat(snapshot1).isNotEqualTo(new FileSnapshot(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +93,7 @@ public class FileSnapshotTests {
|
||||
File file = createNewFile("abc", MODIFIED);
|
||||
FileSnapshot snapshot1 = new FileSnapshot(file);
|
||||
setupFile(file, "abc", MODIFIED + TWO_MINS);
|
||||
assertThat(snapshot1, not(equalTo(new FileSnapshot(file))));
|
||||
assertThat(snapshot1).isNotEqualTo(new FileSnapshot(file));
|
||||
}
|
||||
|
||||
private File createNewFile(String content, long lastModified) throws IOException {
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -37,11 +36,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -112,7 +107,7 @@ public class FileSystemWatcherTests {
|
||||
@Test
|
||||
public void sourceFolderMustExist() throws Exception {
|
||||
File folder = new File("does/not/exist");
|
||||
assertThat(folder.exists(), is(false));
|
||||
assertThat(folder.exists()).isFalse();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Folder '" + folder + "' must exist and must be a directory");
|
||||
@@ -122,7 +117,7 @@ public class FileSystemWatcherTests {
|
||||
@Test
|
||||
public void sourceFolderMustBeADirectory() throws Exception {
|
||||
File folder = new File("pom.xml");
|
||||
assertThat(folder.isFile(), is(true));
|
||||
assertThat(folder.isFile()).isTrue();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Folder 'pom.xml' must exist and must be a directory");
|
||||
this.watcher.addSourceFolder(new File("pom.xml"));
|
||||
@@ -143,7 +138,7 @@ public class FileSystemWatcherTests {
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
|
||||
assertThat(changedFiles.getFiles(), contains(expected));
|
||||
assertThat(changedFiles.getFiles()).contains(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,7 +148,7 @@ public class FileSystemWatcherTests {
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
|
||||
assertThat(changedFiles.getFiles(), contains(expected));
|
||||
assertThat(changedFiles.getFiles()).contains(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +160,7 @@ public class FileSystemWatcherTests {
|
||||
Thread.sleep(200);
|
||||
touch(new File(folder, "test2.txt"));
|
||||
this.watcher.stopAfter(1);
|
||||
assertThat(this.changes.size(), equalTo(2));
|
||||
assertThat(this.changes.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +173,7 @@ public class FileSystemWatcherTests {
|
||||
}
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
assertThat(changedFiles.getFiles().size(), equalTo(10));
|
||||
assertThat(changedFiles.getFiles().size()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,7 +186,7 @@ public class FileSystemWatcherTests {
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
|
||||
assertThat(changedFiles.getFiles(), contains(expected));
|
||||
assertThat(changedFiles.getFiles()).contains(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,17 +200,15 @@ public class FileSystemWatcherTests {
|
||||
File file2 = touch(new File(folder2, "test.txt"));
|
||||
this.watcher.stopAfter(1);
|
||||
Set<ChangedFiles> change = getSingleOnChange();
|
||||
assertThat(change.size(), equalTo(2));
|
||||
assertThat(change.size()).isEqualTo(2);
|
||||
for (ChangedFiles changedFiles : change) {
|
||||
if (changedFiles.getSourceFolder().equals(folder1)) {
|
||||
ChangedFile file = new ChangedFile(folder1, file1, Type.ADD);
|
||||
assertEquals(new HashSet<ChangedFile>(Arrays.asList(file)),
|
||||
changedFiles.getFiles());
|
||||
assertThat(changedFiles.getFiles()).containsOnly(file);
|
||||
}
|
||||
else {
|
||||
ChangedFile file = new ChangedFile(folder2, file2, Type.ADD);
|
||||
assertEquals(new HashSet<ChangedFile>(Arrays.asList(file)),
|
||||
changedFiles.getFiles());
|
||||
assertThat(changedFiles.getFiles()).containsOnly(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,8 +229,8 @@ public class FileSystemWatcherTests {
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
|
||||
assertThat(changedFiles.getFiles(), contains(expected));
|
||||
assertEquals(this.changes.get(0), listener2Changes);
|
||||
assertThat(changedFiles.getFiles()).contains(expected);
|
||||
assertThat(listener2Changes).isEqualTo(this.changes.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,7 +250,7 @@ public class FileSystemWatcherTests {
|
||||
expected.add(new ChangedFile(folder, modify, Type.MODIFY));
|
||||
expected.add(new ChangedFile(folder, delete, Type.DELETE));
|
||||
expected.add(new ChangedFile(folder, add, Type.ADD));
|
||||
assertEquals(expected, actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -277,14 +270,14 @@ public class FileSystemWatcherTests {
|
||||
this.watcher.start();
|
||||
FileCopyUtils.copy("abc".getBytes(), file);
|
||||
Thread.sleep(100);
|
||||
assertThat(this.changes.size(), equalTo(0));
|
||||
assertThat(this.changes.size()).isEqualTo(0);
|
||||
FileCopyUtils.copy("abc".getBytes(), trigger);
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
Set<ChangedFile> actual = changedFiles.getFiles();
|
||||
Set<ChangedFile> expected = new HashSet<ChangedFile>();
|
||||
expected.add(new ChangedFile(folder, file, Type.MODIFY));
|
||||
assertEquals(expected, actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void setupWatcher(long pollingInterval, long quietPeriod) {
|
||||
@@ -306,12 +299,12 @@ public class FileSystemWatcherTests {
|
||||
|
||||
private ChangedFiles getSingleChangedFiles() {
|
||||
Set<ChangedFiles> singleChange = getSingleOnChange();
|
||||
assertThat(singleChange.size(), equalTo(1));
|
||||
assertThat(singleChange.size()).isEqualTo(1);
|
||||
return singleChange.iterator().next();
|
||||
}
|
||||
|
||||
private Set<ChangedFiles> getSingleOnChange() {
|
||||
assertThat(this.changes.size(), equalTo(1));
|
||||
assertThat(this.changes.size()).isEqualTo(1);
|
||||
return this.changes.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FolderSnapshot}.
|
||||
@@ -72,22 +70,22 @@ public class FolderSnapshotTests {
|
||||
@Test
|
||||
public void equalsWhenNothingHasChanged() throws Exception {
|
||||
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
|
||||
assertThat(this.initialSnapshot, equalTo(updatedSnapshot));
|
||||
assertThat(this.initialSnapshot.hashCode(), equalTo(updatedSnapshot.hashCode()));
|
||||
assertThat(this.initialSnapshot).isEqualTo(updatedSnapshot);
|
||||
assertThat(this.initialSnapshot.hashCode()).isEqualTo(updatedSnapshot.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqualsWhenAFileIsAdded() throws Exception {
|
||||
new File(new File(this.folder, "folder1"), "newfile").createNewFile();
|
||||
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
|
||||
assertThat(this.initialSnapshot, not(equalTo(updatedSnapshot)));
|
||||
assertThat(this.initialSnapshot).isNotEqualTo(updatedSnapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqualsWhenAFileIsDeleted() throws Exception {
|
||||
new File(new File(this.folder, "folder1"), "file1").delete();
|
||||
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
|
||||
assertThat(this.initialSnapshot, not(equalTo(updatedSnapshot)));
|
||||
assertThat(this.initialSnapshot).isNotEqualTo(updatedSnapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +93,7 @@ public class FolderSnapshotTests {
|
||||
File file1 = new File(new File(this.folder, "folder1"), "file1");
|
||||
FileCopyUtils.copy("updatedcontent".getBytes(), file1);
|
||||
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
|
||||
assertThat(this.initialSnapshot, not(equalTo(updatedSnapshot)));
|
||||
assertThat(this.initialSnapshot).isNotEqualTo(updatedSnapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,10 +129,10 @@ public class FolderSnapshotTests {
|
||||
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
|
||||
ChangedFiles changedFiles = this.initialSnapshot.getChangedFiles(updatedSnapshot,
|
||||
null);
|
||||
assertThat(changedFiles.getSourceFolder(), equalTo(this.folder));
|
||||
assertThat(getChangedFile(changedFiles, file1).getType(), equalTo(Type.MODIFY));
|
||||
assertThat(getChangedFile(changedFiles, file2).getType(), equalTo(Type.DELETE));
|
||||
assertThat(getChangedFile(changedFiles, newFile).getType(), equalTo(Type.ADD));
|
||||
assertThat(changedFiles.getSourceFolder()).isEqualTo(this.folder);
|
||||
assertThat(getChangedFile(changedFiles, file1).getType()).isEqualTo(Type.MODIFY);
|
||||
assertThat(getChangedFile(changedFiles, file2).getType()).isEqualTo(Type.DELETE);
|
||||
assertThat(getChangedFile(changedFiles, newFile).getType()).isEqualTo(Type.ADD);
|
||||
}
|
||||
|
||||
private ChangedFile getChangedFile(ChangedFiles changedFiles, File file) {
|
||||
|
||||
10
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java
Executable file → Normal file
10
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java
Executable file → Normal file
@@ -54,7 +54,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Simple integration tests for HTTP tunneling.
|
||||
@@ -74,8 +74,8 @@ public class HttpTunnelIntegrationTests {
|
||||
String url = "http://localhost:" + this.config.httpServerPort + "/hello";
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url,
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,8 +83,8 @@ public class HttpTunnelIntegrationTests {
|
||||
String url = "http://localhost:" + this.config.clientPort + "/hello";
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url,
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConnectionInputStream}.
|
||||
@@ -51,7 +50,7 @@ public class ConnectionInputStreamTests {
|
||||
String data = header + "\r\n\r\n" + "content\r\n";
|
||||
ConnectionInputStream inputStream = new ConnectionInputStream(
|
||||
new ByteArrayInputStream(data.getBytes()));
|
||||
assertThat(inputStream.readHeader(), equalTo(header));
|
||||
assertThat(inputStream.readHeader()).isEqualTo(header);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +61,7 @@ public class ConnectionInputStreamTests {
|
||||
ConnectionInputStream inputStream = new ConnectionInputStream(source);
|
||||
byte[] buffer = new byte[bytes.length];
|
||||
inputStream.readFully(buffer, 0, buffer.length);
|
||||
assertThat(buffer, equalTo(bytes));
|
||||
assertThat(buffer).isEqualTo(bytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,8 +22,7 @@ import java.io.OutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -55,7 +54,7 @@ public class ConnectionOutputStreamTests {
|
||||
expected += "Content-Length: 2\r\n";
|
||||
expected += "Connection: close\r\n\r\n";
|
||||
expected += "hi";
|
||||
assertThat(out.toString(), equalTo(expected));
|
||||
assertThat(out.toString()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +66,7 @@ public class ConnectionOutputStreamTests {
|
||||
String expected = "";
|
||||
expected += "A: a\r\n";
|
||||
expected += "B: b\r\n\r\n";
|
||||
assertThat(out.toString(), equalTo(expected));
|
||||
assertThat(out.toString()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link Frame}.
|
||||
@@ -54,15 +53,15 @@ public class FrameTests {
|
||||
@Test
|
||||
public void textPayload() throws Exception {
|
||||
Frame frame = new Frame("abc");
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.TEXT));
|
||||
assertThat(frame.getPayload(), equalTo("abc".getBytes()));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.TEXT);
|
||||
assertThat(frame.getPayload()).isEqualTo("abc".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typedPayload() throws Exception {
|
||||
Frame frame = new Frame(Frame.Type.CLOSE);
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.CLOSE));
|
||||
assertThat(frame.getPayload(), equalTo(new byte[] {}));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.CLOSE);
|
||||
assertThat(frame.getPayload()).isEqualTo(new byte[] {});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +70,7 @@ public class FrameTests {
|
||||
Frame frame = new Frame(payload);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
frame.write(bos);
|
||||
assertThat(bos.toByteArray(), equalTo(new byte[] { (byte) 0x81, 0x01, 0x41 }));
|
||||
assertThat(bos.toByteArray()).isEqualTo(new byte[] { (byte) 0x81, 0x01, 0x41 });
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,13 +80,13 @@ public class FrameTests {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
frame.write(bos);
|
||||
byte[] bytes = bos.toByteArray();
|
||||
assertThat(bytes.length, equalTo(130));
|
||||
assertThat(bytes[0], equalTo((byte) 0x81));
|
||||
assertThat(bytes[1], equalTo((byte) 0x7E));
|
||||
assertThat(bytes[2], equalTo((byte) 0x00));
|
||||
assertThat(bytes[3], equalTo((byte) 126));
|
||||
assertThat(bytes[4], equalTo((byte) 0x41));
|
||||
assertThat(bytes[5], equalTo((byte) 0x41));
|
||||
assertThat(bytes.length).isEqualTo(130);
|
||||
assertThat(bytes[0]).isEqualTo((byte) 0x81);
|
||||
assertThat(bytes[1]).isEqualTo((byte) 0x7E);
|
||||
assertThat(bytes[2]).isEqualTo((byte) 0x00);
|
||||
assertThat(bytes[3]).isEqualTo((byte) 126);
|
||||
assertThat(bytes[4]).isEqualTo((byte) 0x41);
|
||||
assertThat(bytes[5]).isEqualTo((byte) 0x41);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,8 +109,8 @@ public class FrameTests {
|
||||
public void readSmallTextFrame() throws Exception {
|
||||
byte[] bytes = new byte[] { (byte) 0x81, (byte) 0x02, 0x41, 0x41 };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.TEXT));
|
||||
assertThat(frame.getPayload(), equalTo(new byte[] { 0x41, 0x41 }));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.TEXT);
|
||||
assertThat(frame.getPayload()).isEqualTo(new byte[] { 0x41, 0x41 });
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,8 +118,8 @@ public class FrameTests {
|
||||
byte[] bytes = new byte[] { (byte) 0x81, (byte) 0x82, 0x0F, 0x0F, 0x0F, 0x0F,
|
||||
0x4E, 0x4E };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.TEXT));
|
||||
assertThat(frame.getPayload(), equalTo(new byte[] { 0x41, 0x41 }));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.TEXT);
|
||||
assertThat(frame.getPayload()).isEqualTo(new byte[] { 0x41, 0x41 });
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,43 +135,43 @@ public class FrameTests {
|
||||
bytes[6] = 0x0F;
|
||||
bytes[7] = 0x0F;
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.TEXT));
|
||||
assertThat(frame.getPayload(), equalTo(createString(126).getBytes()));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.TEXT);
|
||||
assertThat(frame.getPayload()).isEqualTo(createString(126).getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readContinuation() throws Exception {
|
||||
byte[] bytes = new byte[] { (byte) 0x80, (byte) 0x00 };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.CONTINUATION));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.CONTINUATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readBinary() throws Exception {
|
||||
byte[] bytes = new byte[] { (byte) 0x82, (byte) 0x00 };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.BINARY));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.BINARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readClose() throws Exception {
|
||||
byte[] bytes = new byte[] { (byte) 0x88, (byte) 0x00 };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.CLOSE));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.CLOSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readPing() throws Exception {
|
||||
byte[] bytes = new byte[] { (byte) 0x89, (byte) 0x00 };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.PING));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.PING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readPong() throws Exception {
|
||||
byte[] bytes = new byte[] { (byte) 0x8A, (byte) 0x00 };
|
||||
Frame frame = Frame.read(newConnectionInputStream(bytes));
|
||||
assertThat(frame.getType(), equalTo(Frame.Type.PONG));
|
||||
assertThat(frame.getType()).isEqualTo(Frame.Type.PONG);
|
||||
}
|
||||
|
||||
private ConnectionInputStream newConnectionInputStream(byte[] bytes) {
|
||||
|
||||
@@ -40,10 +40,7 @@ import org.junit.Test;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link LiveReloadServer}.
|
||||
@@ -78,7 +75,7 @@ public class LiveReloadServerTests {
|
||||
RestTemplate template = new RestTemplate();
|
||||
URI uri = new URI("http://localhost:" + this.port + "/livereload.js");
|
||||
String script = template.getForObject(uri, String.class);
|
||||
assertThat(script, containsString("livereload.com/protocols/official-7"));
|
||||
assertThat(script).contains("livereload.com/protocols/official-7");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,9 +86,9 @@ public class LiveReloadServerTests {
|
||||
this.server.triggerReload();
|
||||
Thread.sleep(500);
|
||||
this.server.stop();
|
||||
assertThat(socket.getMessages(0),
|
||||
containsString("http://livereload.com/protocols/official-7"));
|
||||
assertThat(socket.getMessages(1), containsString("command\":\"reload\""));
|
||||
assertThat(socket.getMessages(0))
|
||||
.contains("http://livereload.com/protocols/official-7");
|
||||
assertThat(socket.getMessages(1)).contains("command\":\"reload\"");
|
||||
}
|
||||
finally {
|
||||
client.stop();
|
||||
@@ -107,7 +104,7 @@ public class LiveReloadServerTests {
|
||||
socket.getRemote().sendPing(NO_DATA);
|
||||
Thread.sleep(200);
|
||||
this.server.stop();
|
||||
assertThat(driver.getPongCount(), equalTo(1));
|
||||
assertThat(driver.getPongCount()).isEqualTo(1);
|
||||
}
|
||||
finally {
|
||||
client.stop();
|
||||
@@ -125,7 +122,7 @@ public class LiveReloadServerTests {
|
||||
client.stop();
|
||||
}
|
||||
awaitClosedException();
|
||||
assertThat(this.server.getClosedExceptions().size(), greaterThan(0));
|
||||
assertThat(this.server.getClosedExceptions().size()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
private void awaitClosedException() throws InterruptedException {
|
||||
@@ -144,7 +141,7 @@ public class LiveReloadServerTests {
|
||||
Thread.sleep(200);
|
||||
this.server.stop();
|
||||
Thread.sleep(200);
|
||||
assertThat(socket.getCloseStatus(), equalTo(1006));
|
||||
assertThat(socket.getCloseStatus()).isEqualTo(1006);
|
||||
}
|
||||
finally {
|
||||
client.stop();
|
||||
|
||||
@@ -44,8 +44,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ClassPathChangeUploader}.
|
||||
@@ -117,20 +116,20 @@ public class ClassPathChangeUploaderTests {
|
||||
MockClientHttpRequest request = this.requestFactory.getExecutedRequests().get(0);
|
||||
ClassLoaderFiles classLoaderFiles = deserialize(request.getBodyAsBytes());
|
||||
Collection<SourceFolder> sourceFolders = classLoaderFiles.getSourceFolders();
|
||||
assertThat(sourceFolders.size(), equalTo(1));
|
||||
assertThat(sourceFolders.size()).isEqualTo(1);
|
||||
SourceFolder classSourceFolder = sourceFolders.iterator().next();
|
||||
assertThat(classSourceFolder.getName(), equalTo(sourceFolder.getAbsolutePath()));
|
||||
assertThat(classSourceFolder.getName()).isEqualTo(sourceFolder.getAbsolutePath());
|
||||
Iterator<ClassLoaderFile> classFiles = classSourceFolder.getFiles().iterator();
|
||||
assertClassFile(classFiles.next(), "File1", ClassLoaderFile.Kind.ADDED);
|
||||
assertClassFile(classFiles.next(), "File2", ClassLoaderFile.Kind.MODIFIED);
|
||||
assertClassFile(classFiles.next(), null, ClassLoaderFile.Kind.DELETED);
|
||||
assertThat(classFiles.hasNext(), equalTo(false));
|
||||
assertThat(classFiles.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
private void assertClassFile(ClassLoaderFile file, String content, Kind kind) {
|
||||
assertThat(file.getContents(),
|
||||
equalTo(content == null ? null : content.getBytes()));
|
||||
assertThat(file.getKind(), equalTo(kind));
|
||||
assertThat(file.getContents())
|
||||
.isEqualTo(content == null ? null : content.getBytes());
|
||||
assertThat(file.getKind()).isEqualTo(kind);
|
||||
}
|
||||
|
||||
private File createFile(File sourceFolder, String name) throws IOException {
|
||||
|
||||
@@ -33,8 +33,7 @@ import org.springframework.http.client.ClientHttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -119,7 +118,7 @@ public class DelayedLiveReloadTriggerTests {
|
||||
long startTime = System.currentTimeMillis();
|
||||
this.trigger.setTimings(10, 200, 30000);
|
||||
this.trigger.run();
|
||||
assertThat(System.currentTimeMillis() - startTime, greaterThan(300L));
|
||||
assertThat(System.currentTimeMillis() - startTime).isGreaterThan(300L);
|
||||
verify(this.liveReloadServer).triggerReload();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
@@ -109,8 +108,8 @@ public class HttpHeaderInterceptorTests {
|
||||
public void intercept() throws IOException {
|
||||
ClientHttpResponse result = this.interceptor.intercept(this.request, this.body,
|
||||
this.execution);
|
||||
assertThat(this.request.getHeaders().getFirst(this.name), equalTo(this.value));
|
||||
assertThat(result, equalTo(this.response));
|
||||
assertThat(this.request.getHeaders().getFirst(this.name)).isEqualTo(this.value);
|
||||
assertThat(result).isEqualTo(this.response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -47,8 +46,8 @@ public class LocalDebugPortAvailableConditionTests {
|
||||
@Test
|
||||
public void portAvailable() throws Exception {
|
||||
ConditionOutcome outcome = getOutcome();
|
||||
assertThat(outcome.isMatch(), equalTo(true));
|
||||
assertThat(outcome.getMessage(), equalTo("Local debug port available"));
|
||||
assertThat(outcome.isMatch()).isTrue();
|
||||
assertThat(outcome.getMessage()).isEqualTo("Local debug port available");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,8 +56,8 @@ public class LocalDebugPortAvailableConditionTests {
|
||||
.createServerSocket(this.port);
|
||||
ConditionOutcome outcome = getOutcome();
|
||||
serverSocket.close();
|
||||
assertThat(outcome.isMatch(), equalTo(false));
|
||||
assertThat(outcome.getMessage(), equalTo("Local debug port unavailable"));
|
||||
assertThat(outcome.isMatch()).isFalse();
|
||||
assertThat(outcome.getMessage()).isEqualTo("Local debug port unavailable");
|
||||
}
|
||||
|
||||
private ConditionOutcome getOutcome() {
|
||||
|
||||
@@ -49,9 +49,7 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -88,20 +86,20 @@ public class RemoteClientConfigurationTests {
|
||||
public void warnIfDebugAndRestartDisabled() throws Exception {
|
||||
configure("spring.devtools.remote.debug.enabled:false",
|
||||
"spring.devtools.remote.restart.enabled:false");
|
||||
assertThat(this.output.toString(),
|
||||
containsString("Remote restart and debug are both disabled"));
|
||||
assertThat(this.output.toString())
|
||||
.contains("Remote restart and debug are both disabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warnIfNotHttps() throws Exception {
|
||||
configure("http://localhost", true);
|
||||
assertThat(this.output.toString(), containsString("is insecure"));
|
||||
assertThat(this.output.toString()).contains("is insecure");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntWarnIfUsingHttps() throws Exception {
|
||||
configure("https://localhost", true);
|
||||
assertThat(this.output.toString(), not(containsString("is insecure")));
|
||||
assertThat(this.output.toString()).doesNotContain("is insecure");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -38,8 +38,7 @@ import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.willReturn;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -114,8 +113,8 @@ public class DispatcherFilterTests {
|
||||
ServletServerHttpRequest actualRequest = (ServletServerHttpRequest) dispatcherRequest;
|
||||
ServerHttpResponse dispatcherResponse = this.serverResponseCaptor.getValue();
|
||||
ServletServerHttpResponse actualResponse = (ServletServerHttpResponse) dispatcherResponse;
|
||||
assertThat(actualRequest.getServletRequest(), equalTo(request));
|
||||
assertThat(actualResponse.getServletResponse(), equalTo(response));
|
||||
assertThat(actualRequest.getServletRequest()).isEqualTo(request);
|
||||
assertThat(actualResponse.getServletResponse()).isEqualTo(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
@@ -101,7 +100,7 @@ public class DispatcherTests {
|
||||
Collections.singleton(mapper));
|
||||
dispatcher.handle(this.serverRequest, this.serverResponse);
|
||||
verifyZeroInteractions(handler);
|
||||
assertThat(this.response.getStatus(), equalTo(403));
|
||||
assertThat(this.response.getStatus()).isEqualTo(403);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpHeaderAccessManager}.
|
||||
@@ -87,24 +86,24 @@ public class HttpHeaderAccessManagerTests {
|
||||
@Test
|
||||
public void allowsMatching() throws Exception {
|
||||
this.request.addHeader(HEADER, SECRET);
|
||||
assertThat(this.manager.isAllowed(this.serverRequest), equalTo(true));
|
||||
assertThat(this.manager.isAllowed(this.serverRequest)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disallowsWrongSecret() throws Exception {
|
||||
this.request.addHeader(HEADER, "wrong");
|
||||
assertThat(this.manager.isAllowed(this.serverRequest), equalTo(false));
|
||||
assertThat(this.manager.isAllowed(this.serverRequest)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disallowsNoSecret() throws Exception {
|
||||
assertThat(this.manager.isAllowed(this.serverRequest), equalTo(false));
|
||||
assertThat(this.manager.isAllowed(this.serverRequest)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disallowsWrongHeader() throws Exception {
|
||||
this.request.addHeader("X-WRONG", SECRET);
|
||||
assertThat(this.manager.isAllowed(this.serverRequest), equalTo(false));
|
||||
assertThat(this.manager.isAllowed(this.serverRequest)).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpStatusHandler}.
|
||||
@@ -69,14 +68,14 @@ public class HttpStatusHandlerTests {
|
||||
public void respondsOk() throws Exception {
|
||||
HttpStatusHandler handler = new HttpStatusHandler();
|
||||
handler.handle(this.request, this.response);
|
||||
assertThat(this.servletResponse.getStatus(), equalTo(200));
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void respondsWithStatus() throws Exception {
|
||||
HttpStatusHandler handler = new HttpStatusHandler(HttpStatus.I_AM_A_TEAPOT);
|
||||
handler.handle(this.request, this.response);
|
||||
assertThat(this.servletResponse.getStatus(), equalTo(418));
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(418);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -70,7 +68,7 @@ public class UrlHandlerMapperTests {
|
||||
UrlHandlerMapper mapper = new UrlHandlerMapper("/tunnel", this.handler);
|
||||
HttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/tunnel");
|
||||
ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
|
||||
assertThat(mapper.getHandler(request), equalTo(this.handler));
|
||||
assertThat(mapper.getHandler(request)).isEqualTo(this.handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +77,7 @@ public class UrlHandlerMapperTests {
|
||||
HttpServletRequest servletRequest = new MockHttpServletRequest("GET",
|
||||
"/tunnel/other");
|
||||
ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
|
||||
assertThat(mapper.getHandler(request), nullValue());
|
||||
assertThat(mapper.getHandler(request)).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ChangeableUrls}.
|
||||
@@ -40,19 +39,19 @@ public class ChangeableUrlsTests {
|
||||
@Test
|
||||
public void folderUrl() throws Exception {
|
||||
URL url = makeUrl("myproject");
|
||||
assertThat(ChangeableUrls.fromUrls(url).size(), equalTo(1));
|
||||
assertThat(ChangeableUrls.fromUrls(url).size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileUrl() throws Exception {
|
||||
URL url = this.temporaryFolder.newFile().toURI().toURL();
|
||||
assertThat(ChangeableUrls.fromUrls(url).size(), equalTo(0));
|
||||
assertThat(ChangeableUrls.fromUrls(url).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpUrl() throws Exception {
|
||||
URL url = new URL("http://spring.io");
|
||||
assertThat(ChangeableUrls.fromUrls(url).size(), equalTo(0));
|
||||
assertThat(ChangeableUrls.fromUrls(url).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +60,7 @@ public class ChangeableUrlsTests {
|
||||
makeUrl("spring-boot-autoconfigure"), makeUrl("spring-boot-actuator"),
|
||||
makeUrl("spring-boot-starter"),
|
||||
makeUrl("spring-boot-starter-some-thing"));
|
||||
assertThat(urls.size(), equalTo(0));
|
||||
assertThat(urls.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
private URL makeUrl(String name) throws IOException {
|
||||
|
||||
@@ -20,10 +20,8 @@ import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultRestartInitializer}.
|
||||
@@ -35,7 +33,7 @@ public class DefaultRestartInitializerTests {
|
||||
@Test
|
||||
public void nullForTests() throws Exception {
|
||||
MockRestartInitializer initializer = new MockRestartInitializer(true);
|
||||
assertThat(initializer.getInitialUrls(Thread.currentThread()), nullValue());
|
||||
assertThat(initializer.getInitialUrls(Thread.currentThread())).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,8 +43,8 @@ public class DefaultRestartInitializerTests {
|
||||
Thread thread = new Thread();
|
||||
thread.setName("main");
|
||||
thread.setContextClassLoader(classLoader);
|
||||
assertThat(initializer.isMain(thread), equalTo(true));
|
||||
assertThat(initializer.getInitialUrls(thread), not(nullValue()));
|
||||
assertThat(initializer.isMain(thread)).isTrue();
|
||||
assertThat(initializer.getInitialUrls(thread)).isNotEqualTo(nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,8 +54,8 @@ public class DefaultRestartInitializerTests {
|
||||
Thread thread = new Thread();
|
||||
thread.setName("buscuit");
|
||||
thread.setContextClassLoader(classLoader);
|
||||
assertThat(initializer.isMain(thread), equalTo(false));
|
||||
assertThat(initializer.getInitialUrls(thread), nullValue());
|
||||
assertThat(initializer.isMain(thread)).isFalse();
|
||||
assertThat(initializer.getInitialUrls(thread)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,8 +66,8 @@ public class DefaultRestartInitializerTests {
|
||||
Thread thread = new Thread();
|
||||
thread.setName("main");
|
||||
thread.setContextClassLoader(classLoader);
|
||||
assertThat(initializer.isMain(thread), equalTo(false));
|
||||
assertThat(initializer.getInitialUrls(thread), nullValue());
|
||||
assertThat(initializer.isMain(thread)).isFalse();
|
||||
assertThat(initializer.getInitialUrls(thread)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +84,7 @@ public class DefaultRestartInitializerTests {
|
||||
MockRestartInitializer initializer = new MockRestartInitializer(true);
|
||||
StackTraceElement element = new StackTraceElement(className, "someMethod",
|
||||
"someFile", 123);
|
||||
assertThat(initializer.isSkippedStackElement(element), equalTo(expected));
|
||||
assertThat(initializer.isSkippedStackElement(element)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private static class MockAppClassLoader extends ClassLoader {
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link MainMethod}.
|
||||
@@ -62,9 +61,9 @@ public class MainMethodTests {
|
||||
Valid.main();
|
||||
}
|
||||
}).test();
|
||||
assertThat(method.getMethod(), equalTo(this.actualMain));
|
||||
assertThat(method.getDeclaringClassName(),
|
||||
equalTo(this.actualMain.getDeclaringClass().getName()));
|
||||
assertThat(method.getMethod()).isEqualTo(this.actualMain);
|
||||
assertThat(method.getDeclaringClassName())
|
||||
.isEqualTo(this.actualMain.getDeclaringClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -53,7 +52,7 @@ public class OnInitializedRestarterConditionTests {
|
||||
Restarter.clearInstance();
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
Config.class);
|
||||
assertThat(context.containsBean("bean"), equalTo(false));
|
||||
assertThat(context.containsBean("bean")).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ public class OnInitializedRestarterConditionTests {
|
||||
Restarter.initialize(new String[0], false, RestartInitializer.NONE);
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
Config.class);
|
||||
assertThat(context.containsBean("bean"), equalTo(false));
|
||||
assertThat(context.containsBean("bean")).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -90,7 +89,7 @@ public class OnInitializedRestarterConditionTests {
|
||||
Restarter.initialize(new String[0], false, initializer);
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
Config.class);
|
||||
assertThat(context.containsBean("bean"), equalTo(true));
|
||||
assertThat(context.containsBean("bean")).isTrue();
|
||||
context.close();
|
||||
synchronized (wait) {
|
||||
wait.notify();
|
||||
|
||||
@@ -28,10 +28,8 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -54,32 +52,32 @@ public class RestartApplicationListenerTests {
|
||||
|
||||
@Test
|
||||
public void isHighestPriority() throws Exception {
|
||||
assertThat(new RestartApplicationListener().getOrder(),
|
||||
equalTo(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"),
|
||||
equalTo((Object) ARGS));
|
||||
assertThat(Restarter.getInstance().isFinished(), equalTo(true));
|
||||
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args"))
|
||||
.isEqualTo(ARGS);
|
||||
assertThat(Restarter.getInstance().isFinished()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeWithFail() throws Exception {
|
||||
testInitialize(true);
|
||||
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args"),
|
||||
equalTo((Object) ARGS));
|
||||
assertThat(Restarter.getInstance().isFinished(), equalTo(true));
|
||||
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args"))
|
||||
.isEqualTo(ARGS);
|
||||
assertThat(Restarter.getInstance().isFinished()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disableWithSystemProperty() throws Exception {
|
||||
System.setProperty(ENABLED_PROPERTY, "false");
|
||||
testInitialize(false);
|
||||
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "enabled"),
|
||||
equalTo((Object) false));
|
||||
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "enabled"))
|
||||
.isEqualTo(false);
|
||||
}
|
||||
|
||||
private void testInitialize(boolean failed) {
|
||||
@@ -89,8 +87,8 @@ public class RestartApplicationListenerTests {
|
||||
ConfigurableApplicationContext context = mock(
|
||||
ConfigurableApplicationContext.class);
|
||||
listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
|
||||
assertThat(Restarter.getInstance(), not(nullValue()));
|
||||
assertThat(Restarter.getInstance().isFinished(), equalTo(false));
|
||||
assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
|
||||
assertThat(Restarter.getInstance().isFinished()).isFalse();
|
||||
if (failed) {
|
||||
listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
|
||||
context, new RuntimeException()));
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestartScopeInitializer}.
|
||||
@@ -49,8 +48,8 @@ public class RestartScopeInitializerTests {
|
||||
context.close();
|
||||
context = runApplication();
|
||||
context.close();
|
||||
assertThat(createCount.get(), equalTo(1));
|
||||
assertThat(refreshCount.get(), equalTo(2));
|
||||
assertThat(createCount.get()).isEqualTo(1);
|
||||
assertThat(refreshCount.get()).isEqualTo(2);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext runApplication() {
|
||||
|
||||
@@ -41,9 +41,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -94,9 +92,9 @@ public class RestarterTests {
|
||||
thread.start();
|
||||
Thread.sleep(2600);
|
||||
String output = this.out.toString();
|
||||
assertThat(StringUtils.countOccurrencesOf(output, "Tick 0"), greaterThan(1));
|
||||
assertThat(StringUtils.countOccurrencesOf(output, "Tick 1"), greaterThan(1));
|
||||
assertThat(TestRestartListener.restarts, greaterThan(0));
|
||||
assertThat(StringUtils.countOccurrencesOf(output, "Tick 0")).isGreaterThan(1);
|
||||
assertThat(StringUtils.countOccurrencesOf(output, "Tick 1")).isGreaterThan(1);
|
||||
assertThat(TestRestartListener.restarts).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +103,7 @@ public class RestarterTests {
|
||||
ObjectFactory objectFactory = mock(ObjectFactory.class);
|
||||
given(objectFactory.getObject()).willReturn("abc");
|
||||
Object attribute = Restarter.getInstance().getOrAddAttribute("x", objectFactory);
|
||||
assertThat(attribute, equalTo((Object) "abc"));
|
||||
assertThat(attribute).isEqualTo("abc");
|
||||
}
|
||||
|
||||
public void addUrlsMustNotBeNull() throws Exception {
|
||||
@@ -123,7 +121,7 @@ public class RestarterTests {
|
||||
restarter.restart();
|
||||
ClassLoader classLoader = ((TestableRestarter) restarter)
|
||||
.getRelaunchClassLoader();
|
||||
assertThat(((URLClassLoader) classLoader).getURLs()[0], equalTo(url));
|
||||
assertThat(((URLClassLoader) classLoader).getURLs()[0]).isEqualTo(url);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,8 +140,8 @@ public class RestarterTests {
|
||||
restarter.restart();
|
||||
ClassLoader classLoader = ((TestableRestarter) restarter)
|
||||
.getRelaunchClassLoader();
|
||||
assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f")),
|
||||
equalTo("abc".getBytes()));
|
||||
assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f")))
|
||||
.isEqualTo("abc".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +155,7 @@ public class RestarterTests {
|
||||
});
|
||||
ObjectFactory objectFactory = mock(ObjectFactory.class);
|
||||
Object attribute = Restarter.getInstance().getOrAddAttribute("x", objectFactory);
|
||||
assertThat(attribute, equalTo((Object) "abc"));
|
||||
assertThat(attribute).isEqualTo("abc");
|
||||
verifyZeroInteractions(objectFactory);
|
||||
}
|
||||
|
||||
@@ -173,9 +171,9 @@ public class RestarterTests {
|
||||
ThreadFactory factory = Restarter.getInstance().getThreadFactory();
|
||||
Thread viaFactory = factory.newThread(runnable);
|
||||
// Regular threads will inherit the current thread
|
||||
assertThat(regular.getContextClassLoader(), equalTo(contextClassLoader));
|
||||
assertThat(regular.getContextClassLoader()).isEqualTo(contextClassLoader);
|
||||
// Factory threads should should inherit from the initial thread
|
||||
assertThat(viaFactory.getContextClassLoader(), equalTo(parentLoader));
|
||||
assertThat(viaFactory.getContextClassLoader()).isEqualTo(parentLoader);
|
||||
};
|
||||
};
|
||||
thread.setContextClassLoader(contextClassLoader);
|
||||
@@ -190,7 +188,7 @@ public class RestarterTests {
|
||||
URL[] urls = new URL[] { new URL("file:/proj/module-a.jar!/") };
|
||||
given(initializer.getInitialUrls(any(Thread.class))).willReturn(urls);
|
||||
Restarter.initialize(new String[0], false, initializer, false);
|
||||
assertThat(Restarter.getInstance().getInitialUrls(), equalTo(urls));
|
||||
assertThat(Restarter.getInstance().getInitialUrls()).isEqualTo(urls);
|
||||
}
|
||||
|
||||
@Component
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.springframework.boot.devtools.restart;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@@ -41,7 +39,7 @@ public class SilentExitExceptionHandlerTests {
|
||||
};
|
||||
SilentExitExceptionHandler.setup(testThread);
|
||||
testThread.startAndJoin();
|
||||
assertThat(testThread.getThrown(), nullValue());
|
||||
assertThat(testThread.getThrown()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +52,7 @@ public class SilentExitExceptionHandlerTests {
|
||||
};
|
||||
SilentExitExceptionHandler.setup(testThread);
|
||||
testThread.startAndJoin();
|
||||
assertThat(testThread.getThrown().getMessage(), equalTo("Expected"));
|
||||
assertThat(testThread.getThrown().getMessage()).isEqualTo("Expected");
|
||||
}
|
||||
|
||||
private static abstract class TestThread extends Thread {
|
||||
|
||||
@@ -22,9 +22,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ClassLoaderFile}.
|
||||
@@ -69,22 +67,22 @@ public class ClassLoaderFileTests {
|
||||
@Test
|
||||
public void added() throws Exception {
|
||||
ClassLoaderFile file = new ClassLoaderFile(Kind.ADDED, BYTES);
|
||||
assertThat(file.getKind(), equalTo(ClassLoaderFile.Kind.ADDED));
|
||||
assertThat(file.getContents(), equalTo(BYTES));
|
||||
assertThat(file.getKind()).isEqualTo(ClassLoaderFile.Kind.ADDED);
|
||||
assertThat(file.getContents()).isEqualTo(BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modified() throws Exception {
|
||||
ClassLoaderFile file = new ClassLoaderFile(Kind.MODIFIED, BYTES);
|
||||
assertThat(file.getKind(), equalTo(ClassLoaderFile.Kind.MODIFIED));
|
||||
assertThat(file.getContents(), equalTo(BYTES));
|
||||
assertThat(file.getKind()).isEqualTo(ClassLoaderFile.Kind.MODIFIED);
|
||||
assertThat(file.getContents()).isEqualTo(BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleted() throws Exception {
|
||||
ClassLoaderFile file = new ClassLoaderFile(Kind.DELETED, null);
|
||||
assertThat(file.getKind(), equalTo(ClassLoaderFile.Kind.DELETED));
|
||||
assertThat(file.getContents(), nullValue());
|
||||
assertThat(file.getKind()).isEqualTo(ClassLoaderFile.Kind.DELETED);
|
||||
assertThat(file.getContents()).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -31,10 +29,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
|
||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -65,19 +60,19 @@ public class ClassLoaderFilesTests {
|
||||
|
||||
@Test
|
||||
public void getFileWithNullName() throws Exception {
|
||||
assertThat(this.files.getFile(null), nullValue());
|
||||
assertThat(this.files.getFile(null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAndGet() throws Exception {
|
||||
ClassLoaderFile file = new ClassLoaderFile(Kind.ADDED, new byte[10]);
|
||||
this.files.addFile("myfile", file);
|
||||
assertThat(this.files.getFile("myfile"), equalTo(file));
|
||||
assertThat(this.files.getFile("myfile")).isEqualTo(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMissing() throws Exception {
|
||||
assertThat(this.files.getFile("missing"), nullValue());
|
||||
assertThat(this.files.getFile("missing")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +81,7 @@ public class ClassLoaderFilesTests {
|
||||
ClassLoaderFile file2 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
|
||||
this.files.addFile("myfile", file1);
|
||||
this.files.addFile("myfile", file2);
|
||||
assertThat(this.files.getFile("myfile"), equalTo(file2));
|
||||
assertThat(this.files.getFile("myfile")).isEqualTo(file2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,9 +90,11 @@ public class ClassLoaderFilesTests {
|
||||
ClassLoaderFile file2 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
|
||||
this.files.addFile("a", "myfile", file1);
|
||||
this.files.addFile("b", "myfile", file2);
|
||||
assertThat(this.files.getFile("myfile"), equalTo(file2));
|
||||
assertThat(this.files.getOrCreateSourceFolder("a").getFiles().size(), equalTo(0));
|
||||
assertThat(this.files.getOrCreateSourceFolder("b").getFiles().size(), equalTo(1));
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,13 +110,11 @@ public class ClassLoaderFilesTests {
|
||||
Iterator<SourceFolder> sourceFolders = this.files.getSourceFolders().iterator();
|
||||
SourceFolder sourceFolder1 = sourceFolders.next();
|
||||
SourceFolder sourceFolder2 = sourceFolders.next();
|
||||
assertThat(sourceFolders.hasNext(), equalTo(false));
|
||||
assertThat(sourceFolder1.getName(), equalTo("a"));
|
||||
assertThat(sourceFolder2.getName(), equalTo("b"));
|
||||
assertThat(new ArrayList<ClassLoaderFile>(sourceFolder1.getFiles()),
|
||||
equalTo(Arrays.asList(file1, file2)));
|
||||
assertThat(new ArrayList<ClassLoaderFile>(sourceFolder2.getFiles()),
|
||||
equalTo(Arrays.asList(file3, file4)));
|
||||
assertThat(sourceFolders.hasNext()).isFalse();
|
||||
assertThat(sourceFolder1.getName()).isEqualTo("a");
|
||||
assertThat(sourceFolder2.getName()).isEqualTo("b");
|
||||
assertThat(sourceFolder1.getFiles()).containsOnly(file1, file2);
|
||||
assertThat(sourceFolder2.getFiles()).containsOnly(file3, file4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,7 +128,7 @@ public class ClassLoaderFilesTests {
|
||||
ObjectInputStream ois = new ObjectInputStream(
|
||||
new ByteArrayInputStream(bos.toByteArray()));
|
||||
ClassLoaderFiles readObject = (ClassLoaderFiles) ois.readObject();
|
||||
assertThat(readObject.getFile("myfile"), notNullValue());
|
||||
assertThat(readObject.getFile("myfile")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,11 +144,10 @@ public class ClassLoaderFilesTests {
|
||||
Iterator<SourceFolder> sourceFolders = this.files.getSourceFolders().iterator();
|
||||
SourceFolder sourceFolder1 = sourceFolders.next();
|
||||
SourceFolder sourceFolder2 = sourceFolders.next();
|
||||
assertThat(sourceFolders.hasNext(), equalTo(false));
|
||||
assertThat(sourceFolder1.getName(), equalTo("a"));
|
||||
assertThat(sourceFolder2.getName(), equalTo("b"));
|
||||
assertThat(new ArrayList<ClassLoaderFile>(sourceFolder1.getFiles()),
|
||||
equalTo(Arrays.asList(file1, file2)));
|
||||
assertThat(sourceFolders.hasNext()).isFalse();
|
||||
assertThat(sourceFolder1.getName()).isEqualTo("a");
|
||||
assertThat(sourceFolder2.getName()).isEqualTo("b");
|
||||
assertThat(sourceFolder1.getFiles()).containsOnly(file1, file2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,7 +156,7 @@ public class ClassLoaderFilesTests {
|
||||
this.files.addFile("s1", "n2", mock(ClassLoaderFile.class));
|
||||
this.files.addFile("s2", "n3", mock(ClassLoaderFile.class));
|
||||
this.files.addFile("s2", "n1", mock(ClassLoaderFile.class));
|
||||
assertThat(this.files.size(), equalTo(3));
|
||||
assertThat(this.files.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,8 +172,8 @@ public class ClassLoaderFilesTests {
|
||||
this.files.addFile("s1", "n2", mock(ClassLoaderFile.class));
|
||||
ClassLoaderFiles copy = new ClassLoaderFiles(this.files);
|
||||
this.files.addFile("s2", "n3", mock(ClassLoaderFile.class));
|
||||
assertThat(this.files.size(), equalTo(3));
|
||||
assertThat(copy.size(), equalTo(2));
|
||||
assertThat(this.files.size()).isEqualTo(3);
|
||||
assertThat(copy.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,9 +39,7 @@ import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kin
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestartClassLoader}.
|
||||
@@ -115,48 +113,47 @@ public class RestartClassLoaderTests {
|
||||
public void getResourceFromReloadableUrl() throws Exception {
|
||||
String content = readString(
|
||||
this.reloadClassLoader.getResourceAsStream(PACKAGE_PATH + "/Sample.txt"));
|
||||
assertThat(content, startsWith("fromchild"));
|
||||
assertThat(content).startsWith("fromchild");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResourceFromParent() throws Exception {
|
||||
String content = readString(
|
||||
this.reloadClassLoader.getResourceAsStream(PACKAGE_PATH + "/Parent.txt"));
|
||||
assertThat(content, startsWith("fromparent"));
|
||||
assertThat(content).startsWith("fromparent");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResourcesFiltersDuplicates() throws Exception {
|
||||
List<URL> resources = toList(
|
||||
this.reloadClassLoader.getResources(PACKAGE_PATH + "/Sample.txt"));
|
||||
assertThat(resources.size(), equalTo(1));
|
||||
assertThat(resources.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadClassFromReloadableUrl() throws Exception {
|
||||
Class<?> loaded = this.reloadClassLoader.loadClass(PACKAGE + ".Sample");
|
||||
assertThat(loaded.getClassLoader(),
|
||||
equalTo((ClassLoader) this.reloadClassLoader));
|
||||
assertThat(loaded.getClassLoader()).isEqualTo(this.reloadClassLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadClassFromParent() throws Exception {
|
||||
Class<?> loaded = this.reloadClassLoader.loadClass(PACKAGE + ".SampleParent");
|
||||
assertThat(loaded.getClassLoader(), equalTo(getClass().getClassLoader()));
|
||||
assertThat(loaded.getClassLoader()).isEqualTo(getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDeletedResource() throws Exception {
|
||||
String name = PACKAGE_PATH + "/Sample.txt";
|
||||
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.DELETED, null));
|
||||
assertThat(this.reloadClassLoader.getResource(name), equalTo(null));
|
||||
assertThat(this.reloadClassLoader.getResource(name)).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDeletedResourceAsStream() throws Exception {
|
||||
String name = PACKAGE_PATH + "/Sample.txt";
|
||||
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.DELETED, null));
|
||||
assertThat(this.reloadClassLoader.getResourceAsStream(name), equalTo(null));
|
||||
assertThat(this.reloadClassLoader.getResourceAsStream(name)).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +162,7 @@ public class RestartClassLoaderTests {
|
||||
byte[] bytes = "abc".getBytes();
|
||||
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.MODIFIED, bytes));
|
||||
URL resource = this.reloadClassLoader.getResource(name);
|
||||
assertThat(FileCopyUtils.copyToByteArray(resource.openStream()), equalTo(bytes));
|
||||
assertThat(FileCopyUtils.copyToByteArray(resource.openStream())).isEqualTo(bytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,7 +170,7 @@ public class RestartClassLoaderTests {
|
||||
String name = PACKAGE_PATH + "/Sample.txt";
|
||||
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.DELETED, null));
|
||||
List<URL> resources = toList(this.reloadClassLoader.getResources(name));
|
||||
assertThat(resources.size(), equalTo(0));
|
||||
assertThat(resources.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,8 +179,8 @@ 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()),
|
||||
equalTo(bytes));
|
||||
assertThat(FileCopyUtils.copyToByteArray(resources.get(0).openStream()))
|
||||
.isEqualTo(bytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,8 +206,7 @@ public class RestartClassLoaderTests {
|
||||
.copyToByteArray(getClass().getResourceAsStream("SampleParent.class"));
|
||||
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.ADDED, bytes));
|
||||
Class<?> loaded = this.reloadClassLoader.loadClass(PACKAGE + ".SampleParent");
|
||||
assertThat(loaded.getClassLoader(),
|
||||
equalTo((ClassLoader) this.reloadClassLoader));
|
||||
assertThat(loaded.getClassLoader()).isEqualTo(this.reloadClassLoader);
|
||||
}
|
||||
|
||||
private String readString(InputStream in) throws IOException {
|
||||
|
||||
@@ -24,8 +24,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultSourceFolderUrlFilter}.
|
||||
@@ -76,14 +75,14 @@ public class DefaultSourceFolderUrlFilterTests {
|
||||
+ "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), equalTo(true));
|
||||
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!/"
|
||||
+ "lib/spring-boot-1.3.0.BUILD-SNAPSHOT.jar!/");
|
||||
assertThat(this.filter.isMatch(sourceFolder, nestedJarUrl), equalTo(false));
|
||||
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");
|
||||
assertThat(this.filter.isMatch(sourceFolder, fileUrl), equalTo(true));
|
||||
assertThat(this.filter.isMatch(sourceFolder, fileUrl)).isTrue();
|
||||
}
|
||||
|
||||
private void doTest(String sourcePostfix) throws MalformedURLException {
|
||||
@@ -99,7 +98,8 @@ public class DefaultSourceFolderUrlFilterTests {
|
||||
for (String postfix : COMMON_POSTFIXES) {
|
||||
for (URL url : getUrls(moduleRoot + postfix)) {
|
||||
boolean match = this.filter.isMatch(sourceFolder, url);
|
||||
assertThat(url + " against " + sourceFolder, match, equalTo(expected));
|
||||
assertThat(match).as(url + " against " + sourceFolder)
|
||||
.isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,7 @@ import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
@@ -92,8 +90,8 @@ public class HttpRestartServerTests {
|
||||
this.server.handle(new ServletServerHttpRequest(request),
|
||||
new ServletServerHttpResponse(response));
|
||||
verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
|
||||
assertThat(this.filesCaptor.getValue().getFile("name"), notNullValue());
|
||||
assertThat(response.getStatus(), equalTo(200));
|
||||
assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,7 +101,7 @@ public class HttpRestartServerTests {
|
||||
this.server.handle(new ServletServerHttpRequest(request),
|
||||
new ServletServerHttpResponse(response));
|
||||
verifyZeroInteractions(this.delegate);
|
||||
assertThat(response.getStatus(), equalTo(500));
|
||||
assertThat(response.getStatus()).isEqualTo(500);
|
||||
|
||||
}
|
||||
|
||||
@@ -115,7 +113,7 @@ public class HttpRestartServerTests {
|
||||
this.server.handle(new ServletServerHttpRequest(request),
|
||||
new ServletServerHttpResponse(response));
|
||||
verifyZeroInteractions(this.delegate);
|
||||
assertThat(response.getStatus(), equalTo(500));
|
||||
assertThat(response.getStatus()).isEqualTo(500);
|
||||
}
|
||||
|
||||
private byte[] serialize(Object object) throws IOException {
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kin
|
||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestartServer}.
|
||||
@@ -76,8 +74,8 @@ public class RestartServerTests {
|
||||
files.addFile("my/module-c", "ClassB.class", fileB);
|
||||
server.updateAndRestart(files);
|
||||
Set<URL> expectedUrls = new LinkedHashSet<URL>(Arrays.asList(url1, url3));
|
||||
assertThat(server.restartUrls, equalTo(expectedUrls));
|
||||
assertThat(server.restartFiles, equalTo(files));
|
||||
assertThat(server.restartUrls).isEqualTo(expectedUrls);
|
||||
assertThat(server.restartFiles).isEqualTo(files);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +93,7 @@ public class RestartServerTests {
|
||||
ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
|
||||
files.addFile("my/module-a", "ClassA.class", fileA);
|
||||
server.updateAndRestart(files);
|
||||
assertThat(jarFile.lastModified(), greaterThan(startTime - 1000));
|
||||
assertThat(jarFile.lastModified()).isGreaterThan(startTime - 1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +112,7 @@ public class RestartServerTests {
|
||||
ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, "def".getBytes());
|
||||
files.addFile("my/module-a", "ClassA.class", fileA);
|
||||
server.updateAndRestart(files);
|
||||
assertThat(FileCopyUtils.copyToByteArray(classFile), equalTo("def".getBytes()));
|
||||
assertThat(FileCopyUtils.copyToByteArray(classFile)).isEqualTo("def".getBytes());
|
||||
}
|
||||
|
||||
private static class MockRestartServer extends RestartServer {
|
||||
|
||||
@@ -24,9 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DevToolsSettings}.
|
||||
@@ -45,28 +43,30 @@ public class DevToolsSettingsTests {
|
||||
public void includePatterns() throws Exception {
|
||||
DevToolsSettings settings = DevToolsSettings
|
||||
.load(ROOT + "spring-devtools-include.properties");
|
||||
assertThat(settings.isRestartInclude(new URL("file://test/a")), equalTo(true));
|
||||
assertThat(settings.isRestartInclude(new URL("file://test/b")), equalTo(true));
|
||||
assertThat(settings.isRestartInclude(new URL("file://test/c")), equalTo(false));
|
||||
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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludePatterns() throws Exception {
|
||||
DevToolsSettings settings = DevToolsSettings
|
||||
.load(ROOT + "spring-devtools-exclude.properties");
|
||||
assertThat(settings.isRestartExclude(new URL("file://test/a")), equalTo(true));
|
||||
assertThat(settings.isRestartExclude(new URL("file://test/b")), equalTo(true));
|
||||
assertThat(settings.isRestartExclude(new URL("file://test/c")), equalTo(false));
|
||||
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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultIncludePatterns() throws Exception {
|
||||
DevToolsSettings settings = DevToolsSettings.get();
|
||||
assertTrue(settings.isRestartExclude(makeUrl("spring-boot")));
|
||||
assertTrue(settings.isRestartExclude(makeUrl("spring-boot-autoconfigure")));
|
||||
assertTrue(settings.isRestartExclude(makeUrl("spring-boot-actuator")));
|
||||
assertTrue(settings.isRestartExclude(makeUrl("spring-boot-starter")));
|
||||
assertTrue(settings.isRestartExclude(makeUrl("spring-boot-starter-some-thing")));
|
||||
assertThat(settings.isRestartExclude(makeUrl("spring-boot"))).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();
|
||||
}
|
||||
|
||||
private URL makeUrl(String name) throws IOException {
|
||||
|
||||
@@ -36,9 +36,7 @@ import org.springframework.boot.devtools.tunnel.client.HttpTunnelConnection.Tunn
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -107,9 +105,9 @@ public class HttpTunnelConnectionTests {
|
||||
public void closeTunnelChangesIsOpen() throws Exception {
|
||||
this.requestFactory.willRespondAfterDelay(1000, HttpStatus.GONE);
|
||||
WritableByteChannel channel = openTunnel(false);
|
||||
assertThat(channel.isOpen(), equalTo(true));
|
||||
assertThat(channel.isOpen()).isTrue();
|
||||
channel.close();
|
||||
assertThat(channel.isOpen(), equalTo(false));
|
||||
assertThat(channel.isOpen()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +127,7 @@ public class HttpTunnelConnectionTests {
|
||||
write(channel, "hello");
|
||||
write(channel, "1+1");
|
||||
write(channel, "1+2");
|
||||
assertThat(this.incomingData.toString(), equalTo("hi=2=3"));
|
||||
assertThat(this.incomingData.toString()).isEqualTo("hi=2=3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,8 +138,8 @@ public class HttpTunnelConnectionTests {
|
||||
this.requestFactory.willRespond("hi");
|
||||
TunnelChannel channel = openTunnel(true);
|
||||
write(channel, "hello");
|
||||
assertThat(this.incomingData.toString(), equalTo("hi"));
|
||||
assertThat(this.requestFactory.getExecutedRequests().size(), greaterThan(10));
|
||||
assertThat(this.incomingData.toString()).isEqualTo("hi");
|
||||
assertThat(this.requestFactory.getExecutedRequests().size()).isGreaterThan(10);
|
||||
}
|
||||
|
||||
private void write(TunnelChannel channel, String string) throws IOException {
|
||||
|
||||
@@ -31,8 +31,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -76,7 +75,7 @@ public class TunnelClientTests {
|
||||
channel.read(buffer);
|
||||
channel.close();
|
||||
this.tunnelConnection.verifyWritten("hello");
|
||||
assertThat(new String(buffer.array()), equalTo("olleh"));
|
||||
assertThat(new String(buffer.array())).isEqualTo("olleh");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,8 +88,8 @@ public class TunnelClientTests {
|
||||
channel.close();
|
||||
client.getServerThread().stopAcceptingConnections();
|
||||
client.getServerThread().join(2000);
|
||||
assertThat(this.tunnelConnection.getOpenedTimes(), equalTo(1));
|
||||
assertThat(this.tunnelConnection.isOpen(), equalTo(false));
|
||||
assertThat(this.tunnelConnection.getOpenedTimes()).isEqualTo(1);
|
||||
assertThat(this.tunnelConnection.isOpen()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,9 +100,9 @@ public class TunnelClientTests {
|
||||
.open(new InetSocketAddress(this.listenPort));
|
||||
Thread.sleep(200);
|
||||
client.stop();
|
||||
assertThat(this.tunnelConnection.getOpenedTimes(), equalTo(1));
|
||||
assertThat(this.tunnelConnection.isOpen(), equalTo(false));
|
||||
assertThat(channel.read(ByteBuffer.allocate(1)), equalTo(-1));
|
||||
assertThat(this.tunnelConnection.getOpenedTimes()).isEqualTo(1);
|
||||
assertThat(this.tunnelConnection.isOpen()).isFalse();
|
||||
assertThat(channel.read(ByteBuffer.allocate(1))).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,7 +143,7 @@ public class TunnelClientTests {
|
||||
|
||||
public void verifyWritten(byte[] expected) {
|
||||
synchronized (this.written) {
|
||||
assertThat(this.written.toByteArray(), equalTo(expected));
|
||||
assertThat(this.written.toByteArray()).isEqualTo(expected);
|
||||
this.written.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpTunnelPayloadForwarder}.
|
||||
@@ -53,7 +52,7 @@ public class HttpTunnelPayloadForwarderTests {
|
||||
forwarder.forward(payload(1, "he"));
|
||||
forwarder.forward(payload(2, "ll"));
|
||||
forwarder.forward(payload(3, "o"));
|
||||
assertThat(out.toByteArray(), equalTo("hello".getBytes()));
|
||||
assertThat(out.toByteArray()).isEqualTo("hello".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +63,7 @@ public class HttpTunnelPayloadForwarderTests {
|
||||
forwarder.forward(payload(3, "o"));
|
||||
forwarder.forward(payload(2, "ll"));
|
||||
forwarder.forward(payload(1, "he"));
|
||||
assertThat(out.toByteArray(), equalTo("hello".getBytes()));
|
||||
assertThat(out.toByteArray()).isEqualTo("hello".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,9 +36,7 @@ import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -70,14 +68,14 @@ public class HttpTunnelPayloadTests {
|
||||
@Test
|
||||
public void getSequence() throws Exception {
|
||||
HttpTunnelPayload payload = new HttpTunnelPayload(1, ByteBuffer.allocate(1));
|
||||
assertThat(payload.getSequence(), equalTo(1L));
|
||||
assertThat(payload.getSequence()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getData() throws Exception {
|
||||
ByteBuffer data = ByteBuffer.wrap("hello".getBytes());
|
||||
HttpTunnelPayload payload = new HttpTunnelPayload(1, data);
|
||||
assertThat(getData(payload), equalTo(data.array()));
|
||||
assertThat(getData(payload)).isEqualTo(data.array());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,8 +85,8 @@ public class HttpTunnelPayloadTests {
|
||||
MockHttpServletResponse servletResponse = new MockHttpServletResponse();
|
||||
HttpOutputMessage response = new ServletServerHttpResponse(servletResponse);
|
||||
payload.assignTo(response);
|
||||
assertThat(servletResponse.getHeader("x-seq"), equalTo("2"));
|
||||
assertThat(servletResponse.getContentAsString(), equalTo("hello"));
|
||||
assertThat(servletResponse.getHeader("x-seq")).isEqualTo("2");
|
||||
assertThat(servletResponse.getContentAsString()).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +94,7 @@ public class HttpTunnelPayloadTests {
|
||||
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
|
||||
HttpInputMessage request = new ServletServerHttpRequest(servletRequest);
|
||||
HttpTunnelPayload payload = HttpTunnelPayload.get(request);
|
||||
assertThat(payload, nullValue());
|
||||
assertThat(payload).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,8 +114,8 @@ public class HttpTunnelPayloadTests {
|
||||
servletRequest.addHeader("x-seq", 123);
|
||||
HttpInputMessage request = new ServletServerHttpRequest(servletRequest);
|
||||
HttpTunnelPayload payload = HttpTunnelPayload.get(request);
|
||||
assertThat(payload.getSequence(), equalTo(123L));
|
||||
assertThat(getData(payload), equalTo("hello".getBytes()));
|
||||
assertThat(payload.getSequence()).isEqualTo(123L);
|
||||
assertThat(getData(payload)).isEqualTo("hello".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,7 +128,7 @@ public class HttpTunnelPayloadTests {
|
||||
while (payloadData.hasRemaining()) {
|
||||
writeChannel.write(payloadData);
|
||||
}
|
||||
assertThat(out.toByteArray(), equalTo("hello".getBytes()));
|
||||
assertThat(out.toByteArray()).isEqualTo("hello".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,7 +137,7 @@ public class HttpTunnelPayloadTests {
|
||||
given(channel.read(any(ByteBuffer.class)))
|
||||
.willThrow(new SocketTimeoutException());
|
||||
ByteBuffer payload = HttpTunnelPayload.getPayloadData(channel);
|
||||
assertThat(payload, nullValue());
|
||||
assertThat(payload).isNull();
|
||||
}
|
||||
|
||||
private byte[] getData(HttpTunnelPayload payload) throws IOException {
|
||||
|
||||
@@ -47,8 +47,7 @@ import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -154,7 +153,7 @@ public class HttpTunnelServerTests {
|
||||
this.serverChannel.send("hello");
|
||||
this.serverChannel.disconnect();
|
||||
this.server.getServerThread().join();
|
||||
assertThat(this.servletResponse.getContentAsString(), equalTo("hello"));
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("hello");
|
||||
this.serverChannel.verifyReceived("hello");
|
||||
}
|
||||
|
||||
@@ -193,7 +192,7 @@ public class HttpTunnelServerTests {
|
||||
this.server.handle(h1);
|
||||
this.serverChannel.disconnect();
|
||||
this.server.getServerThread().join();
|
||||
assertThat(h1.getServletResponse().getStatus(), equalTo(410));
|
||||
assertThat(h1.getServletResponse().getStatus()).isEqualTo(410);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,8 +203,8 @@ public class HttpTunnelServerTests {
|
||||
h2.getServletRequest().addHeader("Content-Type", "application/x-disconnect");
|
||||
this.server.handle(h2);
|
||||
this.server.getServerThread().join();
|
||||
assertThat(h1.getServletResponse().getStatus(), equalTo(410));
|
||||
assertThat(this.serverChannel.isOpen(), equalTo(false));
|
||||
assertThat(h1.getServletResponse().getStatus()).isEqualTo(410);
|
||||
assertThat(this.serverChannel.isOpen()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,7 +216,7 @@ public class HttpTunnelServerTests {
|
||||
MockHttpConnection h3 = new MockHttpConnection("2", 3);
|
||||
this.server.handle(h3);
|
||||
h1.waitForResponse();
|
||||
assertThat(h1.getServletResponse().getStatus(), equalTo(429));
|
||||
assertThat(h1.getServletResponse().getStatus()).isEqualTo(429);
|
||||
this.serverChannel.disconnect();
|
||||
this.server.getServerThread().join();
|
||||
}
|
||||
@@ -246,8 +245,8 @@ public class HttpTunnelServerTests {
|
||||
Thread.sleep(400);
|
||||
this.serverChannel.disconnect();
|
||||
this.server.getServerThread().join();
|
||||
assertThat(h1.getServletResponse().getStatus(), equalTo(204));
|
||||
assertThat(h2.getServletResponse().getStatus(), equalTo(204));
|
||||
assertThat(h1.getServletResponse().getStatus()).isEqualTo(204);
|
||||
assertThat(h2.getServletResponse().getStatus()).isEqualTo(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,7 +257,7 @@ public class HttpTunnelServerTests {
|
||||
this.server.handle(h1);
|
||||
this.serverChannel.send("hello");
|
||||
this.server.getServerThread().join();
|
||||
assertThat(this.serverChannel.isOpen(), equalTo(false));
|
||||
assertThat(this.serverChannel.isOpen()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,9 +272,9 @@ public class HttpTunnelServerTests {
|
||||
HttpConnection connection = new HttpConnection(this.request, this.response);
|
||||
connection.waitForResponse();
|
||||
connection.respond(new HttpTunnelPayload(1, ByteBuffer.wrap("hello".getBytes())));
|
||||
assertThat(this.servletResponse.getStatus(), equalTo(200));
|
||||
assertThat(this.servletResponse.getContentAsString(), equalTo("hello"));
|
||||
assertThat(this.servletResponse.getHeader(SEQ_HEADER), equalTo("1"));
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("hello");
|
||||
assertThat(this.servletResponse.getHeader(SEQ_HEADER)).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -283,8 +282,8 @@ public class HttpTunnelServerTests {
|
||||
HttpConnection connection = new HttpConnection(this.request, this.response);
|
||||
connection.waitForResponse();
|
||||
connection.respond(HttpStatus.I_AM_A_TEAPOT);
|
||||
assertThat(this.servletResponse.getStatus(), equalTo(418));
|
||||
assertThat(this.servletResponse.getContentLength(), equalTo(0));
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(418);
|
||||
assertThat(this.servletResponse.getContentLength()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -322,19 +321,19 @@ public class HttpTunnelServerTests {
|
||||
|
||||
};
|
||||
connectionThread.start();
|
||||
assertThat(responded.get(), equalTo(false));
|
||||
assertThat(responded.get()).isFalse();
|
||||
Thread.sleep(sleepBeforeResponse);
|
||||
connection.respond(HttpStatus.NO_CONTENT);
|
||||
connectionThread.join();
|
||||
assertThat(responded.get(), equalTo(true));
|
||||
assertThat(responded.get()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpConnectionRunning() throws Exception {
|
||||
HttpConnection connection = new HttpConnection(this.request, this.response);
|
||||
assertThat(connection.isOlderThan(100), equalTo(false));
|
||||
assertThat(connection.isOlderThan(100)).isFalse();
|
||||
Thread.sleep(200);
|
||||
assertThat(connection.isOlderThan(100), equalTo(true));
|
||||
assertThat(connection.isOlderThan(100)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,7 +373,7 @@ public class HttpTunnelServerTests {
|
||||
|
||||
public void verifyReceived(byte[] expected) {
|
||||
synchronized (this.written) {
|
||||
assertThat(this.written.toByteArray(), equalTo(expected));
|
||||
assertThat(this.written.toByteArray()).isEqualTo(expected);
|
||||
this.written.reset();
|
||||
}
|
||||
}
|
||||
@@ -466,8 +465,8 @@ public class HttpTunnelServerTests {
|
||||
throws Exception {
|
||||
waitForServletResponse();
|
||||
MockHttpServletResponse resp = getServletResponse();
|
||||
assertThat(resp.getContentAsString(), equalTo(expectedContent));
|
||||
assertThat(resp.getHeader(SEQ_HEADER), equalTo(String.valueOf(expectedSeq)));
|
||||
assertThat(resp.getContentAsString()).isEqualTo(expectedContent);
|
||||
assertThat(resp.getHeader(SEQ_HEADER)).isEqualTo(String.valueOf(expectedSeq));
|
||||
}
|
||||
|
||||
public void waitForServletResponse() throws InterruptedException {
|
||||
|
||||
@@ -29,10 +29,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@@ -65,7 +62,7 @@ public class SocketTargetServerConnectionTests {
|
||||
ByteChannel channel = this.connection.open(DEFAULT_TIMEOUT);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(5);
|
||||
channel.read(buffer);
|
||||
assertThat(buffer.array(), equalTo("hello".getBytes()));
|
||||
assertThat(buffer.array()).isEqualTo("hello".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,8 +88,8 @@ public class SocketTargetServerConnectionTests {
|
||||
catch (SocketTimeoutException ex) {
|
||||
// Expected
|
||||
long runTime = System.currentTimeMillis() - startTime;
|
||||
assertThat(runTime, greaterThanOrEqualTo(10L));
|
||||
assertThat(runTime, lessThan(10000L));
|
||||
assertThat(runTime).isGreaterThanOrEqualTo(10L);
|
||||
assertThat(runTime).isLessThan(10000L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +131,7 @@ public class SocketTargetServerConnectionTests {
|
||||
|
||||
public void closeAndVerify() throws InterruptedException {
|
||||
close();
|
||||
assertThat(this.actualRead.array(), equalTo(this.expect));
|
||||
assertThat(this.actualRead.array()).isEqualTo(this.expect);
|
||||
}
|
||||
|
||||
public void close() throws InterruptedException {
|
||||
|
||||
@@ -20,8 +20,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link StaticPortProvider}.
|
||||
@@ -43,7 +42,7 @@ public class StaticPortProviderTests {
|
||||
@Test
|
||||
public void getPort() throws Exception {
|
||||
StaticPortProvider provider = new StaticPortProvider(123);
|
||||
assertThat(provider.getPort(), equalTo(123));
|
||||
assertThat(provider.getPort()).isEqualTo(123);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user