Ignore:
Timestamp:
2016-07-28T01:24:39+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13223 - Minor command class fixes (patch by michael2402, modified) - gsoc-core

File:
1 edited

Legend:

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

    r9943 r10663  
    22package org.openstreetmap.josm.command;
    33
    4 import org.junit.BeforeClass;
     4import static org.junit.Assert.assertArrayEquals;
     5import static org.junit.Assert.assertEquals;
     6import static org.junit.Assert.assertFalse;
     7import static org.junit.Assert.assertTrue;
     8
     9import java.util.ArrayList;
     10import java.util.Arrays;
     11import java.util.Collections;
     12import java.util.List;
     13
     14import org.junit.Before;
     15import org.junit.Rule;
    516import org.junit.Test;
    6 import org.openstreetmap.josm.JOSMFixture;
     17import org.openstreetmap.josm.command.CommandTest.CommandTestData;
     18import org.openstreetmap.josm.data.coor.LatLon;
    719import org.openstreetmap.josm.data.osm.DataSet;
     20import org.openstreetmap.josm.data.osm.Node;
     21import org.openstreetmap.josm.data.osm.OsmPrimitive;
    822import org.openstreetmap.josm.data.osm.User;
    923import org.openstreetmap.josm.data.osm.Way;
    1024import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     25import org.openstreetmap.josm.testutils.JOSMTestRules;
    1126
     27import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1228import nl.jqno.equalsverifier.EqualsVerifier;
    1329import nl.jqno.equalsverifier.Warning;
     
    1935
    2036    /**
    21      * Setup test.
     37     * We need prefs for nodes.
    2238     */
    23     @BeforeClass
    24     public static void setUpBeforeClass() {
    25         JOSMFixture.createUnitTestFixture().init(false);
     39    @Rule
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     41    public JOSMTestRules test = new JOSMTestRules().preferences().i18n();
     42    private CommandTestData testData;
     43
     44    /**
     45     * Set up the test data.
     46     */
     47    @Before
     48    public void createTestData() {
     49        testData = new CommandTestData();
     50    }
     51
     52    /**
     53     * Test that empty ways are prevented.
     54     */
     55    @Test(expected = IllegalArgumentException.class)
     56    public void testPreventEmptyWays() {
     57        new ChangeNodesCommand(testData.existingWay, Collections.<Node>emptyList());
     58    }
     59
     60    /**
     61     * Test {@link ChangeNodesCommand#executeCommand()}
     62     */
     63    @Test
     64    public void testChange() {
     65        List<Node> newNodes = testData.existingWay.getNodes();
     66        Collections.reverse(newNodes);
     67
     68        new ChangeNodesCommand(testData.existingWay, newNodes).executeCommand();
     69        assertArrayEquals(newNodes.toArray(), testData.existingWay.getNodes().toArray());
     70
     71        // tags are unchanged
     72        assertEquals("existing", testData.existingWay.get("existing"));
     73        assertTrue(testData.existingWay.isModified());
     74    }
     75
     76    /**
     77     * Test {@link ChangeCommand#undoCommand()}
     78     */
     79    @Test
     80    public void testUndo() {
     81        List<Node> newNodes = testData.existingWay.getNodes();
     82        Collections.reverse(newNodes);
     83
     84        ChangeNodesCommand command = new ChangeNodesCommand(testData.existingWay, newNodes);
     85        command.executeCommand();
     86        command.undoCommand();
     87        Collections.reverse(newNodes);
     88        assertArrayEquals(newNodes.toArray(), testData.existingWay.getNodes().toArray());
     89        assertFalse(testData.existingWay.isModified());
     90    }
     91
     92    /**
     93     * Tests {@link ChangeNodesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)}
     94     */
     95    @Test
     96    public void testFillModifiedData() {
     97        ArrayList<OsmPrimitive> modified = new ArrayList<>();
     98        ArrayList<OsmPrimitive> deleted = new ArrayList<>();
     99        ArrayList<OsmPrimitive> added = new ArrayList<>();
     100        new ChangeNodesCommand(testData.existingWay, Arrays.asList(testData.existingNode)).fillModifiedData(modified,
     101                deleted, added);
     102        assertArrayEquals(new Object[] {testData.existingWay}, modified.toArray());
     103        assertArrayEquals(new Object[] {}, deleted.toArray());
     104        assertArrayEquals(new Object[] {}, added.toArray());
     105    }
     106
     107    /**
     108     * Test {@link ChangeNodesCommand#getDescriptionText()}
     109     */
     110    @Test
     111    public void testDescription() {
     112        Node node = new Node(LatLon.ZERO);
     113        node.put("name", "xy");
     114        Way way = new Way();
     115        way.addNode(node);
     116        way.put("name", "xy");
     117
     118        assertTrue(
     119                new ChangeNodesCommand(way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));
    26120    }
    27121
Note: See TracChangeset for help on using the changeset viewer.