@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());
  }
  @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());
  }