Search in sources :

Example 1 with Injector

use of net.sf.latexdraw.util.Injector 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 Injector

use of net.sf.latexdraw.util.Injector in project latexdraw by arnobl.

the class TestDrawingProperties method setUp.

@Before
public void setUp() {
    final Injector injector = new Injector() {

        @Override
        protected void configure() throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
            bindAsEagerSingleton(Canvas.class);
            bindAsEagerSingleton(PSTCodeGenerator.class);
            bindWithCommand(IDrawing.class, Canvas.class, canvas -> canvas.getDrawing());
            bindWithCommand(ViewsSynchroniserHandler.class, Canvas.class, canvas -> canvas);
        }
    };
    gen = injector.getInstance(PSTCodeGenerator.class);
    drawing = injector.getInstance(IDrawing.class);
    drawing.addShape(ShapeFactory.INST.createCircle());
}
Also used : IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) Injector(net.sf.latexdraw.util.Injector) Before(org.junit.Before)

Aggregations

IDrawing (net.sf.latexdraw.models.interfaces.shape.IDrawing)2 Injector (net.sf.latexdraw.util.Injector)2 Before (org.junit.Before)2 Field (java.lang.reflect.Field)1 TimeoutException (java.util.concurrent.TimeoutException)1 LaTeXDraw (net.sf.latexdraw.LaTeXDraw)1