@Test public void testSearching() throws Exception { FXPlatform.invokeLater( () -> { adocEditor.searchField.setText("b"); adocEditor.setText("a\na\na\nb\nb\na\nb"); adocEditor.searchForText(); }); activityController.waitForTasks(); FXPlatform.waitForFX(); assertEquals(6, adocEditor.editor.getCaretPosition()); FXPlatform.invokeLater(() -> adocEditor.searchForText()); activityController.waitForTasks(); FXPlatform.waitForFX(); assertEquals(8, adocEditor.editor.getCaretPosition()); FXPlatform.invokeLater(() -> adocEditor.searchForText()); activityController.waitForTasks(); FXPlatform.waitForFX(); assertEquals(12, adocEditor.editor.getCaretPosition()); FXPlatform.invokeLater(() -> adocEditor.searchForText()); activityController.waitForTasks(); FXPlatform.waitForFX(); assertEquals(6, adocEditor.editor.getCaretPosition()); }
@Before public void setUp() throws Exception { ApplicationService service = Launcher.instance.getService(ApplicationService.class); Navigator.registerWithBorderPane(service.getStage()); activityController.startOrResume(new ActivityHint(AscidoctTestActivity.class)); adocEditor = activityController.getControllerInstance(AsciiDocEditor.class); }
@Test public void testImageInsertion() throws Exception { imageProvider.addImage(new ImageData("test", "/de/ks/images/keymap.jpg")); InsertImage command = adocEditor.getCommand(InsertImage.class); command.collectImages(); SelectImageController selectImageController = command.getSelectImageController(); for (Future<?> future : selectImageController.getLoadingFutures()) { future.get(); } activityController.waitForTasks(); FXPlatform.waitForFX(); assertEquals(1, selectImageController.getImagePane().getChildren().size()); FXPlatform.invokeLater( () -> { GridPane grid = (GridPane) command.getSelectImageController().getImagePane().getChildren().get(0); Button node = (Button) grid.getChildren().get(0); node.getOnAction().handle(null); }); assertThat( adocEditor.editor.getText(), Matchers.containsString("image::file:////de/ks/images/keymap.jpg")); }
@Test public void testPersistentStoreBack() throws Exception { File file = new File(System.getProperty("java.io.tmpdir")); adocEditor.setPersistentStoreBack("test", file); FXPlatform.invokeLater(() -> adocEditor.setText("bla blubb")); Thread.sleep(LastTextChange.WAIT_TIME * 2); activityController.waitForTasks(); List<String> strings = Files.readLines(new File(file, "test"), Charsets.UTF_8); assertEquals(1, strings.size()); adocEditor.removePersistentStoreBack(); FXPlatform.invokeLater(() -> adocEditor.setText("")); Thread.sleep(LastTextChange.WAIT_TIME * 2); activityController.waitForTasks(); adocEditor.setPersistentStoreBack("test", file); FXPlatform.invokeLater(() -> adocEditor.onRefresh(null)); activityController.waitForTasks(); assertEquals("bla blubb\n", adocEditor.getText()); }
@After public void tearDown() throws Exception { activityController.stopAll(); }