Skip to content

Commit d1a8aee

Browse files
author
Riker
committed
Use AssertJ 3.27.7 for test assertions instead of JUnit assertions
1 parent 7b22be3 commit d1a8aee

5 files changed

Lines changed: 61 additions & 79 deletions

File tree

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<checkstyle.version>13.4.2</checkstyle.version>
1515
<junit.version>6.1.0</junit.version>
16+
<assertj.version>3.27.7</assertj.version>
1617
<errorprone.version>2.49.0</errorprone.version>
1718
<nullaway.version>0.13.4</nullaway.version>
1819
</properties>
@@ -37,6 +38,13 @@
3738
<version>${junit.version}</version>
3839
<scope>test</scope>
3940
</dependency>
41+
<!-- Source: https://mvnrepository.com/artifact/org.assertj/assertj-core -->
42+
<dependency>
43+
<groupId>org.assertj</groupId>
44+
<artifactId>assertj-core</artifactId>
45+
<version>${assertj.version}</version>
46+
<scope>test</scope>
47+
</dependency>
4048
</dependencies>
4149

4250
<build>

src/test/java/it/aboutbits/checkstyle/JSpecifyAnnotationOrderCheckTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import java.util.List;
77
import java.util.Map;
88

9-
import static org.junit.jupiter.api.Assertions.assertEquals;
10-
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
import static org.assertj.core.api.Assertions.assertThat;
1110

1211
@NullMarked
1312
class JSpecifyAnnotationOrderCheckTest extends CheckTestSupport {
@@ -17,40 +16,40 @@ class JSpecifyAnnotationOrderCheckTest extends CheckTestSupport {
1716
@Test
1817
void jspecifyAnnotationAsLastPasses() throws Exception {
1918
var v = runCheck(JSpecifyAnnotationOrderCheck.class, BASE + "GoodLast.java");
20-
assertEquals(List.of(), v);
19+
assertThat(v).isEmpty();
2120
}
2221

2322
@Test
2423
void jspecifyAnnotationFollowedByOtherFailsAndHighlightsCloseAnnotation() throws Exception {
2524
var v = runCheck(JSpecifyAnnotationOrderCheck.class, BASE + "BadInMiddle.java");
26-
assertEquals(1, v.size());
27-
assertTrue(v.getFirst().contains(NullMarked.class.getSimpleName()), v.toString());
28-
assertTrue(v.getFirst().startsWith("6:"), "violation should be reported on the @NullMarked line: " + v);
25+
assertThat(v).hasSize(1);
26+
assertThat(v.getFirst()).contains(NullMarked.class.getSimpleName());
27+
assertThat(v.getFirst()).startsWith("6:");
2928
}
3029

3130
@Test
3231
void jspecifyAnnotationAsFirstFailsAndHighlightsCloseAnnotation() throws Exception {
3332
var v = runCheck(JSpecifyAnnotationOrderCheck.class, BASE + "BadFirst.java");
34-
assertEquals(1, v.size());
35-
assertTrue(v.getFirst().startsWith("5:"), "violation should be reported on the @NullMarked line: " + v);
33+
assertThat(v).hasSize(1);
34+
assertThat(v.getFirst()).startsWith("5:");
3635
}
3736

3837
@Test
3938
void noJspecifyAnnotationDoesNotFire() throws Exception {
4039
var v = runCheck(JSpecifyAnnotationOrderCheck.class, BASE + "NoJSpecify.java");
41-
assertEquals(List.of(), v);
40+
assertThat(v).isEmpty();
4241
}
4342

4443
@Test
4544
void customCloseAnnotationsArePicked() throws Exception {
4645
var properties = Map.of("closeAnnotations", "Custom,AnotherClose");
4746

4847
var ok = runCheck(JSpecifyAnnotationOrderCheck.class, BASE + "CustomCloseLast.java", properties);
49-
assertEquals(List.of(), ok);
48+
assertThat(ok).isEmpty();
5049

5150
var bad = runCheck(JSpecifyAnnotationOrderCheck.class, BASE + "CustomCloseInMiddle.java", properties);
52-
assertEquals(1, bad.size());
53-
assertTrue(bad.getFirst().contains("Custom"), bad.toString());
51+
assertThat(bad).hasSize(1);
52+
assertThat(bad.getFirst()).contains("Custom");
5453
}
5554

5655
@Test
@@ -60,6 +59,6 @@ void closeAnnotationsAreTrimmed() throws Exception {
6059
BASE + "GoodLast.java",
6160
Map.of("closeAnnotations", " NullMarked , NullUnmarked ")
6261
);
63-
assertEquals(List.of(), v);
62+
assertThat(v).isEmpty();
6463
}
6564
}

src/test/java/it/aboutbits/checkstyle/JSpecifyInlineTypeUseCheckTest.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import org.jspecify.annotations.NullMarked;
44
import org.junit.jupiter.api.Test;
55

6-
import java.util.List;
7-
8-
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.assertj.core.api.Assertions.assertThat;
97

108
@NullMarked
119
class JSpecifyInlineTypeUseCheckTest extends CheckTestSupport {
@@ -14,67 +12,61 @@ class JSpecifyInlineTypeUseCheckTest extends CheckTestSupport {
1412

1513
@Test
1614
void inlineMethodReturnPasses() throws Exception {
17-
assertEquals(List.of(), runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineMethod.java"));
15+
assertThat(runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineMethod.java")).isEmpty();
1816
}
1917

2018
@Test
2119
void inlineFieldPasses() throws Exception {
22-
assertEquals(List.of(), runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineField.java"));
20+
assertThat(runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineField.java")).isEmpty();
2321
}
2422

2523
@Test
2624
void inlineParameterPasses() throws Exception {
27-
assertEquals(List.of(), runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineParameter.java"));
25+
assertThat(runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineParameter.java")).isEmpty();
2826
}
2927

3028
@Test
3129
void inlineLocalPasses() throws Exception {
32-
assertEquals(List.of(), runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineLocal.java"));
30+
assertThat(runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "GoodInlineLocal.java")).isEmpty();
3331
}
3432

3533
@Test
3634
void annotationOnLineAboveMethodFails() throws Exception {
3735
var v = runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "BadAboveMethod.java");
38-
assertEquals(1, v.size(), v.toString());
36+
assertThat(v).hasSize(1);
3937
}
4038

4139
@Test
4240
void annotationOnLineAboveFieldFails() throws Exception {
4341
var v = runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "BadAboveField.java");
44-
assertEquals(1, v.size(), v.toString());
42+
assertThat(v).hasSize(1);
4543
}
4644

4745
@Test
4846
void annotationOnLineAboveParameterFails() throws Exception {
4947
var v = runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "BadAboveParameter.java");
50-
assertEquals(1, v.size(), v.toString());
48+
assertThat(v).hasSize(1);
5149
}
5250

5351
@Test
5452
void annotationOnLineAboveLocalFails() throws Exception {
5553
var v = runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "BadAboveLocal.java");
56-
assertEquals(1, v.size(), v.toString());
54+
assertThat(v).hasSize(1);
5755
}
5856

5957
@Test
6058
void nonJspecifyNullableImportedFromElsewhereIsIgnored() throws Exception {
61-
assertEquals(
62-
List.of(),
63-
runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "NonJSpecifyNullableAboveFieldIgnored.java")
64-
);
59+
assertThat(runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "NonJSpecifyNullableAboveFieldIgnored.java")).isEmpty();
6560
}
6661

6762
@Test
6863
void nonJspecifyFullyQualifiedNullableIsIgnored() throws Exception {
69-
assertEquals(
70-
List.of(),
71-
runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "NonJSpecifyFqnNullableAboveFieldIgnored.java")
72-
);
64+
assertThat(runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "NonJSpecifyFqnNullableAboveFieldIgnored.java")).isEmpty();
7365
}
7466

7567
@Test
7668
void fullyQualifiedJspecifyNullableAboveFieldFails() throws Exception {
7769
var v = runCheck(JSpecifyInlineTypeUseCheck.class, BASE + "JSpecifyFqnAboveFieldFails.java");
78-
assertEquals(1, v.size(), v.toString());
70+
assertThat(v).hasSize(1);
7971
}
8072
}

src/test/java/it/aboutbits/checkstyle/JSpecifyMapStructMapperAnnotationCheckTest.java

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import org.jspecify.annotations.NullMarked;
44
import org.junit.jupiter.api.Test;
55

6-
import java.util.List;
76
import java.util.Map;
87

9-
import static org.junit.jupiter.api.Assertions.assertEquals;
10-
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
import static org.assertj.core.api.Assertions.assertThat;
119

1210
@NullMarked
1311
class JSpecifyMapStructMapperAnnotationCheckTest extends CheckTestSupport {
@@ -16,98 +14,86 @@ class JSpecifyMapStructMapperAnnotationCheckTest extends CheckTestSupport {
1614

1715
@Test
1816
void wellOrderedMapperPasses() throws Exception {
19-
assertEquals(List.of(), runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java"));
17+
assertThat(runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java")).isEmpty();
2018
}
2119

2220
@Test
2321
void mapperWithNamedValueArgumentPasses() throws Exception {
24-
assertEquals(
25-
List.of(),
26-
runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapperNamedValue.java")
27-
);
22+
assertThat(runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapperNamedValue.java")).isEmpty();
2823
}
2924

3025
@Test
3126
void swappedOrderFails() throws Exception {
3227
var v = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "BadOrderSwapped.java");
33-
assertEquals(1, v.size());
34-
assertTrue(v.getFirst().contains("BadOrderSwapped"), v.toString());
28+
assertThat(v).hasSize(1);
29+
assertThat(v.getFirst()).contains("BadOrderSwapped");
3530
}
3631

3732
@Test
3833
void missingAnnotateWithFails() throws Exception {
3934
var v = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "BadMissingAnnotateWith.java");
40-
assertEquals(1, v.size());
35+
assertThat(v).hasSize(1);
4136
}
4237

4338
@Test
4439
void annotateWithWrongClassLiteralFails() throws Exception {
4540
var v = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "BadWrongClassLiteral.java");
46-
assertEquals(1, v.size());
41+
assertThat(v).hasSize(1);
4742
}
4843

4944
@Test
5045
void interfaceWithoutMapperIsIgnored() throws Exception {
51-
assertEquals(
52-
List.of(),
53-
runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "NonMapperInterfaceIgnored.java")
54-
);
46+
assertThat(runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "NonMapperInterfaceIgnored.java")).isEmpty();
5547
}
5648

5749
@Test
5850
void customMapperAnnotationNameIsHonored() throws Exception {
5951
var properties = Map.of("mapperAnnotationName", "MyMapper");
6052

6153
var ok = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "CustomMapperGood.java", properties);
62-
assertEquals(List.of(), ok);
54+
assertThat(ok).isEmpty();
6355

6456
var bad = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "CustomMapperBad.java", properties);
65-
assertEquals(1, bad.size());
66-
assertTrue(bad.getFirst().contains("CustomMapperBad"), bad.toString());
57+
assertThat(bad).hasSize(1);
58+
assertThat(bad.getFirst()).contains("CustomMapperBad");
6759
}
6860

6961
@Test
7062
void customAnnotateWithAnnotationNameIsHonored() throws Exception {
7163
var properties = Map.of("annotateWithAnnotationName", "MyAnnotateWith");
7264

7365
var ok = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "CustomAnnotateWithGood.java", properties);
74-
assertEquals(List.of(), ok);
66+
assertThat(ok).isEmpty();
7567

7668
var bad = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java", properties);
77-
assertEquals(1, bad.size(), bad.toString());
69+
assertThat(bad).hasSize(1);
7870
}
7971

8072
@Test
8173
void customNullUnmarkedAnnotationNameIsHonored() throws Exception {
8274
var properties = Map.of("nullUnmarkedAnnotationName", "MyUnmarked");
8375

8476
var ok = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "CustomNullUnmarkedGood.java", properties);
85-
assertEquals(List.of(), ok);
77+
assertThat(ok).isEmpty();
8678

8779
var bad = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java", properties);
88-
assertEquals(1, bad.size(), bad.toString());
80+
assertThat(bad).hasSize(1);
8981
}
9082

9183
@Test
9284
void wellOrderedAbstractClassMapperPasses() throws Exception {
93-
assertEquals(
94-
List.of(),
95-
runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodAbstractMapper.java")
96-
);
85+
assertThat(runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "GoodAbstractMapper.java")).isEmpty();
9786
}
9887

9988
@Test
10089
void abstractClassMapperWithSwappedOrderFails() throws Exception {
10190
var v = runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "BadAbstractMapperOrderSwapped.java");
102-
assertEquals(1, v.size());
103-
assertTrue(v.getFirst().contains("BadAbstractMapperOrderSwapped"), v.toString());
91+
assertThat(v).hasSize(1);
92+
assertThat(v.getFirst()).contains("BadAbstractMapperOrderSwapped");
10493
}
10594

10695
@Test
10796
void nonAbstractClassWithMapperAnnotationIsIgnored() throws Exception {
108-
assertEquals(
109-
List.of(),
110-
runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "NonAbstractClassWithMapperAnnotationIgnored.java")
111-
);
97+
assertThat(runCheck(JSpecifyMapStructMapperAnnotationCheck.class, BASE + "NonAbstractClassWithMapperAnnotationIgnored.java")).isEmpty();
11298
}
11399
}

src/test/java/it/aboutbits/checkstyle/JSpecifyOnTopLevelTypesCheckTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import org.jspecify.annotations.NullMarked;
44
import org.junit.jupiter.api.Test;
55

6-
import java.util.List;
7-
8-
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
import static org.assertj.core.api.Assertions.assertThat;
107

118
@NullMarked
129
class JSpecifyOnTopLevelTypesCheckTest extends CheckTestSupport {
@@ -16,44 +13,44 @@ class JSpecifyOnTopLevelTypesCheckTest extends CheckTestSupport {
1613
@Test
1714
void classMarkedWithNullMarkedPasses() throws Exception {
1815
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "GoodMarked.java");
19-
assertEquals(List.of(), v);
16+
assertThat(v).isEmpty();
2017
}
2118

2219
@Test
2320
void classMarkedWithNullUnmarkedPasses() throws Exception {
2421
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "GoodUnmarked.java");
25-
assertEquals(List.of(), v);
22+
assertThat(v).isEmpty();
2623
}
2724

2825
@Test
2926
void fullyQualifiedJspecifyAnnotationPasses() throws Exception {
3027
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "GoodFullyQualified.java");
31-
assertEquals(List.of(), v);
28+
assertThat(v).isEmpty();
3229
}
3330

3431
@Test
3532
void classWithoutJspecifyAnnotationFails() throws Exception {
3633
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "BadMissing.java");
37-
assertEquals(1, v.size());
38-
assertTrue(v.getFirst().contains("BadMissing"), v.toString());
34+
assertThat(v).hasSize(1);
35+
assertThat(v.getFirst()).contains("BadMissing");
3936
}
4037

4138
@Test
4239
void annotationDeclarationIsExempt() throws Exception {
4340
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "AnnotationDefExempt.java");
44-
assertEquals(List.of(), v);
41+
assertThat(v).isEmpty();
4542
}
4643

4744
@Test
4845
void nestedClassIsNotChecked() throws Exception {
4946
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "NestedClassOnly.java");
50-
assertEquals(List.of(), v);
47+
assertThat(v).isEmpty();
5148
}
5249

5350
@Test
5451
void recordWithoutJspecifyFails() throws Exception {
5552
var v = runCheck(JSpecifyOnTopLevelTypesCheck.class, BASE + "BadRecord.java");
56-
assertEquals(1, v.size());
57-
assertTrue(v.getFirst().contains("BadRecord"), v.toString());
53+
assertThat(v).hasSize(1);
54+
assertThat(v.getFirst()).contains("BadRecord");
5855
}
5956
}

0 commit comments

Comments
 (0)