{"action":"created","comment":{"url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/comments/38202559","id":38202559,"diff_hunk":"@@ -0,0 +1,86 @@\n+package org.whaka.mock;\n+\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.Collection;\n+import java.util.Collections;\n+import java.util.HashSet;\n+import java.util.List;\n+import java.util.Set;\n+import java.util.function.BiConsumer;\n+import java.util.function.Predicate;\n+import java.util.stream.Collectors;\n+import org.mockito.Matchers;\n+import org.mockito.MockSettings;\n+import org.mockito.Mockito;\n+import org.mockito.invocation.DescribedInvocation;\n+\n+/**\n+ * Collect arguments from the called method (may be used with listeners).\n+ *\n+ * @param <Target>  the target class\n+ * @param <Event>  the event type\n+ */\n+public class EventCollector<Target, Event> {\n+\n+\tprivate final List<Event> events = Collections.synchronizedList(new ArrayList<>());\n+\tprivate final Target target;\n+\n+\t@SafeVarargs\n+\t@SuppressWarnings(\"unchecked\")\n+\tpublic EventCollector(Class<Target> targetClass, BiConsumer<Target, Event> targetMethod, Predicate<Event>... filters) {\n+\t\tthis(targetClass, targetMethod, new HashSet<>(Arrays.asList(filters)));\n+\t}\n+\n+\t@SuppressWarnings(\"unchecked\")\n+\tpublic EventCollector(Class<Target> targetClass, BiConsumer<Target, Event> targetMethod, Collection<Predicate<Event>> filters) {\n+\n+\t\tList<DescribedInvocation> invokes = new ArrayList<>();\n+\t\tMockSettings settings = Mockito.withSettings()\n+\t\t\t\t.invocationListeners(report -> invokes.add(report.getInvocation()));\n+\n+\t\tthis.target = Mockito.mock(targetClass, settings);\n+\n+\t\tSet<EventHandler<Event>> eventHandlers = filters.stream()\n+\t\t\t\t.filter(p -> p instanceof EventHandler)\n+\t\t\t\t.map(p -> (EventHandler<Event>) p)\n+\t\t\t\t.collect(Collectors.toSet());\n+\n+\t\ttargetMethod.accept(Mockito.doAnswer(invoke -> {\n+\t\t\tEvent event = (Event) invoke.getArguments()[0];\n+\t\t\tboolean filterFail = filters.stream().map(p -> p.test(event)).collect(Collectors.toSet()).contains(false);\n+\t\t\tif(!filterFail) {\n+\t\t\t\tevents.add(event);\n+\t\t\t\teventHandlers.forEach(c -> c.accepted(event));\n+\t\t\t}\n+\n+\t\t\treturn null;\n+\t\t}).when(this.target), Matchers.any());","path":"src/main/java/org/whaka/mock/EventCollector.java","position":58,"original_position":58,"commit_id":"edf7e972a9df5495e42b02a29cced894a8cd0672","original_commit_id":"edf7e972a9df5495e42b02a29cced894a8cd0672","user":{"login":"vantuz-subhuman","id":5585355,"avatar_url":"https://avatars.githubusercontent.com/u/5585355?v=3","gravatar_id":"","url":"https://api.github.com/users/vantuz-subhuman","html_url":"https://github.com/vantuz-subhuman","followers_url":"https://api.github.com/users/vantuz-subhuman/followers","following_url":"https://api.github.com/users/vantuz-subhuman/following{/other_user}","gists_url":"https://api.github.com/users/vantuz-subhuman/gists{/gist_id}","starred_url":"https://api.github.com/users/vantuz-subhuman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vantuz-subhuman/subscriptions","organizations_url":"https://api.github.com/users/vantuz-subhuman/orgs","repos_url":"https://api.github.com/users/vantuz-subhuman/repos","events_url":"https://api.github.com/users/vantuz-subhuman/events{/privacy}","received_events_url":"https://api.github.com/users/vantuz-subhuman/received_events","type":"User","site_admin":false},"body":"All \"answer\" functionality should be wrapped in `synchronize` block, so we would ensure handler's `accepted` would be guaranteed to be called immediately after `test`.\r\n\r\nYou need to introduce some local private lock, like:\r\n```\r\nprivate final Object lock = new Object();\r\n```","created_at":"2015-08-28T14:04:53Z","updated_at":"2015-08-28T14:04:53Z","html_url":"https://github.com/Whaka-project/whakamatautau-util/pull/68#discussion_r38202559","pull_request_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68","_links":{"self":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/comments/38202559"},"html":{"href":"https://github.com/Whaka-project/whakamatautau-util/pull/68#discussion_r38202559"},"pull_request":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68"}}},"pull_request":{"url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68","id":43620304,"html_url":"https://github.com/Whaka-project/whakamatautau-util/pull/68","diff_url":"https://github.com/Whaka-project/whakamatautau-util/pull/68.diff","patch_url":"https://github.com/Whaka-project/whakamatautau-util/pull/68.patch","issue_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/68","number":68,"state":"open","locked":false,"title":"Resolve #60 utils create event collector","user":{"login":"visitorus","id":13798091,"avatar_url":"https://avatars.githubusercontent.com/u/13798091?v=3","gravatar_id":"","url":"https://api.github.com/users/visitorus","html_url":"https://github.com/visitorus","followers_url":"https://api.github.com/users/visitorus/followers","following_url":"https://api.github.com/users/visitorus/following{/other_user}","gists_url":"https://api.github.com/users/visitorus/gists{/gist_id}","starred_url":"https://api.github.com/users/visitorus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/visitorus/subscriptions","organizations_url":"https://api.github.com/users/visitorus/orgs","repos_url":"https://api.github.com/users/visitorus/repos","events_url":"https://api.github.com/users/visitorus/events{/privacy}","received_events_url":"https://api.github.com/users/visitorus/received_events","type":"User","site_admin":false},"body":"```org.whaka.mock.EventCollector``` was created with additional custom Predicate```org.whaka.mock.EventCollector.EventHandler```","created_at":"2015-08-28T11:55:36Z","updated_at":"2015-08-28T14:04:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"66924e3d59af33fce7f5ecc2c06665da72acce39","assignee":{"login":"vantuz-subhuman","id":5585355,"avatar_url":"https://avatars.githubusercontent.com/u/5585355?v=3","gravatar_id":"","url":"https://api.github.com/users/vantuz-subhuman","html_url":"https://github.com/vantuz-subhuman","followers_url":"https://api.github.com/users/vantuz-subhuman/followers","following_url":"https://api.github.com/users/vantuz-subhuman/following{/other_user}","gists_url":"https://api.github.com/users/vantuz-subhuman/gists{/gist_id}","starred_url":"https://api.github.com/users/vantuz-subhuman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vantuz-subhuman/subscriptions","organizations_url":"https://api.github.com/users/vantuz-subhuman/orgs","repos_url":"https://api.github.com/users/vantuz-subhuman/repos","events_url":"https://api.github.com/users/vantuz-subhuman/events{/privacy}","received_events_url":"https://api.github.com/users/vantuz-subhuman/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/milestones/2","html_url":"https://github.com/Whaka-project/whakamatautau-util/milestones/Release:%200.0.8","labels_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/milestones/2/labels","id":1262264,"number":2,"title":"Release: 0.0.8","description":"","creator":{"login":"vantuz-subhuman","id":5585355,"avatar_url":"https://avatars.githubusercontent.com/u/5585355?v=3","gravatar_id":"","url":"https://api.github.com/users/vantuz-subhuman","html_url":"https://github.com/vantuz-subhuman","followers_url":"https://api.github.com/users/vantuz-subhuman/followers","following_url":"https://api.github.com/users/vantuz-subhuman/following{/other_user}","gists_url":"https://api.github.com/users/vantuz-subhuman/gists{/gist_id}","starred_url":"https://api.github.com/users/vantuz-subhuman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vantuz-subhuman/subscriptions","organizations_url":"https://api.github.com/users/vantuz-subhuman/orgs","repos_url":"https://api.github.com/users/vantuz-subhuman/repos","events_url":"https://api.github.com/users/vantuz-subhuman/events{/privacy}","received_events_url":"https://api.github.com/users/vantuz-subhuman/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":36,"state":"open","created_at":"2015-08-19T10:01:56Z","updated_at":"2015-08-28T13:33:36Z","due_on":"2015-08-30T21:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68/commits","review_comments_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68/comments","review_comment_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/68/comments","statuses_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/statuses/edf7e972a9df5495e42b02a29cced894a8cd0672","head":{"label":"Whaka-project:#60-Utils-Create-event-collector","ref":"#60-Utils-Create-event-collector","sha":"edf7e972a9df5495e42b02a29cced894a8cd0672","user":{"login":"Whaka-project","id":13866233,"avatar_url":"https://avatars.githubusercontent.com/u/13866233?v=3","gravatar_id":"","url":"https://api.github.com/users/Whaka-project","html_url":"https://github.com/Whaka-project","followers_url":"https://api.github.com/users/Whaka-project/followers","following_url":"https://api.github.com/users/Whaka-project/following{/other_user}","gists_url":"https://api.github.com/users/Whaka-project/gists{/gist_id}","starred_url":"https://api.github.com/users/Whaka-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Whaka-project/subscriptions","organizations_url":"https://api.github.com/users/Whaka-project/orgs","repos_url":"https://api.github.com/users/Whaka-project/repos","events_url":"https://api.github.com/users/Whaka-project/events{/privacy}","received_events_url":"https://api.github.com/users/Whaka-project/received_events","type":"Organization","site_admin":false},"repo":{"id":40726014,"name":"whakamatautau-util","full_name":"Whaka-project/whakamatautau-util","owner":{"login":"Whaka-project","id":13866233,"avatar_url":"https://avatars.githubusercontent.com/u/13866233?v=3","gravatar_id":"","url":"https://api.github.com/users/Whaka-project","html_url":"https://github.com/Whaka-project","followers_url":"https://api.github.com/users/Whaka-project/followers","following_url":"https://api.github.com/users/Whaka-project/following{/other_user}","gists_url":"https://api.github.com/users/Whaka-project/gists{/gist_id}","starred_url":"https://api.github.com/users/Whaka-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Whaka-project/subscriptions","organizations_url":"https://api.github.com/users/Whaka-project/orgs","repos_url":"https://api.github.com/users/Whaka-project/repos","events_url":"https://api.github.com/users/Whaka-project/events{/privacy}","received_events_url":"https://api.github.com/users/Whaka-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Whaka-project/whakamatautau-util","description":"Set of utils useful for authomation testing and any everyday coding","fork":false,"url":"https://api.github.com/repos/Whaka-project/whakamatautau-util","forks_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/forks","keys_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/teams","hooks_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/hooks","issue_events_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/events{/number}","events_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/events","assignees_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/assignees{/user}","branches_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/branches{/branch}","tags_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/tags","blobs_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/refs{/sha}","trees_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/statuses/{sha}","languages_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/languages","stargazers_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/stargazers","contributors_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/contributors","subscribers_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/subscribers","subscription_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/subscription","commits_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/commits{/sha}","git_commits_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/commits{/sha}","comments_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/comments{/number}","issue_comment_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/comments{/number}","contents_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/contents/{+path}","compare_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/merges","archive_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/downloads","issues_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues{/number}","pulls_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls{/number}","milestones_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/milestones{/number}","notifications_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/labels{/name}","releases_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/releases{/id}","created_at":"2015-08-14T16:52:16Z","updated_at":"2015-08-19T08:42:03Z","pushed_at":"2015-08-28T13:33:37Z","git_url":"git://github.com/Whaka-project/whakamatautau-util.git","ssh_url":"git@github.com:Whaka-project/whakamatautau-util.git","clone_url":"https://github.com/Whaka-project/whakamatautau-util.git","svn_url":"https://github.com/Whaka-project/whakamatautau-util","homepage":null,"size":1097,"stargazers_count":0,"watchers_count":0,"language":"Groovy","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":12,"forks":1,"open_issues":12,"watchers":0,"default_branch":"master"}},"base":{"label":"Whaka-project:master","ref":"master","sha":"8a4cdb9df12c9d13f0d7d415e54abda45b4503cc","user":{"login":"Whaka-project","id":13866233,"avatar_url":"https://avatars.githubusercontent.com/u/13866233?v=3","gravatar_id":"","url":"https://api.github.com/users/Whaka-project","html_url":"https://github.com/Whaka-project","followers_url":"https://api.github.com/users/Whaka-project/followers","following_url":"https://api.github.com/users/Whaka-project/following{/other_user}","gists_url":"https://api.github.com/users/Whaka-project/gists{/gist_id}","starred_url":"https://api.github.com/users/Whaka-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Whaka-project/subscriptions","organizations_url":"https://api.github.com/users/Whaka-project/orgs","repos_url":"https://api.github.com/users/Whaka-project/repos","events_url":"https://api.github.com/users/Whaka-project/events{/privacy}","received_events_url":"https://api.github.com/users/Whaka-project/received_events","type":"Organization","site_admin":false},"repo":{"id":40726014,"name":"whakamatautau-util","full_name":"Whaka-project/whakamatautau-util","owner":{"login":"Whaka-project","id":13866233,"avatar_url":"https://avatars.githubusercontent.com/u/13866233?v=3","gravatar_id":"","url":"https://api.github.com/users/Whaka-project","html_url":"https://github.com/Whaka-project","followers_url":"https://api.github.com/users/Whaka-project/followers","following_url":"https://api.github.com/users/Whaka-project/following{/other_user}","gists_url":"https://api.github.com/users/Whaka-project/gists{/gist_id}","starred_url":"https://api.github.com/users/Whaka-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Whaka-project/subscriptions","organizations_url":"https://api.github.com/users/Whaka-project/orgs","repos_url":"https://api.github.com/users/Whaka-project/repos","events_url":"https://api.github.com/users/Whaka-project/events{/privacy}","received_events_url":"https://api.github.com/users/Whaka-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Whaka-project/whakamatautau-util","description":"Set of utils useful for authomation testing and any everyday coding","fork":false,"url":"https://api.github.com/repos/Whaka-project/whakamatautau-util","forks_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/forks","keys_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/teams","hooks_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/hooks","issue_events_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/events{/number}","events_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/events","assignees_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/assignees{/user}","branches_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/branches{/branch}","tags_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/tags","blobs_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/refs{/sha}","trees_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/statuses/{sha}","languages_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/languages","stargazers_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/stargazers","contributors_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/contributors","subscribers_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/subscribers","subscription_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/subscription","commits_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/commits{/sha}","git_commits_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/git/commits{/sha}","comments_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/comments{/number}","issue_comment_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/comments{/number}","contents_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/contents/{+path}","compare_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/merges","archive_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/downloads","issues_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues{/number}","pulls_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls{/number}","milestones_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/milestones{/number}","notifications_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/labels{/name}","releases_url":"https://api.github.com/repos/Whaka-project/whakamatautau-util/releases{/id}","created_at":"2015-08-14T16:52:16Z","updated_at":"2015-08-19T08:42:03Z","pushed_at":"2015-08-28T13:33:37Z","git_url":"git://github.com/Whaka-project/whakamatautau-util.git","ssh_url":"git@github.com:Whaka-project/whakamatautau-util.git","clone_url":"https://github.com/Whaka-project/whakamatautau-util.git","svn_url":"https://github.com/Whaka-project/whakamatautau-util","homepage":null,"size":1097,"stargazers_count":0,"watchers_count":0,"language":"Groovy","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":12,"forks":1,"open_issues":12,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68"},"html":{"href":"https://github.com/Whaka-project/whakamatautau-util/pull/68"},"issue":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/68"},"comments":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/issues/68/comments"},"review_comments":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68/comments"},"review_comment":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/pulls/68/commits"},"statuses":{"href":"https://api.github.com/repos/Whaka-project/whakamatautau-util/statuses/edf7e972a9df5495e42b02a29cced894a8cd0672"}}}}