Skip to content

Powermock replacement: Powermock.mockStatic() with Multiple Classes leads to compilation errors #697

@blamepotato

Description

@blamepotato

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmockitorecipeRecipe request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions