Ignore:
Timestamp:
2017-06-22T23:08:53+02:00 (7 years ago)
Author:
donvip
Message:

see #josm14933 - fix unit tests in Eclipse

Location:
applications/editors/josm/plugins/pt_assistant
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/.classpath

    r32680 r33412  
    22<classpath>
    33        <classpathentry kind="src" path="src"/>
     4        <classpathentry including="GPL-v2.0.txt|GPL-v3.0.txt|LICENSE|README|data/|images/|resources/" kind="src" path=""/>
    45        <classpathentry kind="src" path="test/unit"/>
    56        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutTest.java

    r33410 r33412  
    88import java.io.FileNotFoundException;
    99import java.util.Collection;
     10import java.util.Collections;
    1011import java.util.List;
    1112import java.util.Map;
    1213
    13 import org.junit.After;
    1414import org.junit.Before;
     15import org.junit.Rule;
    1516import org.junit.Test;
    16 import org.openstreetmap.josm.JOSMFixture;
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.actions.SplitWayAction;
     19import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult;
    1920import org.openstreetmap.josm.data.osm.DataSet;
    2021import org.openstreetmap.josm.data.osm.Node;
     
    2728import org.openstreetmap.josm.io.OsmReader;
    2829import org.openstreetmap.josm.plugins.pt_assistant.AbstractTest;
     30import org.openstreetmap.josm.testutils.JOSMTestRules;
    2931
    3032public class SplitRoundaboutTest extends AbstractTest {
    3133
    32     DataSet ds;
    33     OsmDataLayer layer;
    34     SplitRoundaboutAction action;
    35     SplitWayAction swa;
    36     Way r1, r2, r3;
     34    /**
     35     * Setup test.
     36     */
     37    @Rule
     38    public JOSMTestRules rules = new JOSMTestRules().preferences().platform();
     39
     40    private DataSet ds;
     41    private OsmDataLayer layer;
     42    private SplitRoundaboutAction action;
     43    private Way r1, r2, r3;
    3744
    3845    @Before
    3946    public void init() throws FileNotFoundException, IllegalDataException {
    40 
    41         new JOSMFixture("../../JOSM/test/config/unit-josm.home").init(true);
    42 
    4347        ds = OsmReader.parseDataSet(new FileInputStream(AbstractTest.PATH_TO_ROUNDABOUT), null);
    4448        layer = new OsmDataLayer(ds, OsmDataLayer.createNewName(), null);
     
    4751        Main.pref.put("pt_assistant.roundabout-splitter.alignalways", true);
    4852        action = new SplitRoundaboutAction();
    49         swa = Main.main.menu.splitWay;
    50         swa.setEnabled(true);
    5153        r1 = (Way) ds.getPrimitiveById(new SimplePrimitiveId(293302077L, OsmPrimitiveType.WAY));
    5254        r2 = (Way) ds.getPrimitiveById(new SimplePrimitiveId(205833435L, OsmPrimitiveType.WAY));
     
    5456    }
    5557
     58    private Collection<Way> splitWay(Way w) {
     59        Map<Relation, Integer> savedPositions = action.getSavedPositions(w);
     60        List<Node> splitNodes = action.getSplitNodes(w);
     61        assertEquals(4, splitNodes.size());
     62        SplitWayResult result = SplitWayAction.split(layer, w, splitNodes, Collections.emptyList());
     63        result.getCommand().executeCommand();
     64        Collection<Way> splitWays = result.getNewWays();
     65        action.updateRelations(savedPositions, splitNodes, splitWays);
     66        return splitWays;
     67    }
     68
    5669    @Test
    5770    public void test1() {
    58 
    59         Map<Relation, Integer> savedPositions = action.getSavedPositions(r1);
    60         List<Node> splitNodes = action.getSplitNodes(r1);
    61         assertEquals(4, splitNodes.size());
    62         ds.setSelected(splitNodes);
    63         swa.actionPerformed(null);
    64 
    65         Collection<Way> splitWays = ds.getSelectedWays();
    66         action.updateRelations(savedPositions, splitNodes, splitWays);
    67 
    68         splitWays.forEach(w -> {
     71        splitWay(r1).forEach(w -> {
    6972                if (w.firstNode().getUniqueId() == 267843779L && w.lastNode().getUniqueId() == 2968718407L)
    7073                assertEquals(w.getReferrers().size(), 5);
     
    8083    }
    8184
    82      @Test
    83      public void test2() {
    84         Map<Relation, Integer> savedPositions = action.getSavedPositions(r2);
    85         List<Node> splitNodes = action.getSplitNodes(r2);
    86         assertEquals(4, splitNodes.size());
    87         ds.setSelected(splitNodes);
    88         swa.actionPerformed(null);
    89 
    90         Collection<Way> splitWays = ds.getSelectedWays();
    91         action.updateRelations(savedPositions, splitNodes, splitWays);
    92 
    93         splitWays.forEach(w -> {
     85    @Test
     86    public void test2() {
     87        splitWay(r2).forEach(w -> {
    9488            if(w.firstNode().getUniqueId() == 2158181809L && w.lastNode().getUniqueId() == 2158181798L)
    9589                assertEquals(w.getReferrers().size(), 8);
     
    10397                fail();
    10498        });
    105      }
     99    }
    106100
    107      @Test
    108      public void test3() {
    109          Map<Relation, Integer> savedPositions = action.getSavedPositions(r3);
    110         List<Node> splitNodes = action.getSplitNodes(r3);
    111         assertEquals(4, splitNodes.size());
    112         ds.setSelected(splitNodes);
    113         swa.actionPerformed(null);
    114 
    115         Collection<Way> splitWays = ds.getSelectedWays();
    116         action.updateRelations(savedPositions, splitNodes, splitWays);
    117 
    118         splitWays.forEach(w -> {
     101    @Test
     102    public void test3() {
     103        splitWay(r3).forEach(w -> {
    119104            if(w.firstNode().getUniqueId() == 280697532L && w.lastNode().getUniqueId() == 280697452L)
    120105                assertEquals(w.getReferrers().size(), 0);
     
    128113                fail();
    129114        });
    130      }
    131 
    132     @After
    133     public void end() {
    134         Main.getLayerManager().removeLayer(layer);
    135115    }
    136116}
Note: See TracChangeset for help on using the changeset viewer.