Search in sources :

Example 1 with LaTeXDraw

use of net.sf.latexdraw.LaTeXDraw in project latexdraw by arnobl.

the class TestCodeInserter method setUp.

@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
    final Injector injector = createInjector();
    final LaTeXDraw ld = Mockito.mock(LaTeXDraw.class);
    final Field field = LaTeXDraw.class.getDeclaredField("instance");
    field.setAccessible(true);
    field.set(null, ld);
    Mockito.when(LaTeXDraw.getInstance().getInjector()).thenReturn(injector);
    Mockito.when(LaTeXDraw.getInstance().getInstanceCallBack()).thenReturn(cl -> injector.getInstance(cl));
    drawing = LaTeXDraw.getInstance().getInjector().getInstance(IDrawing.class);
    Platform.runLater(() -> {
        inserter = LaTeXDraw.getInstance().getInjector().getInstance(CodeInserter.class);
        try {
            FxToolkit.registerStage(() -> inserter.getInsertCodeDialogue().orElse(null));
            WaitForAsyncUtils.waitForFxEvents();
        } catch (final TimeoutException ex) {
            fail(ex.getMessage());
        }
        inserter.setActivated(true);
        WaitForAsyncUtils.waitForFxEvents();
        inserter.getInsertCodeDialogue().ifPresent(stage -> {
            stage.show();
            stage.toFront();
        });
    });
    WaitForAsyncUtils.waitForFxEvents();
}
Also used : Field(java.lang.reflect.Field) IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) Injector(net.sf.latexdraw.util.Injector) LaTeXDraw(net.sf.latexdraw.LaTeXDraw) TimeoutException(java.util.concurrent.TimeoutException) Before(org.junit.Before)

Example 2 with LaTeXDraw

use of net.sf.latexdraw.LaTeXDraw in project latexdraw by arnobl.

the class TestExporter method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    exporter = (Exporter) injectorFactory.call(Exporter.class);
    hand.setActivated(true);
    when(pencil.isActivated()).thenReturn(false);
    WaitForAsyncUtils.waitForFxEvents();
    final TemplateManager template = (TemplateManager) injectorFactory.call(TemplateManager.class);
    template.templatePane = new FlowPane();
    final StatusBarController status = (StatusBarController) injectorFactory.call(StatusBarController.class);
    Mockito.when(status.getLabel()).thenReturn(new Label());
    Mockito.when(status.getProgressBar()).thenReturn(new ProgressBar());
    chooser = Mockito.mock(FileChooser.class);
    Mockito.when(chooser.getExtensionFilters()).thenReturn(FXCollections.observableArrayList());
    try {
        Mockito.when(chooser.showOpenDialog(Mockito.any())).thenReturn(tmp.newFile());
        Mockito.when(chooser.showSaveDialog(Mockito.any())).thenReturn(tmp.newFile());
        Field field = Exporter.class.getDeclaredField("fileChooserExport");
        field.setAccessible(true);
        field.set(exporter, chooser);
        final LaTeXDraw ld = Mockito.mock(LaTeXDraw.class);
        field = LaTeXDraw.class.getDeclaredField("instance");
        field.setAccessible(true);
        field.set(null, ld);
    } catch (final IllegalAccessException | NoSuchFieldException | IOException ex) {
        fail(ex.getMessage());
    }
}
Also used : Field(java.lang.reflect.Field) LaTeXDraw(net.sf.latexdraw.LaTeXDraw) Label(javafx.scene.control.Label) FileChooser(javafx.stage.FileChooser) FlowPane(javafx.scene.layout.FlowPane) IOException(java.io.IOException) ProgressBar(javafx.scene.control.ProgressBar) Before(org.junit.Before)

Aggregations

Field (java.lang.reflect.Field)2 LaTeXDraw (net.sf.latexdraw.LaTeXDraw)2 Before (org.junit.Before)2 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Label (javafx.scene.control.Label)1 ProgressBar (javafx.scene.control.ProgressBar)1 FlowPane (javafx.scene.layout.FlowPane)1 FileChooser (javafx.stage.FileChooser)1 IDrawing (net.sf.latexdraw.models.interfaces.shape.IDrawing)1 Injector (net.sf.latexdraw.util.Injector)1