add unit tests

This commit is contained in:
bancika
2020-04-09 23:45:16 +02:00
parent 6c3185c3ad
commit c2007f62b1
7 changed files with 125 additions and 21 deletions
@@ -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);
}
}