mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
add unit tests
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="lib" path="lib/commons-compiler-3.0.6.jar"/>
|
<classpathentry kind="lib" path="lib/commons-compiler-3.0.6.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/janino-3.0.6.jar"/>
|
<classpathentry kind="lib" path="lib/janino-3.0.6.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,37 @@
|
|||||||
|
package org.diylc;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
|
||||||
|
public class MockView implements IView {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showMessage(String message, String title, int messageType) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int showConfirmDialog(String message, String title, int optionType, int messageType) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean editProperties(List<PropertyWrapper> properties,
|
||||||
|
Set<PropertyWrapper> defaultedProperties) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File promptFileSave() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.diylc;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
public class PresenterTests extends TestBase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testComponentLoad() {
|
||||||
|
Assert.assertTrue(presenter.getComponentTypes() != null && presenter.getComponentTypes().size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTwoClickAdd() {
|
||||||
|
instantiateTwoClick("Passive", "Resistor", new Point(1000, 1000), new Point(1200, 1000));
|
||||||
|
Assert.assertEquals(1, presenter.getCurrentProject().getComponents().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneClickAdd() {
|
||||||
|
instantiateOneClick("Connectivity", "Solder Pad", new Point(1000, 1000));
|
||||||
|
Assert.assertEquals(1, presenter.getCurrentProject().getComponents().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.diylc;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
import org.diylc.common.ComponentType;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.presenter.Presenter;
|
||||||
|
|
||||||
|
public class TestBase {
|
||||||
|
|
||||||
|
protected Presenter presenter;
|
||||||
|
protected IView view;
|
||||||
|
|
||||||
|
public TestBase() {
|
||||||
|
ConfigurationManager.initialize("diylc-test");
|
||||||
|
view = new MockView();
|
||||||
|
presenter = new Presenter(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void instantiateOneClick(String category, String name, Point point1) {
|
||||||
|
Map<String, List<ComponentType>> componentTypes = presenter.getComponentTypes();
|
||||||
|
ComponentType resistorType = componentTypes.get(category).stream().filter(x -> x.getName().equals(name)).findFirst().get();
|
||||||
|
presenter.setNewComponentTypeSlot(resistorType, null, false);
|
||||||
|
presenter.mouseClicked(point1, MouseEvent.BUTTON1, false, false, false, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void instantiateTwoClick(String category, String name, Point point1, Point point2) {
|
||||||
|
Map<String, List<ComponentType>> componentTypes = presenter.getComponentTypes();
|
||||||
|
ComponentType resistorType = componentTypes.get(category).stream().filter(x -> x.getName().equals(name)).findFirst().get();
|
||||||
|
presenter.setNewComponentTypeSlot(resistorType, null, false);
|
||||||
|
presenter.mouseClicked(point1, MouseEvent.BUTTON1, false, false, false, 1);
|
||||||
|
presenter.mouseMoved(point2, false, false, false);
|
||||||
|
presenter.mouseClicked(point2, MouseEvent.BUTTON1, false, false, false, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user