{"action":"created","issue":{"url":"https://api.github.com/repos/TestFX/TestFX/issues/217","labels_url":"https://api.github.com/repos/TestFX/TestFX/issues/217/labels{/name}","comments_url":"https://api.github.com/repos/TestFX/TestFX/issues/217/comments","events_url":"https://api.github.com/repos/TestFX/TestFX/issues/217/events","html_url":"https://github.com/TestFX/TestFX/issues/217","id":77663797,"number":217,"title":"Usage of JDK8's Optional?","user":{"login":"aalmiray","id":13969,"avatar_url":"https://avatars.githubusercontent.com/u/13969?v=3","gravatar_id":"","url":"https://api.github.com/users/aalmiray","html_url":"https://github.com/aalmiray","followers_url":"https://api.github.com/users/aalmiray/followers","following_url":"https://api.github.com/users/aalmiray/following{/other_user}","gists_url":"https://api.github.com/users/aalmiray/gists{/gist_id}","starred_url":"https://api.github.com/users/aalmiray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aalmiray/subscriptions","organizations_url":"https://api.github.com/users/aalmiray/orgs","repos_url":"https://api.github.com/users/aalmiray/repos","events_url":"https://api.github.com/users/aalmiray/events{/privacy}","received_events_url":"https://api.github.com/users/aalmiray/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-18T13:48:33Z","updated_at":"2015-05-20T12:20:39Z","closed_at":null,"body":"This is not really an issue per se but rather to begin a conversation regarding the usage of Optional in the lookup APIs at the very least.\r\n\r\nI just came across a use case where a test must wait until a tooltip is visible. A naive implementation could look like this\r\n\r\n      Callable<Boolean> callable = () -> lookup(hasText (\"hintext\")).queryFirst ().isVisible ();\r\n      Matcher<Boolean> matcher = equalTo (true);\r\n      waitUntil (callable, matcher); // Delegates to WaitUntilSupport.waitUntil with 2 seconds as timeout\r\n\r\nProblem is that the code throws an NPE because the node is not yet found in the scene (do'h!). If I were to write this test in Groovy I'd simply use the ?. operator and be done with it. Sadly in Java we don't have that luxury, but we do have `Optional` and `flatMap`. Apply `flatMap` to the body of the `callable` would effectively avoid the NPE.\r\n\r\nI'm not a fan of `Optional` as it looks like to be a simple wrapper fopr NPEs, however the usefulness of `flatMap` cannot be overlooked.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/TestFX/TestFX/issues/comments/103861372","html_url":"https://github.com/TestFX/TestFX/issues/217#issuecomment-103861372","issue_url":"https://api.github.com/repos/TestFX/TestFX/issues/217","id":103861372,"user":{"login":"hastebrot","id":496255,"avatar_url":"https://avatars.githubusercontent.com/u/496255?v=3","gravatar_id":"","url":"https://api.github.com/users/hastebrot","html_url":"https://github.com/hastebrot","followers_url":"https://api.github.com/users/hastebrot/followers","following_url":"https://api.github.com/users/hastebrot/following{/other_user}","gists_url":"https://api.github.com/users/hastebrot/gists{/gist_id}","starred_url":"https://api.github.com/users/hastebrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hastebrot/subscriptions","organizations_url":"https://api.github.com/users/hastebrot/orgs","repos_url":"https://api.github.com/users/hastebrot/repos","events_url":"https://api.github.com/users/hastebrot/events{/privacy}","received_events_url":"https://api.github.com/users/hastebrot/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T12:20:39Z","updated_at":"2015-05-20T12:20:39Z","body":"Note: We currently could also write\r\n\r\n~~~java\r\nWaitUntilSupport.waitUntil(lookup(\"label\"), NodeMatchers.isVisible(), 5);\r\n~~~"}}