Commit 43acae3
authored
Refactor PowerMockito recipes for clarity and single responsibility (#943)
* Refactor PowerMockitoMockStaticToMockito for clarity and single responsibility
Extract independent responsibilities from the monolithic 557-line recipe:
- Extract `RemovePowerMockClassExtensions` recipe for removing
`extends PowerMockConfiguration` and `extends PowerMockTestCase`
- Fold `@RunWith(PowerMockRunner.class)` removal (with and without
delegate) into `PowerMockRunnerDelegateToRunWith`
- Replace 8 mutable instance fields with a `TestFramework` enum
- Add early returns throughout to reduce nesting and improve readability
* Clean up PowerMockitoMockStaticToMockito visitor
- Consolidate isStaticMockAlreadyClosed/isStaticMockAlreadyOpened into
single hasMatchingInvocation method parameterized by MethodMatcher
- Restructure visitMethodInvocation with early returns for clarity
- Fix double getTestGroupsAsString() call in maybeAddTearDownMethodBody
- Simplify mockStatic tracking to use direct list access instead of
Optional stream
* Improve PowerMockRunnerDelegateToRunWith per review feedback
- Use service(AnnotationService.class) instead of manual stream check
- Extract findDelegateRunnerArg method to avoid finalDelegateRunnerArg
- Move shared maybeRemoveImport(POWER_MOCK_RUNNER) above if/else so
each branch can return immediately
* Move import removal before withLeadingAnnotations for immediate returns
* Update src/main/java/org/openrewrite/java/testing/mockito/PowerMockRunnerDelegateToRunWith.java1 parent a72d7b1 commit 43acae3
9 files changed
Lines changed: 444 additions & 345 deletions
File tree
- src
- main
- java/org/openrewrite/java/testing/mockito
- resources/META-INF/rewrite
- test/java/org/openrewrite/java/testing/mockito
Lines changed: 47 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | | - | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
47 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
56 | 62 | | |
57 | 63 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 64 | + | |
| 65 | + | |
72 | 66 | | |
73 | 67 | | |
74 | | - | |
75 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
76 | 84 | | |
77 | 85 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
90 | 95 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
95 | 111 | | |
96 | 112 | | |
97 | 113 | | |
| |||
0 commit comments