Simplify AssertJ assertions and also make them more readable

See gh-33653
This commit is contained in:
Krzysztof Krason
2022-12-29 17:52:45 +01:00
committed by Moritz Halbritter
parent c9a2b2ab66
commit cf6493f65c
345 changed files with 1258 additions and 1292 deletions

View File

@@ -407,8 +407,8 @@ abstract class AbstractPackagerTests<P extends Packager> {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
P packager = createPackager();
execute(packager, (callback) -> callback.library(newLibrary(nestedFile, LibraryScope.COMPILE, false)));
assertThat(getPackagedEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()).isEqualTo(ZipEntry.STORED);
assertThat(getPackagedEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isEqualTo(ZipEntry.STORED);
assertThat(getPackagedEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()).isZero();
assertThat(getPackagedEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isZero();
}
@Test

View File

@@ -56,7 +56,7 @@ class FileUtilsTests {
file.createNewFile();
new File(this.originDirectory, "logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isFalse();
assertThat(file).doesNotExist();
}
@Test
@@ -67,7 +67,7 @@ class FileUtilsTests {
file.createNewFile();
new File(this.originDirectory, "sub/logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isFalse();
assertThat(file).doesNotExist();
}
@Test
@@ -78,7 +78,7 @@ class FileUtilsTests {
file.createNewFile();
new File(this.originDirectory, "sub/different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isTrue();
assertThat(file).exists();
}
@Test
@@ -87,7 +87,7 @@ class FileUtilsTests {
file.createNewFile();
new File(this.originDirectory, "different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isTrue();
assertThat(file).exists();
}
@Test

View File

@@ -50,7 +50,7 @@ class LayerTests {
Layer layer1 = new Layer("testa");
Layer layer2 = new Layer("testa");
Layer layer3 = new Layer("testb");
assertThat(layer1.hashCode()).isEqualTo(layer2.hashCode());
assertThat(layer1).hasSameHashCodeAs(layer2);
assertThat(layer1).isEqualTo(layer1).isEqualTo(layer2).isNotEqualTo(layer3);
}

View File

@@ -35,7 +35,7 @@ class LibraryCoordinatesTests {
assertThat(coordinates.getGroupId()).isEqualTo("g");
assertThat(coordinates.getArtifactId()).isEqualTo("a");
assertThat(coordinates.getVersion()).isEqualTo("v");
assertThat(coordinates.toString()).isEqualTo("g:a:v");
assertThat(coordinates).hasToString("g:a:v");
}
@Test

View File

@@ -164,7 +164,7 @@ class MainClassFinderTests {
this.testJarFile.addClass("a/b/G.class", ClassWithMainMethod.class);
ClassNameCollector callback = new ClassNameCollector();
MainClassFinder.doWithMainClasses(this.testJarFile.getJarSource(), callback);
assertThat(callback.getClassNames().toString()).isEqualTo("[a.b.G, a.b.c.D]");
assertThat(callback.getClassNames()).hasToString("[a.b.G, a.b.c.D]");
}
@Test
@@ -176,7 +176,7 @@ class MainClassFinderTests {
ClassNameCollector callback = new ClassNameCollector();
try (JarFile jarFile = this.testJarFile.getJarFile()) {
MainClassFinder.doWithMainClasses(jarFile, null, callback);
assertThat(callback.getClassNames().toString()).isEqualTo("[a.b.G, a.b.c.D]");
assertThat(callback.getClassNames()).hasToString("[a.b.G, a.b.c.D]");
}
}

View File

@@ -50,8 +50,8 @@ class ZipHeaderPeekInputStreamTests {
void readIndividualBytes() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }))) {
assertThat(in.read()).isEqualTo(0);
assertThat(in.read()).isEqualTo(1);
assertThat(in.read()).isZero();
assertThat(in.read()).isOne();
assertThat(in.read()).isEqualTo(2);
assertThat(in.read()).isEqualTo(3);
assertThat(in.read()).isEqualTo(4);
@@ -99,7 +99,7 @@ class ZipHeaderPeekInputStreamTests {
void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 10 }))) {
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(1);
assertThat(in.read(bytes)).isOne();
assertThat(bytes).containsExactly(10, 0, 0, 0, 0, 0, 0, 0);
}
}