Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerMockito doThrow(Throwable).when(Class, String, any()) not converted to Mockito single argument when #597

Open
anand188 opened this issue Sep 10, 2024 · 5 comments
Labels
enhancement New feature or request mockito recipe Recipe request

Comments

@anand188
Copy link

anand188 commented Sep 10, 2024

I am using

org.openrewrite.maven rewrite-maven-plugin 5.39.2 true org.openrewrite.java.testing.mockito.ReplacePowerMockito org.openrewrite.recipe rewrite-testing-frameworks 2.17.0

Is your project a single module or a multi-module project? Yes

Can you share your configuration so that we can rule out any configuration issues?

Is your project public? If so, can you share a link to it? no

@anand188 anand188 added the bug Something isn't working label Sep 10, 2024
@timtebeek
Copy link
Contributor

Hi @anand188 ; There's been a recent fix to the Powermock migration recipe in:

Would you mind trying again with the latest version?
https://github.com/openrewrite/rewrite-testing-frameworks/releases/tag/v2.17.1

Beyond that your question lacks the details we need to replicate the issue;
if the problems persist with the latest version I suggest you create a minimal reproducer.

@timtebeek timtebeek added the question Further information is requested label Sep 10, 2024
@anand188
Copy link
Author

anand188 commented Sep 10, 2024

@timtebeek tried 2.17.1 also doesn't seem to address the issue same not completing migrating.

@anand188
Copy link
Author

anand188 commented Sep 10, 2024

PowerMockito.doThrow(new IllegalArgumentException()).when( xx.class,"abc",any()) these are still not migrated because when in Mockito only takes single argument unlike PowerMockito

@anand188 anand188 changed the title Replace powermockito to mockito only few changes are done not completely works with when and other implementation not migrated Replace powermockito to mockito only few changes are done not completely works only change few imports fine but the when and other implementation not migrated Sep 10, 2024
@timtebeek
Copy link
Contributor

timtebeek commented Sep 10, 2024

Ah yes that form is not yet support; that makes this sounds more like a feature request to expand coverage of our Powermock migration recipe. Would you be willing to help out with it's implementation?

The first step would be a draft pull request that adds your case to this unit test; we can collaborate from there:

void powerMockitoCallsAreReplacedByMockitoCalls() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.BeforeEach;
import org.powermock.api.mockito.PowerMockito;
import java.util.Calendar;
public class MyTest {
private Calendar calendarMock;
@BeforeEach
void setUp() {
calendarMock = PowerMockito.mock(Calendar.class);
PowerMockito.doCallRealMethod().when(calendarMock).getTime();
PowerMockito.doNothing().when(calendarMock).clear();
PowerMockito.doThrow(new NullPointerException()).when(calendarMock.getCalendarType());
}
}
""",
"""
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
import java.util.Calendar;
public class MyTest {
private Calendar calendarMock;
@BeforeEach
void setUp() {
calendarMock = Mockito.mock(Calendar.class);
Mockito.doCallRealMethod().when(calendarMock).getTime();
Mockito.doNothing().when(calendarMock).clear();
Mockito.doThrow(new NullPointerException()).when(calendarMock.getCalendarType());
}
}
"""
)
);

@timtebeek timtebeek changed the title Replace powermockito to mockito only few changes are done not completely works only change few imports fine but the when and other implementation not migrated PowerMockito doThrow(Throwable).when(Class, String, any()) not converted to Mockito single argument when Sep 10, 2024
@timtebeek timtebeek added enhancement New feature or request recipe Recipe request and removed bug Something isn't working question Further information is requested labels Sep 10, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Sep 10, 2024
@anand188
Copy link
Author

@timtebeek thanks let me see if its possible for me to learn and update this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mockito recipe Recipe request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants