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

Migrate Jmockit VerificationsInOrder to Mockito #632

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

shivanisky
Copy link
Collaborator

@shivanisky shivanisky commented Nov 5, 2024

What's changed?

Add feature to migrate Jmockit VerificationsInOrder to mockito https://javadoc.io/doc/org.jmockit/jmockit/latest/mockit/VerificationsInOrder.html
https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/InOrder.html

What's your motivation?

Anyone you would like to review specifically?

@sambsnyd @timtebeek @tinder-dthomson as FYI

Any additional context

Only JMockit Expectations Delegate left to migrate.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@shivanisky shivanisky marked this pull request as draft November 5, 2024 12:38
@shivanisky shivanisky self-assigned this Nov 5, 2024
@shivanisky shivanisky added the enhancement New feature or request label Nov 5, 2024
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see you follow through with the penultimate feature needed to complete the JMockit migrations. I've done a very quick round of comments from GitHub; will need to look in more detail later.


class JMockitBlockRewriter {

private static final String WHEN_TEMPLATE_PREFIX = "when(#{any()}).";
private static final String VERIFY_TEMPLATE_PREFIX = "verify(#{any()}";
private static final String VERIFY_NO_INTERACTIONS_TEMPLATE_PREFIX = "verifyNoMoreInteractions(";
private static final String VERIFY_IN_ORDER_TEMPLATE_PREFIX = "inOrder(";
//private static final String VERIFY_IN_ORDER_TEMPLATE_PREFIX = "InOrder inOrder = inOrder(";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//private static final String VERIFY_IN_ORDER_TEMPLATE_PREFIX = "InOrder inOrder = inOrder(";

Copy link
Collaborator Author

@shivanisky shivanisky Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes - this is one issue I'd like to get input on
inOrder(mock) works, but
InOrder inOrder = inOrder(mock) causes error even though I have the right compilation options and the right import. Hence I am not able to get all the tests passing (have disabled for now).

Caused by: java.lang.IllegalArgumentException: Could not parse as Java
	at org.openrewrite.java.internal.template.JavaTemplateParser.lambda$compileTemplate$13(JavaTemplateParser.java:264)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at org.openrewrite.java.internal.template.JavaTemplateParser.compileTemplate(JavaTemplateParser.java:264)
	at org.openrewrite.java.internal.template.JavaTemplateParser.lambda$parseBlockStatements$9(JavaTemplateParser.java:176)
	at org.openrewrite.java.internal.template.JavaTemplateParser.lambda$cacheIfContextFree$14(JavaTemplateParser.java:287)
	at org.openrewrite.java.internal.template.JavaTemplateParser.cache(JavaTemplateParser.java:308)
	at org.openrewrite.java.internal.template.JavaTemplateParser.cacheIfContextFree(JavaTemplateParser.java:287)
	at org.openrewrite.java.internal.template.JavaTemplateParser.parseBlockStatements(JavaTemplateParser.java:171)
	at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.lambda$visitBlock$1(JavaTemplateJavaExtension.java:112)
	at org.openrewrite.internal.ListUtils.lambda$flatMap$0(ListUtils.java:261)
	at org.openrewrite.internal.ListUtils.flatMap(ListUtils.java:205)
	at org.openrewrite.internal.ListUtils.flatMap(ListUtils.java:261)
	at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitBlock(JavaTemplateJavaExtension.java:110)
	at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitBlock(JavaTemplateJavaExtension.java:55)
	at org.openrewrite.java.tree.J$Block.acceptJava(J.java:838)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	... 58 more

@timtebeek timtebeek added the recipe Recipe request label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request recipe Recipe request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants