Commit 05d0013
Various JMockit fixes (#824)
* Fix mockStatic error in JMockitToMockito (#776)
- Use getFullyQualifiedName() instead of getClassName() for nullable() matchers to avoid ambiguity with same-named classes
- Fix syntax error in getCallRealMethod() by properly handling semicolon
- Add ShortenFullyQualifiedTypeReferences to shorten FQN types where safe
- Add test case to verify thenCallRealMethod() generates correct syntax
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix variable name conflicts in JMockitToMockito (#777)
When setup statements are moved out of Expectations blocks, variable
declarations in the setup statements could conflict with variable
declarations in the method body, causing compilation errors.
This fix detects such conflicts and wraps the setup statements in a
block to maintain proper scoping when conflicts are detected.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix IndexOutOfBoundsException in RemoveTimesZeroAndOne with custom classes
Fixes #748
When converting JMockit Verifications with `times = 1` to Mockito for custom classes,
the RemoveTimesZeroAndOne recipe was failing with IndexOutOfBoundsException because
getParameterTypes() returned an empty list when type information was incomplete.
Changes:
- Check if parameter types list is empty before calling subList()
- If empty, only remove the times() argument without modifying method type
- Add test case with custom class to verify the fix
- Disable method invocation type validation in the test as type info may be incomplete
* Refactor to use direct AST manipulation instead of JavaTemplate
Previously, `removeBlock()` and `rewriteBodyStatement()` were using
JavaTemplate inappropriately - using empty strings or `#{any()}` just
to manipulate AST structure. This was inefficient and error-prone.
Changes:
- Refactored `removeBlock()` to directly manipulate the statements list
- Refactored `rewriteBodyStatement()` to use direct AST manipulation
with proper tree node comparison using `.isScope()`
- Fixed issue #687: Added check for empty Expectations blocks to
prevent IndexOutOfBoundsException
- Added regression test `emptyExpectationsBlockDoesNotCrash()`
* Add contextSensitive() to JavaTemplate in JMockitBlockRewriter
Using `.contextSensitive()` allows the JavaTemplate to use type
information from the surrounding code context, which can improve type
attribution in generated code. While this doesn't fully solve issue #748's
type attribution problem with custom classes (which still requires
disabling type validation for method invocations), it's a best practice
that may help in other scenarios.
All 91 tests pass with 100% success.
* Fix type attribution in verify() calls by using AST manipulation
Issue #748: verify() calls with custom classes were generating
"MethodInvocation type is missing or malformed" errors.
Root cause: JavaTemplate can only resolve types on the classpath,
not types defined in the source code being transformed.
Solution: Template verify() with placeholder types (String, int),
then replace placeholders with actual AST nodes from the original code:
1. Template: verify("", times(1)).toString()
2. Replace "" with actual mock
3. Replace 1 with actual times value
4. Replace toString() with actual method invocation
This preserves all type information from the original invocation.
Also fixed: Filter out times(1) since it's the default.
Fixes #748
All 91 JMockit tests pass with full type validation enabled.
* Polish
* Polish
* Polish
---------
Co-authored-by: Claude <[email protected]>1 parent 093bc47 commit 05d0013
File tree
9 files changed
+410
-53
lines changed- src
- main/java/org/openrewrite/java/testing
- jmockit
- mockito
- test/java/org/openrewrite/java/testing/jmockit
9 files changed
+410
-53
lines changedLines changed: 103 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
174 | 173 | | |
175 | 174 | | |
176 | 175 | | |
177 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
| |||
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | 198 | | |
194 | 199 | | |
| |||
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
231 | 243 | | |
232 | | - | |
233 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
234 | 251 | | |
235 | 252 | | |
236 | | - | |
237 | 253 | | |
238 | 254 | | |
239 | | - | |
240 | 255 | | |
241 | 256 | | |
242 | | - | |
243 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
244 | 302 | | |
245 | 303 | | |
246 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
247 | 330 | | |
248 | | - | |
| 331 | + | |
249 | 332 | | |
250 | 333 | | |
251 | | - | |
252 | | - | |
253 | 334 | | |
254 | 335 | | |
255 | 336 | | |
| |||
487 | 568 | | |
488 | 569 | | |
489 | 570 | | |
490 | | - | |
491 | | - | |
492 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
493 | 574 | | |
494 | 575 | | |
495 | 576 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
161 | | - | |
162 | | - | |
| 161 | + | |
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
| |||
307 | 306 | | |
308 | 307 | | |
309 | 308 | | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | | - | |
| 338 | + | |
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| |||
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
438 | | - | |
439 | 438 | | |
440 | 439 | | |
441 | 440 | | |
| |||
Lines changed: 68 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | | - | |
21 | | - | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| |||
55 | 52 | | |
56 | 53 | | |
57 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | | - | |
70 | | - | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
81 | 103 | | |
82 | 104 | | |
83 | 105 | | |
| |||
91 | 113 | | |
92 | 114 | | |
93 | 115 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
102 | 141 | | |
103 | 142 | | |
104 | 143 | | |
| |||
163 | 202 | | |
164 | 203 | | |
165 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
166 | 218 | | |
Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
0 commit comments