Simplify AssertJ assertions and also make them more readable
See gh-33653
This commit is contained in:
committed by
Moritz Halbritter
parent
c9a2b2ab66
commit
cf6493f65c
@@ -152,7 +152,7 @@ class DevToolsHomePropertiesPostProcessorTests {
|
||||
out2.close();
|
||||
ConfigurableEnvironment environment = getPostProcessedEnvironment();
|
||||
assertThat(environment.getProperty("abc")).isEqualTo("jkl");
|
||||
assertThat(environment.getProperty("bar")).isEqualTo(null);
|
||||
assertThat(environment.getProperty("bar")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +168,7 @@ class DevToolsHomePropertiesPostProcessorTests {
|
||||
out2.close();
|
||||
ConfigurableEnvironment environment = getPostProcessedEnvironment();
|
||||
assertThat(environment.getProperty("abc.xyz")).isEqualTo("def");
|
||||
assertThat(environment.getProperty("bar")).isEqualTo(null);
|
||||
assertThat(environment.getProperty("bar")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -75,7 +75,7 @@ class DirectorySnapshotTests {
|
||||
void equalsWhenNothingHasChanged() {
|
||||
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
|
||||
assertThat(this.initialSnapshot).isEqualTo(updatedSnapshot);
|
||||
assertThat(this.initialSnapshot.hashCode()).isEqualTo(updatedSnapshot.hashCode());
|
||||
assertThat(this.initialSnapshot).hasSameHashCodeAs(updatedSnapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -65,7 +65,7 @@ class FileSnapshotTests {
|
||||
FileSnapshot snapshot1 = new FileSnapshot(file);
|
||||
FileSnapshot snapshot2 = new FileSnapshot(fileCopy);
|
||||
assertThat(snapshot1).isEqualTo(snapshot2);
|
||||
assertThat(snapshot1.hashCode()).isEqualTo(snapshot2.hashCode());
|
||||
assertThat(snapshot1).hasSameHashCodeAs(snapshot2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -104,7 +104,7 @@ class FileSystemWatcherTests {
|
||||
void sourceDirectoryMustNotBeAFile() throws IOException {
|
||||
File file = new File(this.tempDir, "file");
|
||||
assertThat(file.createNewFile()).isTrue();
|
||||
assertThat(file.isFile()).isTrue();
|
||||
assertThat(file).isFile();
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.watcher.addSourceDirectory(file))
|
||||
.withMessageContaining("Directory '" + file + "' must not be a file");
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class FileSystemWatcherTests {
|
||||
@Test
|
||||
void createSourceDirectoryAndAddFile() throws IOException {
|
||||
File directory = new File(this.tempDir, "does/not/exist");
|
||||
assertThat(directory.exists()).isFalse();
|
||||
assertThat(directory).doesNotExist();
|
||||
this.watcher.addSourceDirectory(directory);
|
||||
this.watcher.start();
|
||||
directory.mkdirs();
|
||||
@@ -157,7 +157,7 @@ class FileSystemWatcherTests {
|
||||
}
|
||||
touch(new File(directory, "test2.txt"));
|
||||
this.watcher.stopAfter(1);
|
||||
assertThat(this.changes.size()).isEqualTo(2);
|
||||
assertThat(this.changes).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -198,7 +198,7 @@ class FileSystemWatcherTests {
|
||||
File file2 = touch(new File(directory2, "test.txt"));
|
||||
this.watcher.stopAfter(1);
|
||||
Set<ChangedFiles> change = this.changes.stream().flatMap(Set<ChangedFiles>::stream).collect(Collectors.toSet());
|
||||
assertThat(change.size()).isEqualTo(2);
|
||||
assertThat(change).hasSize(2);
|
||||
for (ChangedFiles changedFiles : change) {
|
||||
if (changedFiles.getSourceDirectory().equals(directory1)) {
|
||||
ChangedFile file = new ChangedFile(directory1, file1, Type.ADD);
|
||||
|
||||
@@ -54,7 +54,7 @@ class ConnectionOutputStreamTests {
|
||||
expected += "Content-Length: 2\r\n";
|
||||
expected += "Connection: close\r\n\r\n";
|
||||
expected += "hi";
|
||||
assertThat(out.toString()).isEqualTo(expected);
|
||||
assertThat(out).hasToString(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +66,7 @@ class ConnectionOutputStreamTests {
|
||||
String expected = "";
|
||||
expected += "A: a\r\n";
|
||||
expected += "B: b\r\n\r\n";
|
||||
assertThat(out.toString()).isEqualTo(expected);
|
||||
assertThat(out).hasToString(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class LiveReloadServerTests {
|
||||
LiveReloadWebSocketHandler handler = connect();
|
||||
handler.close();
|
||||
awaitClosedException();
|
||||
assertThat(this.server.getClosedExceptions().size()).isGreaterThan(0);
|
||||
assertThat(this.server.getClosedExceptions()).isNotEmpty();
|
||||
}
|
||||
|
||||
private void awaitClosedException() {
|
||||
|
||||
@@ -114,7 +114,7 @@ class ClassPathChangeUploaderTests {
|
||||
throws IOException, ClassNotFoundException {
|
||||
ClassLoaderFiles classLoaderFiles = deserialize(request.getBodyAsBytes());
|
||||
Collection<SourceDirectory> sourceDirectories = classLoaderFiles.getSourceDirectories();
|
||||
assertThat(sourceDirectories.size()).isEqualTo(1);
|
||||
assertThat(sourceDirectories).hasSize(1);
|
||||
SourceDirectory classSourceDirectory = sourceDirectories.iterator().next();
|
||||
assertThat(classSourceDirectory.getName()).isEqualTo(sourceDirectory.getAbsolutePath());
|
||||
Iterator<ClassLoaderFile> classFiles = classSourceDirectory.getFiles().iterator();
|
||||
|
||||
@@ -48,7 +48,7 @@ class ChangeableUrlsTests {
|
||||
@Test
|
||||
void directoryUrl() throws Exception {
|
||||
URL url = makeUrl("myproject");
|
||||
assertThat(ChangeableUrls.fromUrls(url).size()).isEqualTo(1);
|
||||
assertThat(ChangeableUrls.fromUrls(url).size()).isOne();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -71,7 +71,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
|
||||
@Test
|
||||
void getResourceShouldReturnResource() {
|
||||
Resource resource = this.resolver.getResource("index.html");
|
||||
assertThat(resource).isNotNull().isInstanceOf(ClassPathResource.class);
|
||||
assertThat(resource).isInstanceOf(ClassPathResource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +79,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
|
||||
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
|
||||
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
|
||||
Resource resource = this.resolver.getResource("index.html");
|
||||
assertThat(resource).isNotNull().isInstanceOf(ServletContextResource.class);
|
||||
assertThat(resource).isInstanceOf(ServletContextResource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +87,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
|
||||
File file = createFile(directory, "name.class");
|
||||
this.files.addFile(directory.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
|
||||
Resource resource = this.resolver.getResource("file:" + file.getAbsolutePath());
|
||||
assertThat(resource).isNotNull().isInstanceOf(DeletedClassLoaderFileResource.class);
|
||||
assertThat(resource).isInstanceOf(DeletedClassLoaderFileResource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -107,7 +107,7 @@ class DefaultRestartInitializerTests {
|
||||
StackTraceElement element = new StackTraceElement(s, "someMethod", "someFile", 123);
|
||||
given(thread.getStackTrace()).willReturn(new StackTraceElement[] { element });
|
||||
given(thread.getContextClassLoader()).willReturn(classLoader);
|
||||
assertThat(initializer.getInitialUrls(thread)).isEqualTo(null);
|
||||
assertThat(initializer.getInitialUrls(thread)).isNull();
|
||||
}
|
||||
|
||||
static class MockAppClassLoader extends ClassLoader {
|
||||
|
||||
@@ -49,7 +49,7 @@ class RestartScopeInitializerTests {
|
||||
context.close();
|
||||
context = runApplication();
|
||||
context.close();
|
||||
assertThat(createCount.get()).isEqualTo(1);
|
||||
assertThat(createCount.get()).isOne();
|
||||
assertThat(refreshCount.get()).isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,8 @@ class ClassLoaderFilesTests {
|
||||
this.files.addFile("a", "myfile", file1);
|
||||
this.files.addFile("b", "myfile", file2);
|
||||
assertThat(this.files.getFile("myfile")).isEqualTo(file2);
|
||||
assertThat(this.files.getOrCreateSourceDirectory("a").getFiles().size()).isEqualTo(0);
|
||||
assertThat(this.files.getOrCreateSourceDirectory("b").getFiles().size()).isEqualTo(1);
|
||||
assertThat(this.files.getOrCreateSourceDirectory("a").getFiles()).isEmpty();
|
||||
assertThat(this.files.getOrCreateSourceDirectory("b").getFiles()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -129,7 +129,7 @@ class RestartClassLoaderTests {
|
||||
@Test
|
||||
void getResourcesFiltersDuplicates() throws Exception {
|
||||
List<URL> resources = toList(this.reloadClassLoader.getResources(PACKAGE_PATH + "/Sample.txt"));
|
||||
assertThat(resources.size()).isEqualTo(1);
|
||||
assertThat(resources).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -121,7 +121,7 @@ class HttpTunnelConnectionTests {
|
||||
write(channel, "hello");
|
||||
write(channel, "1+1");
|
||||
write(channel, "1+2");
|
||||
assertThat(this.incomingData.toString()).isEqualTo("hi=2=3");
|
||||
assertThat(this.incomingData).hasToString("hi=2=3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,8 +132,8 @@ class HttpTunnelConnectionTests {
|
||||
this.requestFactory.willRespond("hi");
|
||||
TunnelChannel channel = openTunnel(true);
|
||||
write(channel, "hello");
|
||||
assertThat(this.incomingData.toString()).isEqualTo("hi");
|
||||
assertThat(this.requestFactory.getExecutedRequests().size()).isGreaterThan(10);
|
||||
assertThat(this.incomingData).hasToString("hi");
|
||||
assertThat(this.requestFactory.getExecutedRequests()).hasSizeGreaterThan(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -78,7 +78,7 @@ class TunnelClientTests {
|
||||
channel.close();
|
||||
client.getServerThread().stopAcceptingConnections();
|
||||
client.getServerThread().join(2000);
|
||||
assertThat(this.tunnelConnection.getOpenedTimes()).isEqualTo(1);
|
||||
assertThat(this.tunnelConnection.getOpenedTimes()).isOne();
|
||||
assertThat(this.tunnelConnection.isOpen()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class HttpTunnelPayloadTests {
|
||||
@Test
|
||||
void getSequence() {
|
||||
HttpTunnelPayload payload = new HttpTunnelPayload(1, ByteBuffer.allocate(1));
|
||||
assertThat(payload.getSequence()).isEqualTo(1L);
|
||||
assertThat(payload.getSequence()).isOne();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -283,7 +283,7 @@ class HttpTunnelServerTests {
|
||||
connection.waitForResponse();
|
||||
connection.respond(HttpStatus.I_AM_A_TEAPOT);
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(418);
|
||||
assertThat(this.servletResponse.getContentLength()).isEqualTo(0);
|
||||
assertThat(this.servletResponse.getContentLength()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user