{"action":"created","issue":{"url":"https://api.github.com/repos/junit-team/junit4/issues/1433","repository_url":"https://api.github.com/repos/junit-team/junit4","labels_url":"https://api.github.com/repos/junit-team/junit4/issues/1433/labels{/name}","comments_url":"https://api.github.com/repos/junit-team/junit4/issues/1433/comments","events_url":"https://api.github.com/repos/junit-team/junit4/issues/1433/events","html_url":"https://github.com/junit-team/junit4/issues/1433","id":215548406,"number":1433,"title":"Theories Runner runs @Theory methods before Mockito's JUnitRule initializes mocks","user":{"login":"magneticflux-","id":9124288,"avatar_url":"https://avatars2.githubusercontent.com/u/9124288?v=3","gravatar_id":"","url":"https://api.github.com/users/magneticflux-","html_url":"https://github.com/magneticflux-","followers_url":"https://api.github.com/users/magneticflux-/followers","following_url":"https://api.github.com/users/magneticflux-/following{/other_user}","gists_url":"https://api.github.com/users/magneticflux-/gists{/gist_id}","starred_url":"https://api.github.com/users/magneticflux-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magneticflux-/subscriptions","organizations_url":"https://api.github.com/users/magneticflux-/orgs","repos_url":"https://api.github.com/users/magneticflux-/repos","events_url":"https://api.github.com/users/magneticflux-/events{/privacy}","received_events_url":"https://api.github.com/users/magneticflux-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-03-20T20:39:50Z","updated_at":"2017-03-20T22:49:52Z","closed_at":null,"body":"Mockito's `JUnitRule` rule runs the `MockitoAnnotations.initMocks(testClass)` method after all `@DataPoint` annotated fields have been acquired. This causes all `@DataPoint` annotated fields to appear to be `null` when the tests are run. This is due to the nature of `PotentialAssignment`, which maintains a reference to the field's _value_, but not the field itself.\r\n\r\nIs there any way to allow Mockito's automatic mocking rule assign the values to the fields so that the Theories runner can see them? My naïve solution would be to instead reference each field (or index of List/Array) in an `Assignment` or `PotentialAssignment`, but I'm sure that would introduce all sorts of other bugs."},"comment":{"url":"https://api.github.com/repos/junit-team/junit4/issues/comments/287922526","html_url":"https://github.com/junit-team/junit4/issues/1433#issuecomment-287922526","issue_url":"https://api.github.com/repos/junit-team/junit4/issues/1433","id":287922526,"user":{"login":"magneticflux-","id":9124288,"avatar_url":"https://avatars2.githubusercontent.com/u/9124288?v=3","gravatar_id":"","url":"https://api.github.com/users/magneticflux-","html_url":"https://github.com/magneticflux-","followers_url":"https://api.github.com/users/magneticflux-/followers","following_url":"https://api.github.com/users/magneticflux-/following{/other_user}","gists_url":"https://api.github.com/users/magneticflux-/gists{/gist_id}","starred_url":"https://api.github.com/users/magneticflux-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magneticflux-/subscriptions","organizations_url":"https://api.github.com/users/magneticflux-/orgs","repos_url":"https://api.github.com/users/magneticflux-/repos","events_url":"https://api.github.com/users/magneticflux-/events{/privacy}","received_events_url":"https://api.github.com/users/magneticflux-/received_events","type":"User","site_admin":false},"created_at":"2017-03-20T22:49:52Z","updated_at":"2017-03-20T22:49:52Z","body":"@kcooney The `MockitoAnnotations.initMocks(testClass)` gets an instance of the test class through the `apply` method in the `MethodRule` class. It then uses the `Class.getDeclaredFields()` method to access each field, before setting the field using the provided test class instance. If the field is null, as per Oracle Javadocs for `Field.setField`, the instance is ignored.\r\n\r\nAs for my use case, I have fields declared `public static` that are annotated with `@Mock` and `@DataPoint`. Even if I add a rule as described here:\r\n```\r\n@Rule\r\npublic final MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);\r\n```\r\nThe fields annotated with `@Mock` are null when the Theories runner looks for them. They _are_ non-null as the test method runs, but since I only access the parameters passed to the test method, I only receive null objects."}}
{"actor":{"display_login":"magneticflux-"}}