{"action":"created","comment":{"url":"https://api.github.com/repos/mockito/mockito/pulls/comments/94290358","pull_request_review_id":14818756,"id":94290358,"diff_hunk":"@@ -75,6 +75,7 @@ dependencies {\n \n     provided \"junit:junit:4.12\", \"org.hamcrest:hamcrest-core:1.3\"\n     compile \"org.objenesis:objenesis:2.4\"\n+    compile 'net.jodah:typetools:0.4.8'","path":"build.gradle","position":4,"original_position":4,"commit_id":"b77a240127a7f42699a3b681ff3a0d13f49d8d4d","original_commit_id":"b77a240127a7f42699a3b681ff3a0d13f49d8d4d","user":{"login":"szpak","id":148013,"avatar_url":"https://avatars.githubusercontent.com/u/148013?v=3","gravatar_id":"","url":"https://api.github.com/users/szpak","html_url":"https://github.com/szpak","followers_url":"https://api.github.com/users/szpak/followers","following_url":"https://api.github.com/users/szpak/following{/other_user}","gists_url":"https://api.github.com/users/szpak/gists{/gist_id}","starred_url":"https://api.github.com/users/szpak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szpak/subscriptions","organizations_url":"https://api.github.com/users/szpak/orgs","repos_url":"https://api.github.com/users/szpak/repos","events_url":"https://api.github.com/users/szpak/events{/privacy}","received_events_url":"https://api.github.com/users/szpak/received_events","type":"User","site_admin":false},"body":"Looking at the [code](https://github.com/jhalterman/typetools/blob/master/src/main/java/net/jodah/typetools/TypeResolver.java) there seem to be some corner cases in resolving return types.\r\n\r\nIn this code it is needed to determine a return type of lambda implementing `Consumer` interface. @raphw Maybe you have some code in ByteBuddy which could be used to do that?","created_at":"2017-01-01T23:31:52Z","updated_at":"2017-01-01T23:31:52Z","html_url":"https://github.com/mockito/mockito/pull/859#discussion_r94290358","pull_request_url":"https://api.github.com/repos/mockito/mockito/pulls/859","_links":{"self":{"href":"https://api.github.com/repos/mockito/mockito/pulls/comments/94290358"},"html":{"href":"https://github.com/mockito/mockito/pull/859#discussion_r94290358"},"pull_request":{"href":"https://api.github.com/repos/mockito/mockito/pulls/859"}}},"pull_request":{"url":"https://api.github.com/repos/mockito/mockito/pulls/859","id":99790623,"html_url":"https://github.com/mockito/mockito/pull/859","diff_url":"https://github.com/mockito/mockito/pull/859.diff","patch_url":"https://github.com/mockito/mockito/pull/859.patch","issue_url":"https://api.github.com/repos/mockito/mockito/issues/859","number":859,"state":"open","locked":false,"title":"[#297] Add AssertionMatcher and LambdaMatcher","user":{"login":"szpak","id":148013,"avatar_url":"https://avatars.githubusercontent.com/u/148013?v=3","gravatar_id":"","url":"https://api.github.com/users/szpak","html_url":"https://github.com/szpak","followers_url":"https://api.github.com/users/szpak/followers","following_url":"https://api.github.com/users/szpak/following{/other_user}","gists_url":"https://api.github.com/users/szpak/gists{/gist_id}","starred_url":"https://api.github.com/users/szpak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szpak/subscriptions","organizations_url":"https://api.github.com/users/szpak/orgs","repos_url":"https://api.github.com/users/szpak/repos","events_url":"https://api.github.com/users/szpak/events{/privacy}","received_events_url":"https://api.github.com/users/szpak/received_events","type":"User","site_admin":false},"body":"The matchers leverages Java 8 to provide inlined ArgumentCaptor with a lambda expression and inlined argument matcher with a predicate lambda expression. More information below and in JavaDoc.\r\n\r\n### Lambda matcher\r\n\r\nAllows to define matcher logic within a lambda expression. Useful when working with complex classes pass as an argument.\r\n\r\n```\r\n@Immutable\r\nclass ShipSearchCriteria {\r\n    int minimumRange;\r\n    int numberOfPhasers;\r\n}\r\n```\r\n\r\n```\r\n@Test\r\npublic void shouldAllowToUseLambdaInStubbing() {\r\n    //given\r\n    given(ts.findNumberOfShipsInRangeByCriteria(\r\n        argLambda(c -> c.getMinimumRange() > 1000))).willReturn(4);\r\n    //expect\r\n    assertThat(ts.findNumberOfShipsInRangeByCriteria(new ShipSearchCriteria(1500, 2)))\r\n        .isEqualTo(4);\r\n    //expect\r\n    assertThat(ts.findNumberOfShipsInRangeByCriteria(new ShipSearchCriteria(700, 2)))\r\n        .isEqualTo(0);\r\n}\r\n```\r\n\r\nIn comparison the same logic implemented with a custom Answer in Java 7:\r\n\r\n```\r\n@Test\r\npublic void stubbingWithCustomAnswerShouldBeLonger() {  //old way\r\n    //given\r\n    given(ts.findNumberOfShipsInRangeByCriteria(any())).willAnswer(new Answer<Integer>() {\r\n        @Override\r\n        public Integer answer(InvocationOnMock invocation) throws Throwable {\r\n            Object[] args = invocation.getArguments();\r\n            ShipSearchCriteria criteria = (ShipSearchCriteria) args[0];\r\n            if (criteria.getMinimumRange() > 1000) {\r\n                return 4;\r\n            } else {\r\n                return 0;\r\n            }\r\n        }\r\n    });\r\n    //expect\r\n    assertThat(ts.findNumberOfShipsInRangeByCriteria(new ShipSearchCriteria(1500, 2)))\r\n        .isEqualTo(4);\r\n    //expect\r\n    assertThat(ts.findNumberOfShipsInRangeByCriteria(new ShipSearchCriteria(700, 2)))\r\n        .isEqualTo(0);\r\n}\r\n```\r\n\r\nEven Java 8 and less readable constructions don't help too much:\r\n\r\n```\r\n@Test\r\npublic void stubbingWithCustomAnswerShouldBeLongerEvenAsLambda() {  //old way\r\n    //given\r\n    given(ts.findNumberOfShipsInRangeByCriteria(any())).willAnswer(invocation -> {\r\n        ShipSearchCriteria criteria = (ShipSearchCriteria) invocation.getArguments()[0];\r\n        return criteria.getMinimumRange() > 1000 ? 4 : 0;\r\n    });\r\n    //expect\r\n    assertThat(ts.findNumberOfShipsInRangeByCriteria(new ShipSearchCriteria(1500, 2)))\r\n        .isEqualTo(4);\r\n    //expect\r\n    assertThat(ts.findNumberOfShipsInRangeByCriteria(new ShipSearchCriteria(700, 2)))\r\n        .isEqualTo(0);\r\n}\r\n```\r\n\r\n### Argument Captor - Java 8 edition\r\n\r\nAllows to use ArgumentCaptor in one line:\r\n\r\n```\r\n@Test\r\npublic void shouldAllowToUseAssertionInLambda() {\r\n    //when\r\n    ts.findNumberOfShipsInRangeByCriteria(searchCriteria);\r\n    //then\r\n    verify(ts).findNumberOfShipsInRangeByCriteria(\r\n        assertArg(sc -> assertThat(sc.getMinimumRange()).isLessThan(2000)));\r\n}\r\n```\r\n\r\nIn comparison to 3 lines in the classic way:\r\n\r\n```\r\n@Test\r\npublic void shouldAllowToUseArgumentCaptorInClassicWay() {  //old way\r\n    //when\r\n    ts.findNumberOfShipsInRangeByCriteria(searchCriteria);\r\n    //then\r\n    ArgumentCaptor<ShipSearchCriteria> captor = \r\n        ArgumentCaptor.forClass(ShipSearchCriteria.class);\r\n    verify(ts).findNumberOfShipsInRangeByCriteria(captor.capture());\r\n    assertThat(captor.getValue().getMinimumRange()).isLessThan(2000);\r\n}\r\n```\r\n\r\nBackported from https://github.com/szpak/mockito-java8/\r\nRelated to #297.\r\n\r\nBtw, I'm not sure if `Primitives` is the best name for a class with `defaultValue()` working also with non primitives classes. I probably liked `HandyReturnValues` more.","created_at":"2016-12-30T23:36:19Z","updated_at":"2017-01-01T23:31:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"10416c474cc705e101c6b63ffe544cc904d0fedf","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/mockito/mockito/milestones/2","html_url":"https://github.com/mockito/mockito/milestone/2","labels_url":"https://api.github.com/repos/mockito/mockito/milestones/2/labels","id":1348552,"number":2,"title":"3.0","description":null,"creator":{"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},"open_issues":8,"closed_issues":1,"state":"open","created_at":"2015-10-10T18:17:08Z","updated_at":"2016-12-30T23:36:19Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/mockito/mockito/pulls/859/commits","review_comments_url":"https://api.github.com/repos/mockito/mockito/pulls/859/comments","review_comment_url":"https://api.github.com/repos/mockito/mockito/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mockito/mockito/issues/859/comments","statuses_url":"https://api.github.com/repos/mockito/mockito/statuses/b77a240127a7f42699a3b681ff3a0d13f49d8d4d","head":{"label":"mockito:feature/297-java8Marchers","ref":"feature/297-java8Marchers","sha":"b77a240127a7f42699a3b681ff3a0d13f49d8d4d","user":{"login":"mockito","id":2054056,"avatar_url":"https://avatars.githubusercontent.com/u/2054056?v=3","gravatar_id":"","url":"https://api.github.com/users/mockito","html_url":"https://github.com/mockito","followers_url":"https://api.github.com/users/mockito/followers","following_url":"https://api.github.com/users/mockito/following{/other_user}","gists_url":"https://api.github.com/users/mockito/gists{/gist_id}","starred_url":"https://api.github.com/users/mockito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockito/subscriptions","organizations_url":"https://api.github.com/users/mockito/orgs","repos_url":"https://api.github.com/users/mockito/repos","events_url":"https://api.github.com/users/mockito/events{/privacy}","received_events_url":"https://api.github.com/users/mockito/received_events","type":"Organization","site_admin":false},"repo":{"id":6207167,"name":"mockito","full_name":"mockito/mockito","owner":{"login":"mockito","id":2054056,"avatar_url":"https://avatars.githubusercontent.com/u/2054056?v=3","gravatar_id":"","url":"https://api.github.com/users/mockito","html_url":"https://github.com/mockito","followers_url":"https://api.github.com/users/mockito/followers","following_url":"https://api.github.com/users/mockito/following{/other_user}","gists_url":"https://api.github.com/users/mockito/gists{/gist_id}","starred_url":"https://api.github.com/users/mockito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockito/subscriptions","organizations_url":"https://api.github.com/users/mockito/orgs","repos_url":"https://api.github.com/users/mockito/repos","events_url":"https://api.github.com/users/mockito/events{/privacy}","received_events_url":"https://api.github.com/users/mockito/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mockito/mockito","description":"Most popular Mocking framework for unit tests written in Java","fork":false,"url":"https://api.github.com/repos/mockito/mockito","forks_url":"https://api.github.com/repos/mockito/mockito/forks","keys_url":"https://api.github.com/repos/mockito/mockito/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mockito/mockito/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mockito/mockito/teams","hooks_url":"https://api.github.com/repos/mockito/mockito/hooks","issue_events_url":"https://api.github.com/repos/mockito/mockito/issues/events{/number}","events_url":"https://api.github.com/repos/mockito/mockito/events","assignees_url":"https://api.github.com/repos/mockito/mockito/assignees{/user}","branches_url":"https://api.github.com/repos/mockito/mockito/branches{/branch}","tags_url":"https://api.github.com/repos/mockito/mockito/tags","blobs_url":"https://api.github.com/repos/mockito/mockito/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mockito/mockito/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mockito/mockito/git/refs{/sha}","trees_url":"https://api.github.com/repos/mockito/mockito/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mockito/mockito/statuses/{sha}","languages_url":"https://api.github.com/repos/mockito/mockito/languages","stargazers_url":"https://api.github.com/repos/mockito/mockito/stargazers","contributors_url":"https://api.github.com/repos/mockito/mockito/contributors","subscribers_url":"https://api.github.com/repos/mockito/mockito/subscribers","subscription_url":"https://api.github.com/repos/mockito/mockito/subscription","commits_url":"https://api.github.com/repos/mockito/mockito/commits{/sha}","git_commits_url":"https://api.github.com/repos/mockito/mockito/git/commits{/sha}","comments_url":"https://api.github.com/repos/mockito/mockito/comments{/number}","issue_comment_url":"https://api.github.com/repos/mockito/mockito/issues/comments{/number}","contents_url":"https://api.github.com/repos/mockito/mockito/contents/{+path}","compare_url":"https://api.github.com/repos/mockito/mockito/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mockito/mockito/merges","archive_url":"https://api.github.com/repos/mockito/mockito/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mockito/mockito/downloads","issues_url":"https://api.github.com/repos/mockito/mockito/issues{/number}","pulls_url":"https://api.github.com/repos/mockito/mockito/pulls{/number}","milestones_url":"https://api.github.com/repos/mockito/mockito/milestones{/number}","notifications_url":"https://api.github.com/repos/mockito/mockito/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mockito/mockito/labels{/name}","releases_url":"https://api.github.com/repos/mockito/mockito/releases{/id}","deployments_url":"https://api.github.com/repos/mockito/mockito/deployments","created_at":"2012-10-13T20:27:12Z","updated_at":"2017-01-01T18:26:30Z","pushed_at":"2017-01-01T23:06:02Z","git_url":"git://github.com/mockito/mockito.git","ssh_url":"git@github.com:mockito/mockito.git","clone_url":"https://github.com/mockito/mockito.git","svn_url":"https://github.com/mockito/mockito","homepage":"http://mockito.org","size":42553,"stargazers_count":3809,"watchers_count":3809,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":755,"mirror_url":null,"open_issues_count":99,"forks":755,"open_issues":99,"watchers":3809,"default_branch":"release/2.x"}},"base":{"label":"mockito:master","ref":"master","sha":"b5b087e1ca7868e0c0e187ae955526884b8ff136","user":{"login":"mockito","id":2054056,"avatar_url":"https://avatars.githubusercontent.com/u/2054056?v=3","gravatar_id":"","url":"https://api.github.com/users/mockito","html_url":"https://github.com/mockito","followers_url":"https://api.github.com/users/mockito/followers","following_url":"https://api.github.com/users/mockito/following{/other_user}","gists_url":"https://api.github.com/users/mockito/gists{/gist_id}","starred_url":"https://api.github.com/users/mockito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockito/subscriptions","organizations_url":"https://api.github.com/users/mockito/orgs","repos_url":"https://api.github.com/users/mockito/repos","events_url":"https://api.github.com/users/mockito/events{/privacy}","received_events_url":"https://api.github.com/users/mockito/received_events","type":"Organization","site_admin":false},"repo":{"id":6207167,"name":"mockito","full_name":"mockito/mockito","owner":{"login":"mockito","id":2054056,"avatar_url":"https://avatars.githubusercontent.com/u/2054056?v=3","gravatar_id":"","url":"https://api.github.com/users/mockito","html_url":"https://github.com/mockito","followers_url":"https://api.github.com/users/mockito/followers","following_url":"https://api.github.com/users/mockito/following{/other_user}","gists_url":"https://api.github.com/users/mockito/gists{/gist_id}","starred_url":"https://api.github.com/users/mockito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockito/subscriptions","organizations_url":"https://api.github.com/users/mockito/orgs","repos_url":"https://api.github.com/users/mockito/repos","events_url":"https://api.github.com/users/mockito/events{/privacy}","received_events_url":"https://api.github.com/users/mockito/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mockito/mockito","description":"Most popular Mocking framework for unit tests written in Java","fork":false,"url":"https://api.github.com/repos/mockito/mockito","forks_url":"https://api.github.com/repos/mockito/mockito/forks","keys_url":"https://api.github.com/repos/mockito/mockito/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mockito/mockito/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mockito/mockito/teams","hooks_url":"https://api.github.com/repos/mockito/mockito/hooks","issue_events_url":"https://api.github.com/repos/mockito/mockito/issues/events{/number}","events_url":"https://api.github.com/repos/mockito/mockito/events","assignees_url":"https://api.github.com/repos/mockito/mockito/assignees{/user}","branches_url":"https://api.github.com/repos/mockito/mockito/branches{/branch}","tags_url":"https://api.github.com/repos/mockito/mockito/tags","blobs_url":"https://api.github.com/repos/mockito/mockito/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mockito/mockito/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mockito/mockito/git/refs{/sha}","trees_url":"https://api.github.com/repos/mockito/mockito/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mockito/mockito/statuses/{sha}","languages_url":"https://api.github.com/repos/mockito/mockito/languages","stargazers_url":"https://api.github.com/repos/mockito/mockito/stargazers","contributors_url":"https://api.github.com/repos/mockito/mockito/contributors","subscribers_url":"https://api.github.com/repos/mockito/mockito/subscribers","subscription_url":"https://api.github.com/repos/mockito/mockito/subscription","commits_url":"https://api.github.com/repos/mockito/mockito/commits{/sha}","git_commits_url":"https://api.github.com/repos/mockito/mockito/git/commits{/sha}","comments_url":"https://api.github.com/repos/mockito/mockito/comments{/number}","issue_comment_url":"https://api.github.com/repos/mockito/mockito/issues/comments{/number}","contents_url":"https://api.github.com/repos/mockito/mockito/contents/{+path}","compare_url":"https://api.github.com/repos/mockito/mockito/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mockito/mockito/merges","archive_url":"https://api.github.com/repos/mockito/mockito/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mockito/mockito/downloads","issues_url":"https://api.github.com/repos/mockito/mockito/issues{/number}","pulls_url":"https://api.github.com/repos/mockito/mockito/pulls{/number}","milestones_url":"https://api.github.com/repos/mockito/mockito/milestones{/number}","notifications_url":"https://api.github.com/repos/mockito/mockito/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mockito/mockito/labels{/name}","releases_url":"https://api.github.com/repos/mockito/mockito/releases{/id}","deployments_url":"https://api.github.com/repos/mockito/mockito/deployments","created_at":"2012-10-13T20:27:12Z","updated_at":"2017-01-01T18:26:30Z","pushed_at":"2017-01-01T23:06:02Z","git_url":"git://github.com/mockito/mockito.git","ssh_url":"git@github.com:mockito/mockito.git","clone_url":"https://github.com/mockito/mockito.git","svn_url":"https://github.com/mockito/mockito","homepage":"http://mockito.org","size":42553,"stargazers_count":3809,"watchers_count":3809,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":755,"mirror_url":null,"open_issues_count":99,"forks":755,"open_issues":99,"watchers":3809,"default_branch":"release/2.x"}},"_links":{"self":{"href":"https://api.github.com/repos/mockito/mockito/pulls/859"},"html":{"href":"https://github.com/mockito/mockito/pull/859"},"issue":{"href":"https://api.github.com/repos/mockito/mockito/issues/859"},"comments":{"href":"https://api.github.com/repos/mockito/mockito/issues/859/comments"},"review_comments":{"href":"https://api.github.com/repos/mockito/mockito/pulls/859/comments"},"review_comment":{"href":"https://api.github.com/repos/mockito/mockito/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mockito/mockito/pulls/859/commits"},"statuses":{"href":"https://api.github.com/repos/mockito/mockito/statuses/b77a240127a7f42699a3b681ff3a0d13f49d8d4d"}}}}
{"actor":{"display_login":"szpak"}}