1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertArrayEquals;
|
---|
5 |
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.Arrays;
|
---|
8 | import java.util.Collections;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.data.osm.NodeData;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Unit tests of {@link OsmWriter} class.
|
---|
16 | */
|
---|
17 | public class OsmWriterTest {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit test of {@link OsmWriter#byIdComparator}.
|
---|
21 | */
|
---|
22 | @Test
|
---|
23 | public void testByIdComparator() {
|
---|
24 |
|
---|
25 | final List<NodeData> ids = new ArrayList<>();
|
---|
26 | for (Long id : Arrays.asList(12L, Long.MIN_VALUE, 65L, -12L, 2L, 0L, -3L, -20L, Long.MAX_VALUE)) {
|
---|
27 | final NodeData n = new NodeData();
|
---|
28 | n.setId(id);
|
---|
29 | ids.add(n);
|
---|
30 | }
|
---|
31 |
|
---|
32 | Collections.sort(ids, OsmWriter.byIdComparator);
|
---|
33 |
|
---|
34 | final long[] longIds = ids.stream().mapToLong(NodeData::getUniqueId).toArray();
|
---|
35 | assertArrayEquals(new long[] {
|
---|
36 | -3, -12, -20, -9223372036854775808L, 0, 2, 12, 65, 9223372036854775807L
|
---|
37 | }, longIds);
|
---|
38 | }
|
---|
39 | }
|
---|