package test.gui.pencil;
import com.google.inject.AbstractModule;
import javafx.scene.paint.Color;
import net.sf.latexdraw.instruments.Hand;
import net.sf.latexdraw.instruments.Pencil;
import net.sf.latexdraw.instruments.ShapeDoubleBorderCustomiser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import test.gui.CompositeGUIVoidCommand;
import test.gui.ShapePropModule;
import test.gui.TestDoubleLineStyleGUI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@RunWith(MockitoJUnitRunner.class)
public class TestPencilDoubleLineStyle extends TestDoubleLineStyleGUI {
@Override
protected AbstractModule createModule() {
return new ShapePropModule() {
@Override
protected void configure() {
super.configure();
hand = mock(Hand.class);
bind(ShapeDoubleBorderCustomiser.class).asEagerSingleton();
bind(Pencil.class).asEagerSingleton();
bind(Hand.class).toInstance(hand);
}
};
}
@Test
public void testControllerActivatedWhenGoodPencilUsed() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, updateIns, checkInsActivated).execute();
}
@Test
public void testControllerNotActivatedWhenBadPencilUsed() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesDot, updateIns, checkInsDeactivated).execute();
}
@Test
public void testWidgetsGoodStateWhenGoodPencilUsed() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, updateIns).execute();
assertTrue(titledPane.isVisible());
}
@Test
public void testWidgetsGoodStateWhenBadPencilUsed() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesPic, updateIns).execute();
assertFalse(titledPane.isVisible());
}
@Test
public void testNotDbledWidgetsNotEnabledPencil() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, updateIns).execute();
assertFalse(dbleBoundCB.isDisabled());
assertTrue(dbleBoundColB.isDisabled());
assertTrue(dbleSepField.isDisabled());
}
@Test
public void testDbledWidgetsEnabledPencil() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, selectdbleLine, updateIns).execute();
assertFalse(dbleBoundCB.isDisabled());
assertFalse(dbleBoundColB.isDisabled());
assertFalse(dbleSepField.isDisabled());
}
@Test
public void testSelectDbleLinePencil() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, updateIns).execute();
boolean sel = dbleBoundCB.isSelected();
selectdbleLine.execute();
assertEquals(!sel, pencil.createShapeInstance().hasDbleBord());
assertNotEquals(sel, dbleBoundCB.isSelected());
}
@Test
public void testIncrementDbleSpacingPencil() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, selectdbleLine, updateIns).execute();
double val = dbleSepField.getValue();
incrementDbleSep.execute();
assertEquals(dbleSepField.getValue(), pencil.createShapeInstance().getDbleBordSep(), 0.0001);
assertNotEquals(val, dbleSepField.getValue(), 0.0001);
}
@Test
public void testPickDbleColourPencil() {
new CompositeGUIVoidCommand(activatePencil, pencilCreatesRec, selectdbleLine, updateIns).execute();
Color col = dbleBoundColB.getValue();
pickDbleColour.execute();
assertEquals(dbleBoundColB.getValue(), pencil.createShapeInstance().getDbleBordCol().toJFX());
assertNotEquals(col, dbleBoundColB.getValue());
}
}