{"action":"created","issue":{"url":"https://api.github.com/repos/mockito/mockito/issues/826","repository_url":"https://api.github.com/repos/mockito/mockito","labels_url":"https://api.github.com/repos/mockito/mockito/issues/826/labels{/name}","comments_url":"https://api.github.com/repos/mockito/mockito/issues/826/comments","events_url":"https://api.github.com/repos/mockito/mockito/issues/826/events","html_url":"https://github.com/mockito/mockito/pull/826","id":195810431,"number":826,"title":"Introduce validable answers for early validation of stubbing","user":{"login":"bric3","id":803621,"avatar_url":"https://avatars.githubusercontent.com/u/803621?v=3","gravatar_id":"","url":"https://api.github.com/users/bric3","html_url":"https://github.com/bric3","followers_url":"https://api.github.com/users/bric3/followers","following_url":"https://api.github.com/users/bric3/following{/other_user}","gists_url":"https://api.github.com/users/bric3/gists{/gist_id}","starred_url":"https://api.github.com/users/bric3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bric3/subscriptions","organizations_url":"https://api.github.com/users/bric3/orgs","repos_url":"https://api.github.com/users/bric3/repos","events_url":"https://api.github.com/users/bric3/events{/privacy}","received_events_url":"https://api.github.com/users/bric3/received_events","type":"User","site_admin":false},"labels":[{"id":16375485,"url":"https://api.github.com/repos/mockito/mockito/labels/enhancement","name":"enhancement","color":"207de5","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-12-15T13:51:47Z","updated_at":"2016-12-30T16:47:03Z","closed_at":"2016-12-19T13:35:03Z","pull_request":{"url":"https://api.github.com/repos/mockito/mockito/pulls/826","html_url":"https://github.com/mockito/mockito/pull/826","diff_url":"https://github.com/mockito/mockito/pull/826.diff","patch_url":"https://github.com/mockito/mockito/pull/826.patch"},"body":"## Overview\r\n\r\nCustom Answers are now more robust - users can add add validation logic to the Answer implementation. It can validate the return type early, during stubbing in test, rather than fail late, during execution of code under test. Mockito team uses this API behind the hood for all custom implementations of Answer interface. Now advanced users can leverage this new API, too!\r\n\r\n```java\r\nclass MyCustomAnswer implements Answer, ValidableAnswer { // <-- note extra \"ValidableAnswer\" interface\r\n  public Object answer(InvocationOnMock invocation) {\r\n    // answer implementation\r\n  }\r\n\r\n  public void validateFor(InvocationOnMock invocation) {\r\n    // throw MockitoException if answer cannot be applied to given invocation\r\n  }\r\n}\r\n\r\n``` \r\n\r\n## Implementation\r\n\r\nWhile trying to fix #820 / #821, I noticed that `AnswersValidator` knew too much about other answers. To fix the design issue I propose the following design :\r\n\r\n* Introduce `ValidableAnswer` in public API which is a single method interface that doesn't extends `Answer`.\r\n* Each answer that wants to be validated hence implement this interface\r\n\r\nBenefit, reduced visibility of some methods in these answers. Each new answer that want to be validated can just by implementing the new contract.\r\n\r\nValidating returned value of a mock's default answer had to be handled differently."},"comment":{"url":"https://api.github.com/repos/mockito/mockito/issues/comments/269793334","html_url":"https://github.com/mockito/mockito/pull/826#issuecomment-269793334","issue_url":"https://api.github.com/repos/mockito/mockito/issues/826","id":269793334,"user":{"login":"szczepiq","id":24743,"avatar_url":"https://avatars.githubusercontent.com/u/24743?v=3","gravatar_id":"","url":"https://api.github.com/users/szczepiq","html_url":"https://github.com/szczepiq","followers_url":"https://api.github.com/users/szczepiq/followers","following_url":"https://api.github.com/users/szczepiq/following{/other_user}","gists_url":"https://api.github.com/users/szczepiq/gists{/gist_id}","starred_url":"https://api.github.com/users/szczepiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szczepiq/subscriptions","organizations_url":"https://api.github.com/users/szczepiq/orgs","repos_url":"https://api.github.com/users/szczepiq/repos","events_url":"https://api.github.com/users/szczepiq/events{/privacy}","received_events_url":"https://api.github.com/users/szczepiq/received_events","type":"User","site_admin":false},"created_at":"2016-12-30T16:47:03Z","updated_at":"2016-12-30T16:47:03Z","body":">@szczepiq A press release ?\r\n\r\nBy \"press release\" I mean a paragraph that describes the benefits for the users, at a high level."}}
{"actor":{"display_login":"szczepiq"}}