openrewrite / openrewrite/rewrite-testing-frameworks
Powermock replacement: Powermock.mockStatic() with Multiple Classes leads to compilation errors
Open
Nobody has claimed this yet.
bug
mockito
recipe
- Dominant language
- Java
- Stars
- 100
- Forks
- 105
- Avg merge
- 2h 25m
- Merged PRs (30d)
- 9
Description
What version of OpenRewrite are you using?
I am using
- OpenRewrite latest
- Maven/Gradle plugin-
- rewrite-module latest
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a multi module project.
What is the smallest, simplest way to reproduce the problem?
@RunWith(PowerMockRunner.class)
@PrepareForTest( {B.class, C.class })
public class A
{
@Before
public void setup()
{
PowerMockito.mockStatic(B.class, C.class);
}
}
What did you expect to see?
public class A
{
private MockedStatic<B> mockedB;
private MockedStatic<C> mockedC;
@Before
public void setup()
{
mockedB = Mockito.mockStatic(B.class);
mockedC = Mockito.mockStatic(C.class);
}
}
What did you see instead?
public class A
{
private MockedStatic<B> mockedB;
@Before
public void setup()
{
mockedB = Mockito.mockStatic(B.class, C.class); // leads to compilation error
}
}
What is the full stack trace of any errors you encountered?
java: no suitable method found for mockStatic(java.lang.Class<>,java.lang.Class<>)
method org.mockito.Mockito.<T>mockStatic(java.lang.Class<T>) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
method org.mockito.Mockito.<T>mockStatic(java.lang.Class<T>,org.mockito.stubbing.Answer) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; java.lang.Class<> cannot be converted to org.mockito.stubbing.Answer))
method org.mockito.Mockito.<T>mockStatic(java.lang.Class<T>,java.lang.String) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; java.lang.Class<> cannot be converted to java.lang.String))
method org.mockito.Mockito.<T>mockStatic(java.lang.Class<T>,org.mockito.MockSettings) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; java.lang.Class<> cannot be converted to org.mockito.MockSettings))
Are you interested in contributing a fix to OpenRewrite?
Depends on if I have time
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the OpenRewrite recipe that migrates PowerMockito.mockStatic calls, then reproduce the issue with the multi-class example from the report. Compare the current transformation with the expected separate MockedStatic fields and mockStatic calls. Done means the generated Java compiles and a regression test covers multiple classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100