-
Notifications
You must be signed in to change notification settings - Fork 52
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
Assert instance of migration #372
Assert instance of migration #372
Conversation
Added recipe which migrates JUnit4 (or JUnit5) assertTrue(x instanceof y) into JUnit5 assertInstanceOf(y.class, x) Signed-off-by: matus.matok <matus.matok@pantheon.tech>
Added recipe which migrates JUnit4 (or JUnit5) assertTrue(x instanceof y) into JUnit5 assertInstanceOf(y.class, x) Signed-off-by: matus.matok <matus.matok@pantheon.tech>
Firstly, if this is something that is already covered in the project, shut me down. Secondly, I am kinda desparate about the method matcher: |
@Override | ||
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) { | ||
J.MethodInvocation mi = super.visitMethodInvocation(method, executionContext); | ||
MethodMatcher junit5Matcher = new MethodMatcher("org.junit.jupiter.api.Assertions assertTrue(* instanceof *,String)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see what you are trying to do here. Unfortunately MethodMatcher
can't do that, but since the rest of your code already properly checks the parameter for J.InstanceOf
, all you have to do is this:
MethodMatcher junit5Matcher = new MethodMatcher("org.junit.jupiter.api.Assertions assertTrue(* instanceof *,String)"); | |
MethodMatcher junit5Matcher = new MethodMatcher("org.junit.jupiter.api.Assertions assertTrue(boolean, ..)"); |
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) { | ||
J.MethodInvocation mi = super.visitMethodInvocation(method, executionContext); | ||
MethodMatcher junit5Matcher = new MethodMatcher("org.junit.jupiter.api.Assertions assertTrue(* instanceof *,String)"); | ||
MethodMatcher junit4Matcher = new MethodMatcher("org.junit.Assert assertTrue(..,* instanceof *)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here:
MethodMatcher junit4Matcher = new MethodMatcher("org.junit.Assert assertTrue(..,* instanceof *)"); | |
MethodMatcher junit4Matcher = new MethodMatcher("org.junit.Assert assertTrue(.., boolean)"); |
Fixed method matchers to work properly. Signed-off-by: matus.matok <matus.matok@pantheon.tech>
Added recipe which migrates JUnit4 (or JUnit5) assertTrue(x instanceof y) into JUnit5 assertInstanceOf(y.class, x)
What's changed?
Added recipe which migrates JUnit4 (or JUnit5) assertTrue(x instanceof y) into JUnit5 assertInstanceOf(y.class, x)
Checklist
./gradlew licenseFormat