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

Add new static Answers RETURNS_DEFAULT_VALUE #2104

Open
3 of 5 tasks
rymsha opened this issue Nov 20, 2020 · 2 comments
Open
3 of 5 tasks

Add new static Answers RETURNS_DEFAULT_VALUE #2104

rymsha opened this issue Nov 20, 2020 · 2 comments

Comments

@rymsha
Copy link

rymsha commented Nov 20, 2020

  • The mockito message in the stacktrace have useful information, but it didn't help
  • The problematic code (if that's possible) is copied here;
    Note that some configuration are impossible to mock via Mockito
  • Provide versions (mockito / jdk / os / any other relevant information)
  • Provide a Short, Self Contained, Correct (Compilable), Example of the issue
    (same as any question on stackoverflow.com)
  • Read the contributing guide

Mockito v3.6.0

Add new static Answer to Answers: Answers.RETURNS_DEFAULT_VALUE that calls method's getDefaultValue
This would be useful for annotation mocking, especially with MockitoExtension @Mock(answer = Answers.RETURNS_DEFAULT_VALUE)

Background:
In OSGi Annotations are used as "Component Property Type":

public @interface MyConfig { String timeout() default "1s";}

...

@Activate
public void activate(MyConfig config) {timeout = config.timeout();}

verifying the method activate and configuration property default values is problematic.

Current workaround:
mock(MyConfig.class, invocation -> invocation.getMethod().getDefaultValue());

@TimvdLippe
Copy link
Contributor

I think this is a duplicate of #1900

@rymsha
Copy link
Author

rymsha commented Dec 1, 2020

Yeah, trying to solve the same problem with a different approach, basically.

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

No branches or pull requests

2 participants