Skip to content

Commit cb47cfe

Browse files
AssertJ best practices
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.testing.assertj.Assertj?organizationId=ODQ2MGExMTUtNDg0My00N2EwLTgzMGMtNGE1NGExMTBmZDkw Co-authored-by: Moderne <team@moderne.io>
1 parent 8c5b3f4 commit cb47cfe

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/test/java/org/openrewrite/java/dependencies/DependencyResolutionDiagnosticTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ void gradle() {
6868
// It is a limitation of the tooling API which prevents configuration-granularity error information from being collected.
6969
// So the GradleDependencyConfigurationErrors table will never be populated in unit tests.
7070
.dataTable(RepositoryAccessibilityReport.Row.class, rows -> {
71-
assertThat(rows).hasSize(4);
72-
assertThat(rows).contains(
71+
assertThat(rows)
72+
.hasSize(4)
73+
.contains(
7374
new RepositoryAccessibilityReport.Row("https://repo.maven.apache.org/maven2", "", "", 200, "", ""));
7475
assertThat(rows).filteredOn(row -> row.getUri().startsWith("file:/") && "".equals(row.getPingExceptionMessage())).hasSize(1);
7576
assertThat(rows).contains(
@@ -107,10 +108,11 @@ void gradleNoDefaultRepos() {
107108
// It is a limitation of the tooling API which prevents configuration-granularity error information from being collected.
108109
// So the GradleDependencyConfigurationErrors table will never be populated in unit tests.
109110
.dataTable(RepositoryAccessibilityReport.Row.class, rows -> {
110-
assertThat(rows).hasSize(2);
111-
assertThat(rows).contains(
112-
new RepositoryAccessibilityReport.Row("https://plugins.gradle.org/m2", "", "", 200, "", ""));
113-
assertThat(rows).contains(
111+
assertThat(rows)
112+
.hasSize(2)
113+
.contains(
114+
new RepositoryAccessibilityReport.Row("https://plugins.gradle.org/m2", "", "", 200, "", ""))
115+
.contains(
114116
new RepositoryAccessibilityReport.Row("https://nonexistent.moderne.io/maven2", "java.net.UnknownHostException", "nonexistent.moderne.io", null, "", ""));
115117
}),
116118
//language=groovy
@@ -157,10 +159,11 @@ void mavenSettingsWithMirrors() {
157159
ctx.setMavenSettings(settings);
158160
spec.beforeRecipe(withToolingApi())
159161
.dataTable(RepositoryAccessibilityReport.Row.class, rows -> {
160-
assertThat(rows).contains(
162+
assertThat(rows)
163+
.contains(
161164
new RepositoryAccessibilityReport.Row("https://nonexistent.moderne.io/maven2", "java.net.UnknownHostException", "nonexistent.moderne.io", null, "", "")
162-
);
163-
assertThat(rows).noneMatch(repo -> repo.getUri().contains("https://repo.maven.apache.org/maven2"));
165+
)
166+
.noneMatch(repo -> repo.getUri().contains("https://repo.maven.apache.org/maven2"));
164167
})
165168
.executionContext(ctx);
166169
},

src/test/java/org/openrewrite/java/dependencies/internal/StaticVersionComparatorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class StaticVersionComparatorTest {
2626

2727
@Test
2828
void milestone() {
29-
assertThat(svc.compare(v("2.0.0"), v("1.0.0"))).isEqualTo(1);
30-
assertThat(svc.compare(v("1.0.0"), v("1.0.0-M1"))).isEqualTo(1);
31-
assertThat(svc.compare(v("1.0.0-M2"), v("1.0.0-M1"))).isEqualTo(1);
32-
assertThat(svc.compare(v("1.0.0-rc-1"), v("1.0.0-M1"))).isEqualTo(1);
29+
assertThat(svc.compare(v("2.0.0"), v("1.0.0"))).isOne();
30+
assertThat(svc.compare(v("1.0.0"), v("1.0.0-M1"))).isOne();
31+
assertThat(svc.compare(v("1.0.0-M2"), v("1.0.0-M1"))).isOne();
32+
assertThat(svc.compare(v("1.0.0-rc-1"), v("1.0.0-M1"))).isOne();
3333
}
3434

3535
Version v(String version) {

0 commit comments

Comments
 (0)