Changeset 12069 in josm for trunk/test/unit


Ignore:
Timestamp:
2017-05-06T14:10:40+02:00 (3 years ago)
Author:
michael2402
Message:

Fix #14737: Preserve selection order and add comments that it is ordered. Add unit tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java

    r12036 r12069  
    55import static org.junit.Assert.assertTrue;
    66
     7import java.util.ArrayList;
    78import java.util.Arrays;
    89import java.util.HashSet;
     
    124125        ds.unlinkNodeFromWays(n2);
    125126    }
     127
     128    /**
     129     * Test the selection order.
     130     * See <a href="https://josm.openstreetmap.de/ticket/14737">#14737</a>
     131     * @since 12069
     132     */
     133    @Test
     134    public void testSelectionOrderPreserved() {
     135        final DataSet ds = new DataSet();
     136        Node n1 = new Node(1);
     137        Node n2 = new Node(2);
     138        Node n3 = new Node(3);
     139        ds.addPrimitive(n1);
     140        ds.addPrimitive(n2);
     141        ds.addPrimitive(n3);
     142
     143        assertEquals(Arrays.asList(), new ArrayList<>(ds.getSelected()));
     144
     145        ds.setSelected(n1.getPrimitiveId(), n2.getPrimitiveId());
     146        assertEquals(Arrays.asList(n1, n2), new ArrayList<>(ds.getSelected()));
     147
     148        ds.clearSelection();
     149        assertEquals(Arrays.asList(), new ArrayList<>(ds.getSelected()));
     150
     151        ds.addSelected(n3.getPrimitiveId());
     152        ds.addSelected(n1.getPrimitiveId(), n2.getPrimitiveId());
     153        assertEquals(Arrays.asList(n3, n1, n2), new ArrayList<>(ds.getSelected()));
     154
     155        ds.addSelected(n3.getPrimitiveId());
     156        assertEquals(Arrays.asList(n3, n1, n2), new ArrayList<>(ds.getSelected()));
     157
     158        ds.clearSelection(n1.getPrimitiveId());
     159        assertEquals(Arrays.asList(n3, n2), new ArrayList<>(ds.getSelected()));
     160
     161        ds.toggleSelected(n1.getPrimitiveId());
     162        assertEquals(Arrays.asList(n3, n2, n1), new ArrayList<>(ds.getSelected()));
     163
     164        ds.toggleSelected(n2.getPrimitiveId());
     165        assertEquals(Arrays.asList(n3, n1), new ArrayList<>(ds.getSelected()));
     166
     167    }
    126168}
Note: See TracChangeset for help on using the changeset viewer.