Changeset 12726 in josm for trunk/test


Ignore:
Timestamp:
2017-09-04T23:45:49+02:00 (2 years ago)
Author:
Don-vip
Message:

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r12130 r12726  
    2222
    2323import org.openstreetmap.josm.command.Command;
     24import org.openstreetmap.josm.data.osm.DataSet;
    2425import org.openstreetmap.josm.data.osm.Node;
    2526import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    257258    /**
    258259     * Creates a new empty command.
     260     * @param ds data set
    259261     * @return a new empty command
    260262     */
    261     public static Command newCommand() {
    262         return new Command() {
     263    public static Command newCommand(DataSet ds) {
     264        return new Command(ds) {
    263265            @Override
    264266            public String getDescriptionText() {
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java

    r12659 r12726  
    1717import org.openstreetmap.josm.data.osm.RelationMember;
    1818import org.openstreetmap.josm.data.osm.Way;
     19import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    1920import org.openstreetmap.josm.data.osm.search.SearchParseError;
    2021import org.openstreetmap.josm.data.osm.search.SearchSetting;
    21 import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    2222import org.openstreetmap.josm.io.OsmReader;
    2323import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4242        Map<String, String> refToRole = new TreeMap<>();
    4343        for (RelationMember i : relation.getMembers()) {
    44             refToRole.put(i.getMember().get("ref"), i.getRole());
     44            String ref = i.getMember().get("ref");
     45            if (ref != null) {
     46                refToRole.put(ref, i.getRole());
     47            }
    4548        }
    4649        return refToRole;
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r12643 r12726  
    162162    void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) {
    163163        final DataSet dataSet = new DataSet();
    164         final OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
    165164        final Node n1 = new Node(new LatLon(1, 0));
    166165        final Node n2 = new Node(new LatLon(2, 0));
     
    197196            };
    198197        final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay(
    199                 layer, w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);
     198                w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);
    200199        MainApplication.undoRedo.add(result.getCommand());
    201200
  • trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java

    r12636 r12726  
    1616import org.openstreetmap.josm.data.osm.User;
    1717import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.gui.MainApplication;
    1918import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2019import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4140    @Test
    4241    public void testAdd() {
    43         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    44         MainApplication.getLayerManager().addLayer(layer1);
    45         assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray());
     42        DataSet ds = new DataSet();
     43        assertArrayEquals(new Object[0], ds.allPrimitives().toArray());
    4644
    4745        Node osm = new Node(LatLon.ZERO);
    48         assertTrue(new AddCommand(osm).executeCommand());
     46        assertTrue(new AddCommand(ds, osm).executeCommand());
    4947
    50         assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());
    51         assertArrayEquals(new Object[] {osm}, layer1.data.allModifiedPrimitives().toArray());
     48        assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray());
     49        assertArrayEquals(new Object[] {osm}, ds.allModifiedPrimitives().toArray());
    5250        assertTrue(osm.isModified());
    5351    }
    5452
    5553    /**
    56      * Tests if the add command respects the layer.
     54     * Tests if the add command respects the data set.
    5755     */
    5856    @Test
    5957    public void testAddToLayer() {
    60         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    61         OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null);
    62 
    63         MainApplication.getLayerManager().addLayer(layer1);
    64         MainApplication.getLayerManager().addLayer(layer2);
     58        DataSet ds1 = new DataSet();
     59        DataSet ds2 = new DataSet();
    6560
    6661        Node osm = new Node(LatLon.ZERO);
    67         assertTrue(new AddCommand(layer2, osm).executeCommand());
     62        assertTrue(new AddCommand(ds2, osm).executeCommand());
    6863
    69         assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray());
    70         assertArrayEquals(new Object[] {osm}, layer2.data.allPrimitives().toArray());
     64        assertArrayEquals(new Object[0], ds1.allPrimitives().toArray());
     65        assertArrayEquals(new Object[] {osm}, ds2.allPrimitives().toArray());
    7166    }
    7267
     
    7671    @Test
    7772    public void testUndo() {
    78         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    79         MainApplication.getLayerManager().addLayer(layer1);
    8073        Node osm = new Node(LatLon.ZERO);
    81         layer1.data.addPrimitive(osm);
     74        DataSet ds = new DataSet(osm);
    8275
    83         AddCommand command = new AddCommand(new Node(LatLon.ZERO));
     76        AddCommand command = new AddCommand(ds, new Node(LatLon.ZERO));
    8477        command.executeCommand();
    8578
    8679        command.undoCommand();
    87         assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());
     80        assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray());
    8881    }
    8982
     
    9588        Node osm = new Node(LatLon.ZERO);
    9689
    97         assertArrayEquals(new Object[] {osm}, new AddCommand(osm).getParticipatingPrimitives().toArray());
     90        assertArrayEquals(new Object[] {osm}, new AddCommand(new DataSet(), osm).getParticipatingPrimitives().toArray());
    9891    }
    9992
     
    108101        ArrayList<OsmPrimitive> deleted = new ArrayList<>();
    109102        ArrayList<OsmPrimitive> added = new ArrayList<>();
    110         new AddCommand(osm).fillModifiedData(modified, deleted, added);
     103        new AddCommand(new DataSet(), osm).fillModifiedData(modified, deleted, added);
    111104        assertArrayEquals(new Object[] {}, modified.toArray());
    112105        assertArrayEquals(new Object[] {}, deleted.toArray());
     
    127120        relation.put("name", "xy");
    128121
    129         assertTrue(new AddCommand(node).getDescriptionText().matches("Add node.*xy.*"));
    130         assertTrue(new AddCommand(way).getDescriptionText().matches("Add way.*xy.*"));
    131         assertTrue(new AddCommand(relation).getDescriptionText().matches("Add relation.*xy.*"));
     122        DataSet ds = new DataSet();
     123        assertTrue(new AddCommand(ds, node).getDescriptionText().matches("Add node.*xy.*"));
     124        assertTrue(new AddCommand(ds, way).getDescriptionText().matches("Add way.*xy.*"));
     125        assertTrue(new AddCommand(ds, relation).getDescriptionText().matches("Add relation.*xy.*"));
    132126    }
    133127
  • trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java

    r12636 r12726  
    2323import org.openstreetmap.josm.data.osm.Way;
    2424import org.openstreetmap.josm.data.osm.WayData;
    25 import org.openstreetmap.josm.gui.MainApplication;
    2625import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2726import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4847    @Test
    4948    public void testAdd() {
    50         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    51         MainApplication.getLayerManager().addLayer(layer1);
    52 
    53         List<PrimitiveData> testData = createTestData();
    54         assertTrue(new AddPrimitivesCommand(testData).executeCommand());
    55 
    56         testContainsTestData(layer1);
    57         assertEquals(3, layer1.data.getAllSelected().size());
     49        DataSet ds = new DataSet();
     50
     51        List<PrimitiveData> testData = createTestData();
     52        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
     53
     54        testContainsTestData(ds);
     55        assertEquals(3, ds.getAllSelected().size());
    5856    }
    5957
     
    6361    @Test
    6462    public void testAddSetSelection() {
    65         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    66         MainApplication.getLayerManager().addLayer(layer1);
    67 
    68         List<PrimitiveData> testData = createTestData();
    69         assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3)).executeCommand());
    70 
    71         testContainsTestData(layer1);
    72 
    73         assertEquals(1, layer1.data.getAllSelected().size());
    74         assertEquals(1, layer1.data.getSelectedWays().size());
    75     }
    76 
    77     /**
    78      * Tests if the add command respects the layer.
     63        DataSet ds = new DataSet();
     64
     65        List<PrimitiveData> testData = createTestData();
     66        assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds).executeCommand());
     67
     68        testContainsTestData(ds);
     69
     70        assertEquals(1, ds.getAllSelected().size());
     71        assertEquals(1, ds.getSelectedWays().size());
     72    }
     73
     74    /**
     75     * Tests if the add command respects the data set.
    7976     */
    8077    @Test
    8178    public void testAddToLayer() {
    82         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    83         OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null);
    84 
    85         MainApplication.getLayerManager().addLayer(layer1);
    86         MainApplication.getLayerManager().addLayer(layer2);
    87 
    88         List<PrimitiveData> testData = createTestData();
    89         assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), layer1).executeCommand());
    90 
    91         testContainsTestData(layer1);
    92         assertTrue(layer2.data.allPrimitives().isEmpty());
    93 
    94         assertEquals(1, layer1.data.getAllSelected().size());
    95         assertEquals(1, layer1.data.getSelectedWays().size());
     79        DataSet ds1 = new DataSet();
     80        DataSet ds2 = new DataSet();
     81
     82        List<PrimitiveData> testData = createTestData();
     83        assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds1).executeCommand());
     84
     85        testContainsTestData(ds1);
     86        assertTrue(ds2.allPrimitives().isEmpty());
     87
     88        assertEquals(1, ds1.getAllSelected().size());
     89        assertEquals(1, ds1.getSelectedWays().size());
    9690    }
    9791
     
    10195    @Test
    10296    public void testAddIgnoresExisting() {
    103         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    104         MainApplication.getLayerManager().addLayer(layer1);
    105 
    106         List<PrimitiveData> testData = createTestData();
    107         assertTrue(new AddPrimitivesCommand(testData).executeCommand());
    108         assertEquals(2, layer1.data.getNodes().size());
    109         assertEquals(1, layer1.data.getWays().size());
     97        DataSet ds = new DataSet();
     98
     99        List<PrimitiveData> testData = createTestData();
     100        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
     101        assertEquals(2, ds.getNodes().size());
     102        assertEquals(1, ds.getWays().size());
    110103
    111104        testData.set(2, createTestNode(7));
    112         assertTrue(new AddPrimitivesCommand(testData).executeCommand());
    113 
    114         assertEquals(3, layer1.data.getNodes().size());
    115         assertEquals(1, layer1.data.getWays().size());
     105        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
     106
     107        assertEquals(3, ds.getNodes().size());
     108        assertEquals(1, ds.getWays().size());
    116109    }
    117110
     
    121114    @Test
    122115    public void testDescription() {
    123         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    124         MainApplication.getLayerManager().addLayer(layer1);
     116        DataSet ds = new DataSet();
    125117
    126118        List<PrimitiveData> testData = createTestData();
    127119        NodeData data2 = createTestNode(7);
    128120
    129         AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData);
    130         AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2));
     121        AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData, ds);
     122        AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2), ds);
    131123
    132124        assertEquals("Added 3 objects", command1.getDescriptionText());
     
    146138    @Test
    147139    public void testUndo() {
    148         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    149         MainApplication.getLayerManager().addLayer(layer1);
    150 
    151         List<PrimitiveData> testData = createTestData();
    152 
    153         AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
     140        DataSet ds = new DataSet();
     141
     142        List<PrimitiveData> testData = createTestData();
     143
     144        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
    154145
    155146        assertTrue(command.executeCommand());
    156147
    157         assertEquals(3, layer1.data.allPrimitives().size());
    158         assertEquals(1, layer1.data.getWays().size());
    159         Way way = layer1.data.getWays().iterator().next();
     148        assertEquals(3, ds.allPrimitives().size());
     149        assertEquals(1, ds.getWays().size());
     150        Way way = ds.getWays().iterator().next();
    160151
    161152        for (int i = 0; i < 2; i++) {
     
    163154            command.undoCommand();
    164155
    165             assertEquals(0, layer1.data.allPrimitives().size());
    166             assertEquals(0, layer1.data.getWays().size());
     156            assertEquals(0, ds.allPrimitives().size());
     157            assertEquals(0, ds.getWays().size());
    167158
    168159            // redo
    169160            assertTrue(command.executeCommand());
    170161
    171             assertEquals(3, layer1.data.allPrimitives().size());
    172             assertEquals(1, layer1.data.getWays().size());
    173             assertSame(way, layer1.data.getWays().iterator().next());
     162            assertEquals(3, ds.allPrimitives().size());
     163            assertEquals(1, ds.getWays().size());
     164            assertSame(way, ds.getWays().iterator().next());
    174165        }
    175166    }
     
    181172    @Test
    182173    public void testUndoIgnoresExisting() {
    183         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    184         MainApplication.getLayerManager().addLayer(layer1);
    185 
    186         List<PrimitiveData> testData = createTestData();
    187 
    188         assertTrue(new AddPrimitivesCommand(testData).executeCommand());
    189         assertEquals(2, layer1.data.getNodes().size());
    190         assertEquals(1, layer1.data.getWays().size());
     174        DataSet ds = new DataSet();
     175
     176        List<PrimitiveData> testData = createTestData();
     177
     178        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
     179        assertEquals(2, ds.getNodes().size());
     180        assertEquals(1, ds.getWays().size());
    191181
    192182        testData.set(2, createTestNode(7));
    193183
    194         AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
     184        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
    195185
    196186        assertTrue(command.executeCommand());
    197187
    198         assertEquals(3, layer1.data.getNodes().size());
    199         assertEquals(1, layer1.data.getWays().size());
     188        assertEquals(3, ds.getNodes().size());
     189        assertEquals(1, ds.getWays().size());
    200190
    201191        for (int i = 0; i < 2; i++) {
     
    203193            command.undoCommand();
    204194
    205             assertEquals(2, layer1.data.getNodes().size());
    206             assertEquals(1, layer1.data.getWays().size());
     195            assertEquals(2, ds.getNodes().size());
     196            assertEquals(1, ds.getWays().size());
    207197
    208198            // redo
    209199            assertTrue(command.executeCommand());
    210200
    211             assertEquals(3, layer1.data.getNodes().size());
    212             assertEquals(1, layer1.data.getWays().size());
     201            assertEquals(3, ds.getNodes().size());
     202            assertEquals(1, ds.getWays().size());
    213203        }
    214204    }
     
    219209    @Test
    220210    public void testParticipatingPrimitives() {
    221         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    222         MainApplication.getLayerManager().addLayer(layer1);
    223 
    224         List<PrimitiveData> testData = createTestData();
    225         AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
     211        DataSet ds = new DataSet();
     212
     213        List<PrimitiveData> testData = createTestData();
     214        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
    226215        assertTrue(command.executeCommand());
    227216
    228217        assertEquals(3, command.getParticipatingPrimitives().size());
    229         HashSet<OsmPrimitive> should = new HashSet<>(layer1.data.allPrimitives());
     218        HashSet<OsmPrimitive> should = new HashSet<>(ds.allPrimitives());
    230219        assertEquals(should, new HashSet<>(command.getParticipatingPrimitives()));
    231220
     
    245234
    246235        List<PrimitiveData> testData = createTestData();
    247         new AddPrimitivesCommand(testData).fillModifiedData(modified, deleted, added);
     236        new AddPrimitivesCommand(testData, new DataSet()).fillModifiedData(modified, deleted, added);
    248237
    249238        assertArrayEquals(new Object[] {}, modified.toArray());
     
    252241    }
    253242
    254     private void testContainsTestData(OsmDataLayer layer1) {
    255         assertEquals(3, layer1.data.allPrimitives().size());
    256         assertEquals(2, layer1.data.getNodes().size());
    257         assertEquals(1, layer1.data.getWays().size());
    258         assertEquals(3, layer1.data.allModifiedPrimitives().size());
    259         for (OsmPrimitive n : layer1.data.allPrimitives()) {
     243    private void testContainsTestData(DataSet data) {
     244        assertEquals(3, data.allPrimitives().size());
     245        assertEquals(2, data.getNodes().size());
     246        assertEquals(1, data.getWays().size());
     247        assertEquals(3, data.allModifiedPrimitives().size());
     248        for (OsmPrimitive n : data.allPrimitives()) {
    260249            assertEquals("test", n.get("test"));
    261250            assertTrue(n.isModified());
    262251        }
    263252
    264         for (Node n : layer1.data.getNodes()) {
     253        for (Node n : data.getNodes()) {
    265254            assertEquals(LatLon.ZERO, n.getCoor());
    266255        }
    267256
    268         for (Way w : layer1.data.getWays()) {
     257        for (Way w : data.getWays()) {
    269258            assertEquals(2, w.getNodes().size());
    270259            assertEquals(5, w.getNode(0).getId());
  • trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java

    r10758 r12726  
    142142        Relation relation = new Relation();
    143143        relation.put("name", "xy");
     144        DataSet ds = new DataSet(node, way, relation);
    144145
    145         assertTrue(new ChangeCommand(node, node).getDescriptionText().matches("Change node.*xy.*"));
    146         assertTrue(new ChangeCommand(way, way).getDescriptionText().matches("Change way.*xy.*"));
    147         assertTrue(new ChangeCommand(relation, relation).getDescriptionText().matches("Change relation.*xy.*"));
     146        assertTrue(new ChangeCommand(ds, node, node).getDescriptionText().matches("Change node.*xy.*"));
     147        assertTrue(new ChangeCommand(ds, way, way).getDescriptionText().matches("Change way.*xy.*"));
     148        assertTrue(new ChangeCommand(ds, relation, relation).getDescriptionText().matches("Change relation.*xy.*"));
    148149    }
    149150
  • trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java

    r10758 r12726  
    115115        way.addNode(node);
    116116        way.put("name", "xy");
    117 
     117        DataSet ds = new DataSet(node, way);
    118118        assertTrue(
    119                 new ChangeNodesCommand(way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));
     119                new ChangeNodesCommand(ds, way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));
    120120    }
    121121
  • trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java

    r10758 r12726  
    201201        tagsRemove.put("existing", "");
    202202
    203         Way way = new Way();
    204         way.addNode(node1);
     203        Way way = testData.createWay(20, node1);
    205204        way.put("name", "xy");
    206205        way.put("existing", "existing");
    207         Relation relation = new Relation();
     206        Relation relation = testData.createRelation(30);
    208207        relation.put("name", "xy");
    209208        relation.put("existing", "existing");
  • trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java

    r12718 r12726  
    22package org.openstreetmap.josm.command;
    33
    4 import static org.junit.Assert.assertSame;
     4import java.util.Arrays;
    55
    6 import java.util.Arrays;
    7 import java.util.Collection;
    8 
    9 import org.junit.Before;
    106import org.junit.Rule;
    117import org.junit.Test;
     
    139import org.openstreetmap.josm.data.osm.DataSet;
    1410import org.openstreetmap.josm.data.osm.Node;
    15 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1611import org.openstreetmap.josm.data.osm.Relation;
    1712import org.openstreetmap.josm.data.osm.RelationMember;
     
    3732    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3833    public JOSMTestRules test = new JOSMTestRules().preferences().i18n();
    39     private CommandTestData testData;
    40 
    41     /**
    42      * Set up the test data.
    43      */
    44     @Before
    45     public void createTestData() {
    46         testData = new CommandTestData();
    47     }
    48 
    49     /**
    50      * Test {@link Command#getLayer()}
    51      * @deprecated to be removed end of 2017
    52      */
    53     @Test
    54     @Deprecated
    55     public void testGetLayer() {
    56         OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null);
    57         Command command = new NopCommand();
    58         Command command2 = new NopCommand(layer2.data);
    59         assertSame(testData.layer, command.getLayer());
    60         assertSame(layer2, command2.getLayer());
    61     }
    6234
    6335    /**
     
    7547            .suppress(Warning.NONFINAL_FIELDS)
    7648            .verify();
    77     }
    78 
    79     private static final class NopCommand extends Command {
    80         NopCommand() {
    81             super();
    82         }
    83 
    84         NopCommand(DataSet dataset) {
    85             super(dataset);
    86         }
    87 
    88         @Override
    89         public String getDescriptionText() {
    90             return "";
    91         }
    92 
    93         @Override
    94         public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
    95                 Collection<OsmPrimitive> added) {
    96             // nop
    97         }
    9849    }
    9950
  • trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java

    r10775 r12726  
    1111import java.util.Collection;
    1212import java.util.List;
     13import java.util.NoSuchElementException;
    1314
    1415import org.junit.Before;
     
    113114     */
    114115    @Test
    115     public void testDelteNodesInWay() {
     116    public void testDeleteNodesInWay() {
    116117        testData.existingNode.removeAll();
    117118        // That untagged node should be deleted.
    118119        testData.existingNode2.removeAll();
    119         DeleteCommand.delete(testData.layer, Arrays.asList(testData.existingWay), true, true).executeCommand();
     120        DeleteCommand.delete(Arrays.asList(testData.existingWay), true, true).executeCommand();
    120121
    121122        assertTrue(testData.existingWay.isDeleted());
     
    137138        way2.setNodes(Arrays.asList(node2, node3, node4));
    138139        testData.layer.data.addPrimitive(way2);
    139         DeleteCommand.delete(testData.layer, Arrays.asList(way1, way2), true, true).executeCommand();
     140        DeleteCommand.delete(Arrays.asList(way1, way2), true, true).executeCommand();
    140141
    141142        assertTrue(way1.isDeleted());
     
    167168     * Test that {@link DeleteCommand} checks for non-empty list
    168169     */
    169     @Test(expected = IllegalArgumentException.class)
     170    @Test(expected = NoSuchElementException.class)
    170171    public void testConsistencyNonEmpty() {
    171172        new DeleteCommand(Arrays.<OsmPrimitive>asList());
     
    175176     * Test that {@link DeleteCommand} checks for non-null list
    176177     */
    177     @Test(expected = IllegalArgumentException.class)
     178    @Test(expected = NullPointerException.class)
    178179    public void testConsistencyNonNull() {
    179180        new DeleteCommand((Collection<OsmPrimitive>) null);
  • trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java

    r10758 r12726  
    248248        Node node = new Node(LatLon.ZERO);
    249249        node.put("name", "xy");
    250 
     250        new DataSet(node);
    251251        List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node);
    252252        assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node"));
  • trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java

    r10758 r12726  
    5555        Node n2 = new Node(new EastNorth(-1, 0));
    5656        Node n3 = new Node(new EastNorth(-9, -10));
     57        new DataSet(n1, n2, n3);
    5758        RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    5859        rotate.setRotationAngle(Math.PI / 4);
     
    7374        Node n2 = new Node(new EastNorth(-1, 0));
    7475        Node n3 = new Node(new EastNorth(-9, -10));
     76        new DataSet(n1, n2, n3);
    7577        RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    7678        rotate.setRotationAngle(Math.PI / 4);
  • trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java

    r10758 r12726  
    5555        Node n2 = new Node(new EastNorth(-1, 0));
    5656        Node n3 = new Node(new EastNorth(-9, -10));
     57        new DataSet(n1, n2, n3);
    5758        ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    5859        scale.setScalingFactor(2.5);
     
    7374        Node n2 = new Node(new EastNorth(-1, 0));
    7475        Node n3 = new Node(new EastNorth(-9, -10));
     76        new DataSet(n1, n2, n3);
    7577        ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    7678        scale.setScalingFactor(2.5);
  • trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java

    r12368 r12726  
    5050    @Test
    5151    public void testExecute() {
    52         SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay));
     52        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay));
    5353
    5454        testData.layer.data.setSelected(Arrays.asList(testData.existingNode2));
     
    6767    public void testExecuteAfterModify() {
    6868        List<OsmPrimitive> list = new ArrayList<>(Arrays.asList(testData.existingNode, testData.existingWay));
    69         SelectCommand command = new SelectCommand(list);
     69        SelectCommand command = new SelectCommand(testData.layer.data, list);
    7070
    7171        list.remove(testData.existingNode);
     
    8484    @Test
    8585    public void testUndo() {
    86         SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay));
     86        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay));
    8787        testData.layer.data.setSelected(Arrays.asList(testData.existingNode2));
    8888
     
    110110        ArrayList<OsmPrimitive> deleted = new ArrayList<>();
    111111        ArrayList<OsmPrimitive> added = new ArrayList<>();
    112         SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay));
     112        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay));
    113113        command.fillModifiedData(modified, deleted, added);
    114114        // intentionally empty.
     
    123123    @Test
    124124    public void testGetParticipatingPrimitives() {
    125         SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode));
     125        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode));
    126126        command.executeCommand();
    127127        assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray());
     
    133133    @Test
    134134    public void testDescription() {
    135         assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList(testData.existingNode))
     135        DataSet ds = testData.layer.data;
     136        assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode))
    136137                .getDescriptionText().matches("Selected 1 object"));
    137         assertTrue(new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay))
     138        assertTrue(new SelectCommand(ds, Arrays.asList(testData.existingNode, testData.existingWay))
    138139                .getDescriptionText().matches("Selected 2 objects"));
    139         assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList())
     140        assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList())
    140141                .getDescriptionText().matches("Selected 0 objects"));
    141         assertTrue(new SelectCommand(null)
     142        assertTrue(new SelectCommand(ds, null)
    142143                .getDescriptionText().matches("Selected 0 objects"));
    143144    }
  • trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java

    r11874 r12726  
    1212import java.util.Arrays;
    1313import java.util.Collection;
     14import java.util.Collections;
    1415
    1516import org.junit.Before;
     
    5455    @Test
    5556    public void testExecute() {
    56         final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
    57         TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)) {
     57        DataSet ds = new DataSet();
     58        final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
     59        TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)) {
    5860            @Override
    5961            public boolean executeCommand() {
     
    7577    @Test
    7678    public void testUndo() {
    77         final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
    78         TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) {
     79        DataSet ds = new DataSet();
     80        final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
     81        TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)) {
    7982            @Override
    8083            public void undoCommand() {
     
    103106    @Test
    104107    public void testExecuteRollback() {
    105         TestCommand command1 = new TestCommand(null);
    106         FailingCommand command2 = new FailingCommand();
    107         TestCommand command3 = new TestCommand(null);
     108        DataSet ds = new DataSet();
     109        TestCommand command1 = new TestCommand(ds, null);
     110        FailingCommand command2 = new FailingCommand(ds);
     111        TestCommand command3 = new TestCommand(ds, null);
    108112        SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3));
    109113        assertFalse(command.executeCommand());
     
    119123    @Test
    120124    public void testContinueOnErrors() {
    121         TestCommand command1 = new TestCommand(null);
    122         FailingCommand command2 = new FailingCommand();
    123         TestCommand command3 = new TestCommand(null);
     125        DataSet ds = new DataSet();
     126        TestCommand command1 = new TestCommand(ds, null);
     127        FailingCommand command2 = new FailingCommand(ds);
     128        TestCommand command3 = new TestCommand(ds, null);
    124129        SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3), true);
    125130        assertTrue(command.executeCommand());
     
    137142    @Test
    138143    public void testGetLastCommand() {
    139         final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
    140         final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
    141 
    142         assertEquals(command2, new SequenceCommand("seq", command1, command2).getLastCommand());
    143         assertNull(new SequenceCommand("seq").getLastCommand());
     144        DataSet ds = new DataSet();
     145        final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
     146        final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
     147
     148        assertEquals(command2, new SequenceCommand(ds, "seq", Arrays.asList(command1, command2), false).getLastCommand());
     149        assertNull(new SequenceCommand(ds, "seq", Collections.emptyList(), false).getLastCommand());
    144150    }
    145151
     
    149155    @Test
    150156    public void testFillModifiedData() {
    151         Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
    152         Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
    153         Command command3 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingWay)) {
     157        DataSet ds = new DataSet();
     158        Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
     159        Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
     160        Command command3 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingWay)) {
    154161            @Override
    155162            public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
     
    158165            }
    159166        };
    160         Command command4 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingRelation)) {
     167        Command command4 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingRelation)) {
    161168            @Override
    162169            public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
     
    181188    @Test
    182189    public void testGetParticipatingPrimitives() {
    183         Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
    184         Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
     190        DataSet ds = new DataSet();
     191        Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
     192        Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
    185193
    186194        SequenceCommand command = new SequenceCommand("seq", command1, command2);
     
    197205    @Test
    198206    public void testDescription() {
    199         assertTrue(new SequenceCommand("test").getDescriptionText().matches("Sequence: test"));
     207        assertTrue(new SequenceCommand(new DataSet(), "test", Collections.emptyList(), false).getDescriptionText().matches("Sequence: test"));
    200208    }
    201209
     
    205213    @Test
    206214    public void testEqualsContract() {
     215        DataSet ds = new DataSet();
    207216        EqualsVerifier.forClass(SequenceCommand.class).usingGetClass()
    208217            .withPrefabValues(Command.class,
    209                 new AddCommand(new Node(1)), new AddCommand(new Node(2)))
     218                new AddCommand(ds, new Node(1)), new AddCommand(ds, new Node(2)))
    210219            .withPrefabValues(DataSet.class,
    211220                    new DataSet(), new DataSet())
     
    222231        protected boolean executed;
    223232
    224         TestCommand(Collection<? extends OsmPrimitive> primitives) {
    225             super();
     233        TestCommand(DataSet ds, Collection<? extends OsmPrimitive> primitives) {
     234            super(ds);
    226235            this.primitives = primitives;
    227236        }
     
    266275    private static class FailingCommand extends TestCommand {
    267276
    268         FailingCommand() {
    269             super(null);
     277        FailingCommand(DataSet ds) {
     278            super(ds, null);
    270279        }
    271280
     
    286295            return "FailingCommand";
    287296        }
    288 
    289     }
    290 
     297    }
    291298}
  • trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java

    r12672 r12726  
    66import static org.junit.Assert.assertTrue;
    77
    8 import org.junit.After;
    98import org.junit.Before;
    109import org.junit.Rule;
    1110import org.junit.Test;
     11import org.openstreetmap.josm.command.CommandTest.CommandTestData;
    1212import org.openstreetmap.josm.data.conflict.Conflict;
    1313import org.openstreetmap.josm.data.osm.DataSet;
     
    1515import org.openstreetmap.josm.data.osm.User;
    1616import org.openstreetmap.josm.data.osm.Way;
    17 import org.openstreetmap.josm.gui.MainApplication;
    1817import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1918import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    2827public class ConflictAddCommandTest {
    2928
    30     private OsmDataLayer layer;
    31 
    3229    /**
    3330     * Setup test.
     
    3633    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3734    public JOSMTestRules test = new JOSMTestRules().platform();
     35    private CommandTestData testData;
    3836
    3937    /**
     
    4240    @Before
    4341    public void setUp() {
    44         layer = new OsmDataLayer(new DataSet(), null, null);
    45         MainApplication.getLayerManager().addLayer(layer);
    46     }
    47 
    48     /**
    49      * Cleanup test resources.
    50      */
    51     @After
    52     public void tearDown() {
    53         MainApplication.getLayerManager().removeLayer(layer);
     42        testData = new CommandTestData();
    5443    }
    5544
     
    5948    @Test
    6049    public void testExecuteUndoCommand() {
    61         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    62         Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
     50        DataSet ds = testData.layer.data;
     51        Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2);
    6352        ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict);
    6453        assertTrue(cmd.executeCommand());
     
    7564    @Test
    7665    public void testGetDescriptionIcon() {
    77         OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    78         Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
    79         assertNotNull(new ConflictAddCommand(layer, conflict).getDescriptionIcon());
     66        Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2);
     67        assertNotNull(new ConflictAddCommand(testData.layer.data, conflict).getDescriptionIcon());
    8068    }
    8169
  • trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java

    r12636 r12726  
    66import static org.junit.Assert.assertTrue;
    77
    8 import org.junit.After;
    98import org.junit.Before;
    109import org.junit.Rule;
    1110import org.junit.Test;
     11import org.openstreetmap.josm.command.CommandTest.CommandTestData;
    1212import org.openstreetmap.josm.data.conflict.Conflict;
    1313import org.openstreetmap.josm.data.coor.LatLon;
     
    1616import org.openstreetmap.josm.data.osm.User;
    1717import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.gui.MainApplication;
    1918import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    3029public class CoordinateConflictResolveCommandTest {
    3130
    32     private OsmDataLayer layer;
     31    private CommandTestData testData;
    3332
    3433    /**
     
    4443    @Before
    4544    public void setUp() {
    46         layer = new OsmDataLayer(new DataSet(), null, null);
    47         MainApplication.getLayerManager().addLayer(layer);
     45        testData = new CommandTestData();
    4846    }
    4947
    50     /**
    51      * Cleanup test resources.
    52      */
    53     @After
    54     public void tearDown() {
    55         MainApplication.getLayerManager().removeLayer(layer);
    56     }
    57 
    58     private static Conflict<Node> createConflict() {
    59         return new Conflict<>(new Node(LatLon.ZERO), new Node(new LatLon(50, 50)));
     48    private Conflict<Node> createConflict() {
     49        return new Conflict<>(testData.existingNode, testData.existingNode2);
    6050    }
    6151
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r12620 r12726  
    2525import org.openstreetmap.josm.command.PseudoCommand;
    2626import org.openstreetmap.josm.command.SequenceCommand;
    27 import org.openstreetmap.josm.data.osm.Node;
     27import org.openstreetmap.josm.data.osm.DataSet;
    2828import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2929import org.openstreetmap.josm.data.osm.OsmUtils;
     
    8282        assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString());
    8383        assertEquals("fixAdd: wetland=marsh", check.fixCommands.get(2).toString());
    84         final Node n1 = new Node();
    85         n1.put("natural", "marsh");
     84        final OsmPrimitive n1 = OsmUtils.createPrimitive("node natural=marsh");
     85        final OsmPrimitive n2 = OsmUtils.createPrimitive("node natural=wood");
     86        new DataSet(n1, n2);
    8687        assertTrue(check.test(n1));
    8788        assertEquals("deprecated", check.getErrorForPrimitive(n1).getMessage());
     
    9091        assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText());
    9192        assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString());
    92         final Node n2 = new Node();
    93         n2.put("natural", "wood");
    9493        assertFalse(check.test(n2));
    9594        assertEquals("The key is natural and the value is marsh",
     
    109108                "fixAdd: \"highway=construction\";\n" +
    110109                "}")).parseChecks.get(0);
     110        new DataSet(p);
    111111        final Command command = check.fixPrimitive(p);
    112112        assertTrue(command instanceof SequenceCommand);
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java

    r11102 r12726  
    55import static org.junit.Assert.assertNotNull;
    66
     7import java.util.NoSuchElementException;
     8
    79import org.junit.Rule;
    810import org.junit.Test;
     
    1012import org.openstreetmap.josm.data.conflict.Conflict;
    1113import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1215import org.openstreetmap.josm.data.osm.Node;
    1316import org.openstreetmap.josm.data.osm.Relation;
     
    3235     * Unit test of {@link ConflictResolver#buildResolveCommand} - empty case.
    3336     */
    34     @Test
     37    @Test(expected = NoSuchElementException.class)
    3538    public void testBuildResolveCommandEmpty() {
    3639        assertNotNull(new ConflictResolver().buildResolveCommand());
     
    4750        Node n2 = new Node(LatLon.NORTH_POLE);
    4851        n2.put("source", "theirs");
     52        new DataSet(n1, n2);
    4953        resolver.populate(new Conflict<>(n1, n2));
    5054        resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
     
    6266        Way w2 = new Way();
    6367        w2.put("source", "theirs");
     68        new DataSet(w1, w2);
    6469        resolver.populate(new Conflict<>(w1, w2));
    6570        resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
     
    7782        Relation r2 = new Relation();
    7883        r2.put("source", "theirs");
     84        new DataSet(r1, r2);
    7985        resolver.populate(new Conflict<>(r1, r2));
    8086        resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
  • trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java

    r12564 r12726  
    6464    public void testPasteTags() {
    6565        Node n = new Node(LatLon.ZERO);
     66        new DataSet(n);
    6667
    6768        ClipboardUtils.copyString("test=ok");
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java

    r12641 r12726  
    4646    @Test
    4747    public void testCommandStackDialogNotEmpty() {
    48         OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
     48        DataSet ds = new DataSet();
     49        OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    4950        MainApplication.getLayerManager().addLayer(layer);
    5051        try {
    51             Command cmd1 = TestUtils.newCommand();
    52             Command cmd2 = TestUtils.newCommand();
     52            Command cmd1 = TestUtils.newCommand(ds);
     53            Command cmd2 = TestUtils.newCommand(ds);
    5354            MainApplication.undoRedo.add(cmd1);
    5455            MainApplication.undoRedo.add(cmd2);
Note: See TracChangeset for help on using the changeset viewer.