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

Last change on this file since 8857 was 8857, checked in by Don-vip, 9 years ago

improve/cleanup unit tests

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