@@ -101,6 +101,124 @@ void testMethod(List<String> list) {
101
101
);
102
102
}
103
103
104
+ @ Nested
105
+ class CollapseAfterConversion {
106
+ @ Test
107
+ void hamcrestToCollapsedAssertions () {
108
+ rewriteRun (
109
+ spec -> spec .parser (JavaParser .fromJavaVersion ().classpathFromResources (new InMemoryExecutionContext (), "hamcrest-3" )),
110
+ //language=java
111
+ java (
112
+ """
113
+ import java.util.List;
114
+
115
+ import static org.hamcrest.MatcherAssert.assertThat;
116
+ import static org.hamcrest.Matchers.*;
117
+
118
+ class BiscuitTest {
119
+ void biscuits() {
120
+ List<String> biscuits = List.of("Ginger", "Chocolate", "Oatmeal");
121
+ assertThat(biscuits, is(not(nullValue())));
122
+ assertThat(biscuits, hasSize(3));
123
+ assertThat(biscuits, hasItem("Chocolate"));
124
+ }
125
+ }
126
+ """ ,
127
+ """
128
+ import java.util.List;
129
+
130
+ import static org.assertj.core.api.Assertions.assertThat;
131
+
132
+ class BiscuitTest {
133
+ void biscuits() {
134
+ List<String> biscuits = List.of("Ginger", "Chocolate", "Oatmeal");
135
+ assertThat(biscuits).isNotNull();
136
+ assertThat(biscuits)
137
+ .hasSize(3)
138
+ .contains("Chocolate");
139
+ }
140
+ }
141
+ """
142
+ )
143
+ );
144
+ }
145
+
146
+ @ Test
147
+ void junitCollapsedAssertions () {
148
+ rewriteRun (
149
+ spec -> spec .parser (JavaParser .fromJavaVersion ().classpathFromResources (new InMemoryExecutionContext (), "junit-jupiter-api-5" )),
150
+ //language=java
151
+ java (
152
+ """
153
+ import java.util.List;
154
+
155
+ import static org.junit.jupiter.api.Assertions.*;
156
+
157
+ class BiscuitTest {
158
+ void biscuits() {
159
+ List<String> biscuits = List.of("Ginger", "Chocolate", "Oatmeal");
160
+ assertNotNull(biscuits);
161
+ assertEquals(3, biscuits.size());
162
+ assertTrue(biscuits.contains("Chocolate"));
163
+ }
164
+ }
165
+ """ ,
166
+ """
167
+ import java.util.List;
168
+
169
+ import static org.assertj.core.api.Assertions.assertThat;
170
+
171
+ class BiscuitTest {
172
+ void biscuits() {
173
+ List<String> biscuits = List.of("Ginger", "Chocolate", "Oatmeal");
174
+ assertThat(biscuits)
175
+ .hasSize(3)
176
+ .contains("Chocolate");
177
+ }
178
+ }
179
+ """
180
+ )
181
+ );
182
+ }
183
+
184
+ @ Test
185
+ void assertjCollapsedAssertions () {
186
+ rewriteRun (
187
+ //language=java
188
+ java (
189
+ """
190
+ import java.util.List;
191
+
192
+ import static org.assertj.core.api.Assertions.assertThat;
193
+
194
+ class BiscuitTest {
195
+ void biscuits() {
196
+ List<String> biscuits = List.of("Ginger", "Chocolate", "Oatmeal");
197
+ assertThat(biscuits).isNotNull();
198
+ assertThat(biscuits).hasSize(3);
199
+ assertThat(biscuits).contains("Chocolate");
200
+ }
201
+ }
202
+ """ ,
203
+ """
204
+ import java.util.List;
205
+
206
+ import static org.assertj.core.api.Assertions.assertThat;
207
+
208
+ class BiscuitTest {
209
+ void biscuits() {
210
+ List<String> biscuits = List.of("Ginger", "Chocolate", "Oatmeal");
211
+ assertThat(biscuits)
212
+ .hasSize(3)
213
+ .contains("Chocolate");
214
+ }
215
+ }
216
+ """
217
+ )
218
+ );
219
+ }
220
+ }
221
+
104
222
/**
105
223
* Chained AssertJ assertions should be simplified to the corresponding dedicated assertion, as
106
224
* per <a
0 commit comments