{"action":"created","issue":{"url":"https://api.github.com/repos/TestFX/TestFX/issues/207","labels_url":"https://api.github.com/repos/TestFX/TestFX/issues/207/labels{/name}","comments_url":"https://api.github.com/repos/TestFX/TestFX/issues/207/comments","events_url":"https://api.github.com/repos/TestFX/TestFX/issues/207/events","html_url":"https://github.com/TestFX/TestFX/issues/207","id":60603502,"number":207,"title":"How to test method of the controller?","user":{"login":"chiahao","id":4538329,"avatar_url":"https://avatars.githubusercontent.com/u/4538329?v=3","gravatar_id":"","url":"https://api.github.com/users/chiahao","html_url":"https://github.com/chiahao","followers_url":"https://api.github.com/users/chiahao/followers","following_url":"https://api.github.com/users/chiahao/following{/other_user}","gists_url":"https://api.github.com/users/chiahao/gists{/gist_id}","starred_url":"https://api.github.com/users/chiahao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chiahao/subscriptions","organizations_url":"https://api.github.com/users/chiahao/orgs","repos_url":"https://api.github.com/users/chiahao/repos","events_url":"https://api.github.com/users/chiahao/events{/privacy}","received_events_url":"https://api.github.com/users/chiahao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-11T03:07:08Z","updated_at":"2015-03-11T13:47:32Z","closed_at":null,"body":"Hi all:\r\n\r\nI was trying to use TestFX to test my application.\r\nI would like to run the test for the method of my controller.\r\nP.S. I use DataFX to controll flow.\r\n\r\nMain.java:\r\n\r\n```\r\npublic class Main extends Application {\r\n        try{\r\n\t\tnew Flow(ManageCtrl.class).startInStage(primaryStage);\r\n\t} catch (Exception ex) {\r\n\t\tLOGGER.log(Level.SEVERE, null, ex);\r\n\t}\r\n}\r\n```\r\n\r\nManageCtrl.java:\r\n\r\n```\r\n@ViewController(\"/FPManage.fxml\")\r\npublic class ManageCtrl extends AnchorPane {\r\n\r\n\t@FXML // fx:id=\"email\"\r\n\tprivate TextField email; // Value injected by FXMLLoader\r\n\r\n\tpublic void setEmail(String address) {\r\n\t\tthis.email.setText(address);\r\n\t}\r\n}\r\n\r\n```\r\n\r\nManageCtrlTest.java:\r\n\r\n```\r\npublic class ManageCtrlTest extends ApplicationTest {\r\n\r\n\t@Override\r\n\tpublic void start(Stage stage) {\r\n\t\ttry {\r\n\t\t\tnew Flow(ManageCtrl.class).startInStage(stage);\r\n\t\t} catch (FlowException ex) {\r\n\t\t\tLogger.getLogger(ManageCtrlTest.class.getName()).log(Level.SEVERE, null, ex);\r\n\t\t}\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testSetEmail() {\r\n\r\n\t\tManageCtrl instance = new ManageCtrl();\r\n\t\tinstance.setEmail(\"test@gmai.com\");\r\n\r\n\t\tassertEquals(\"test@gmail.com\", ((TextField)GuiTest.find(\"#name\")).getText());\r\n\t\t\r\n\t}\t\r\n}\r\n\r\n```\r\nBut I get the following Exception:\r\n```\r\ntestSetEmail Failed: java.lang.illegalStateException: Not on FX application thread; currentThread = Test worker\r\njava.lang.illegalStateException: Not on FX application thread; currentThread = Test Worker\r\n\r\n```\r\n\r\nThanks for the help.\r\n"},"comment":{"url":"https://api.github.com/repos/TestFX/TestFX/issues/comments/78265408","html_url":"https://github.com/TestFX/TestFX/issues/207#issuecomment-78265408","issue_url":"https://api.github.com/repos/TestFX/TestFX/issues/207","id":78265408,"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-03-11T13:47:32Z","updated_at":"2015-03-11T13:47:32Z","body":"If you have a `getEmail()` method, you can also test it:\r\n\r\n__Example 3a: `ManageCtrl .java`__\r\n~~~java\r\n@ViewController(\"manage.fxml\")\r\npublic class ManageCtrl extends AnchorPane {\r\n    @FXML\r\n    private TextField email;\r\n\r\n    public String getEmail() {\r\n        return email.getText();\r\n    }\r\n\r\n    public void setEmail(String address) {\r\n        this.email.setText(address);\r\n    }\r\n}\r\n~~~\r\n\r\n__Example 3b: `ManageCtrlTest.java`__\r\n~~~java\r\n@Test\r\npublic void should_get_email() throws Exception {\r\n    // when:\r\n    clickOn(\"#email\").write(\"test@gmail.com\");\r\n\r\n    // then:\r\n    verifyThat(controller.getEmail(), Matchers.is(\"test@gmail.com\"));\r\n}\r\n~~~\r\n"}}