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

Upgrade Mockito to 3.x #73

Merged
merged 9 commits into from
Jun 2, 2021
Merged

Upgrade Mockito to 3.x #73

merged 9 commits into from
Jun 2, 2021

Conversation

GreyTeardrop
Copy link
Contributor

@GreyTeardrop GreyTeardrop commented Feb 5, 2021

Overview & motivation

Update test code to Mockito 3 and adapt when needed. This PR is inspired by temporalio/sdk-java#332 and should provide an example of how a recent Mockito can be used with Temporal SDK.

Details

  • Upgrade Mockito and PowerMock to the latest versions
  • Fix deprecation warnings
  • Use withSettings().withoutAnnotations() in HelloActivityTest to prevent Mockito from copying annotations from activity interface to mock class
  • Re-enable HelloChildTest.testMockedChild() and HelloExceptionTest.testChildWorkflowTimeout() as they no longer fail with Mockito 3, presumably due to Mockito's switch to ByteBuddy

* Upgrade Mockito and PowerMock to the latest version
* Fix deprecation warnings
* Use withSettings().withoutAnnotations() in HelloActivityTest to
  prevent Mockito from copying annotations from activity interface to
  mock class
* Re-enable HelloChildTest.testMockedChild() and
  HelloExceptionTest.testChildWorkflowTimeout() as they no longer fail
  with Mockito 3
@GreyTeardrop
Copy link
Contributor Author

@mfateev @vitarb I've noticed that Java SDK is getting Mockito 3 in the scope of temporalio/sdk-java#360. Do you think it's worth upgrading samples as well?

The annotation is added for illustration purposes to show that Mockito's
withSettings().withoutAnnotations() is required to mock an activity that
has that annotation on a method.
@tsurdilo
Copy link
Contributor

@GreyTeardrop will need to be rebased. Also if you have time let's check if there are any examples tests that were added recently needs an update as well. Thanks!

@GreyTeardrop
Copy link
Contributor Author

Thank you, @tsurdilo! I've merged the latest master and updated HelloLocalActivityTest.

// withoutAnnotations() is required to stop Mockito from copying
// method-level annotations from the GreetingActivities interface
GreetingActivities activities =
mock(GreetingActivities.class, withSettings().withoutAnnotations());
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason that you don't want Mockito to preserve the annotations?
Why if you do preserve them (testMockedActivityWithoutSettings) you expect the exception?

Just asking because if you have an Activity method with let's say

@ActivityMethod(name = "sayHello")
String composeGreeting(String greeting, String name);

The activity type is different if you remove the annotation, and you probably would want to test with the
actually registered type from the annotation name param? Same really with the @ActivityInterface annotation.

Just wondering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The annotation on the interface class GreetingActivities should not be affected. The withoutAnnotations() setting removes annotations that Mockito copies from the interface class to the dynamically generated mock. Without it, the worker.registerActivitiesImplementations(activities) call fails, as it explicitly checks that the activity implementation class should not have @ActivityMethod annotations.

Someone has reported that behavior as a temporalio/sdk-java#332 issue for the Java SDK.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 thanks for the explanation

@tsurdilo
Copy link
Contributor

@vitarb please review as well when you can. thanks!

@vitarb vitarb merged commit 60985cf into temporalio:master Jun 2, 2021
@GreyTeardrop GreyTeardrop deleted the mockito-3 branch June 2, 2021 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants