{"action":"created","issue":{"url":"https://api.github.com/repos/mockito/mockito/issues/1348","repository_url":"https://api.github.com/repos/mockito/mockito","labels_url":"https://api.github.com/repos/mockito/mockito/issues/1348/labels{/name}","comments_url":"https://api.github.com/repos/mockito/mockito/issues/1348/comments","events_url":"https://api.github.com/repos/mockito/mockito/issues/1348/events","html_url":"https://github.com/mockito/mockito/issues/1348","id":308385862,"number":1348,"title":"Support @Mock injection in JUnit 5 method parameters","user":{"login":"smoyer64","id":328333,"avatar_url":"https://avatars0.githubusercontent.com/u/328333?v=4","gravatar_id":"","url":"https://api.github.com/users/smoyer64","html_url":"https://github.com/smoyer64","followers_url":"https://api.github.com/users/smoyer64/followers","following_url":"https://api.github.com/users/smoyer64/following{/other_user}","gists_url":"https://api.github.com/users/smoyer64/gists{/gist_id}","starred_url":"https://api.github.com/users/smoyer64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smoyer64/subscriptions","organizations_url":"https://api.github.com/users/smoyer64/orgs","repos_url":"https://api.github.com/users/smoyer64/repos","events_url":"https://api.github.com/users/smoyer64/events{/privacy}","received_events_url":"https://api.github.com/users/smoyer64/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-03-25T21:08:04Z","updated_at":"2018-03-25T22:28:04Z","closed_at":null,"author_association":"NONE","body":"JUnit 5 has the ability to \"inject\" parameters into test methods via an extensible ``ParameterResolver`` interface.  The JUnit 5 users guide provides an example that shows how such a ``ParameterResolver`` can supply mock objects as test parameters as follows (shamelessly copied from https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection):\r\n\r\n```\r\n@ExtendWith(MockitoExtension.class)\r\nclass MyMockitoTest {\r\n\r\n    @BeforeEach\r\n    void init(@Mock Person person) {\r\n        when(person.getName()).thenReturn(\"Dilbert\");\r\n    }\r\n\r\n    @Test\r\n    void simpleTestWithInjectedMock(@Mock Person person) {\r\n        assertEquals(\"Dilbert\", person.getName());\r\n    }\r\n\r\n}\r\n```\r\n\r\nThe prototype ``MockitoExtension`` provided in the JUnit 5 samples project shows a simple implementation of the required ``supportsParameter()`` and ``resolveParameter()`` methods. (See: https://github.com/junit-team/junit5-samples/blob/r5.1.0/junit5-mockito-extension/src/main/java/com/example/mockito/MockitoExtension.java)\r\n\r\n[ ]   Add the ability to inject mock objects into test method parameters to the official ``MockitoExtension``.  References #445"},"comment":{"url":"https://api.github.com/repos/mockito/mockito/issues/comments/376008862","html_url":"https://github.com/mockito/mockito/issues/1348#issuecomment-376008862","issue_url":"https://api.github.com/repos/mockito/mockito/issues/1348","id":376008862,"user":{"login":"smoyer64","id":328333,"avatar_url":"https://avatars0.githubusercontent.com/u/328333?v=4","gravatar_id":"","url":"https://api.github.com/users/smoyer64","html_url":"https://github.com/smoyer64","followers_url":"https://api.github.com/users/smoyer64/followers","following_url":"https://api.github.com/users/smoyer64/following{/other_user}","gists_url":"https://api.github.com/users/smoyer64/gists{/gist_id}","starred_url":"https://api.github.com/users/smoyer64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smoyer64/subscriptions","organizations_url":"https://api.github.com/users/smoyer64/orgs","repos_url":"https://api.github.com/users/smoyer64/repos","events_url":"https://api.github.com/users/smoyer64/events{/privacy}","received_events_url":"https://api.github.com/users/smoyer64/received_events","type":"User","site_admin":false},"created_at":"2018-03-25T22:28:04Z","updated_at":"2018-03-25T22:28:04Z","author_association":"NONE","body":"I just edited the description of this issue to include a link to the sample ``MockitoExtension`` (I had intended to provide that reference originally).  I don't know if I'd refer to the the methods sharing the parameter instance as \"magic\" but without looking at the code it certainly isn't clear that the parameters are the shared if the types and names match.  I definitely think that there are use-cases for this technique and the use of ``ExtensionContext.Store`` is a great way to provide references to objects from different methods.  My main concern is that when there is a name collision and the types match, you might end up with behavior that's really hard to understand (without knowing how the underlying extension works).\r\n\r\nI'm not sure I'm a fan of the syntax you described above as it seems more redundant than ``@Mock MyWeirdThing myWeirdMock`` - I'm guessing I'm misunderstanding your intention (I get the erasure part)."}}
{"actor":{"display_login":"smoyer64"}}