source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/history/HistoryWayTest.java@ 4603

Last change on this file since 4603 was 4603, checked in by jttt, 12 years ago

Fix tests

File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.history;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.fail;
6
7import java.util.ArrayList;
8import java.util.Date;
9
10import org.junit.Test;
11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
12import org.openstreetmap.josm.data.osm.User;
13
14public class HistoryWayTest {
15
16 @Test
17 public void wayTest() {
18 Date d = new Date();
19 HistoryWay way = new HistoryWay(
20 1,
21 2,
22 true,
23 User.createOsmUser(3, "testuser"),
24 4,
25 d
26 );
27
28 assertEquals(1, way.getId());
29 assertEquals(2, way.getVersion());
30 assertEquals(true, way.isVisible());
31 assertEquals("testuser", way.getUser().getName());
32 assertEquals(3, way.getUser().getId());
33 assertEquals(4, way.getChangesetId());
34 assertEquals(d, way.getTimestamp());
35
36 assertEquals(0, way.getNumNodes());
37 }
38
39 @Test
40 public void getType() {
41 Date d = new Date();
42 HistoryWay way = new HistoryWay(
43 1,
44 2,
45 true,
46 User.createOsmUser(3, "testuser"),
47 4,
48 d
49 );
50
51 assertEquals(OsmPrimitiveType.WAY, way.getType());
52 }
53
54 @Test
55 public void nodeManipulation() {
56 Date d = new Date();
57 HistoryWay way = new HistoryWay(
58 1,
59 2,
60 true,
61 User.createOsmUser(3, "testuser"),
62 4,
63 d
64 );
65
66 way.addNode(1);
67 assertEquals(1, way.getNumNodes());
68 assertEquals(1, way.getNodeId(0));
69 try {
70 way.getNodeId(1);
71 fail("expected expection of type " + IndexOutOfBoundsException.class.toString());
72 } catch(IndexOutOfBoundsException e) {
73 // OK
74 }
75
76 way.addNode(5);
77 assertEquals(2, way.getNumNodes());
78 assertEquals(5, way.getNodeId(1));
79 }
80
81 @Test
82 public void iterating() {
83 Date d = new Date();
84 HistoryWay way = new HistoryWay(
85 1,
86 2,
87 true,
88 User.createOsmUser(3, "testuser"),
89 4,
90 d
91 );
92
93 way.addNode(1);
94 way.addNode(2);
95 ArrayList<Long> ids = new ArrayList<Long>();
96 for (long id : way.getNodes()) {
97 ids.add(id);
98 }
99
100 assertEquals(2, ids.size());
101 assertEquals(1, (long) ids.get(0));
102 assertEquals(2, (long) ids.get(1));
103 }
104
105}
Note: See TracBrowser for help on using the repository browser.