Changeset 9203 in josm for trunk/test
- Timestamp:
- 2015-12-28T19:15:45+01:00 (9 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data/osm/history
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/osm/history/HistoryNodeTest.java
r8857 r9203 6 6 7 7 import java.util.Date; 8 import java.util.HashMap; 9 import java.util.Map; 8 10 11 import org.junit.BeforeClass; 9 12 import org.junit.Test; 13 import org.openstreetmap.josm.JOSMFixture; 10 14 import org.openstreetmap.josm.data.coor.LatLon; 15 import org.openstreetmap.josm.data.osm.Node; 11 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 17 import org.openstreetmap.josm.data.osm.User; 18 import org.openstreetmap.josm.gui.DefaultNameFormatter; 13 19 14 20 /** … … 17 23 public class HistoryNodeTest { 18 24 19 @Test 20 public void historyNode() { 21 Date d = new Date(); 22 HistoryNode node = new HistoryNode( 23 1L, 24 2L, 25 true, 25 /** 26 * Setup test. 27 */ 28 @BeforeClass 29 public static void init() { 30 JOSMFixture.createUnitTestFixture().init(); 31 } 32 33 private static HistoryNode create(Date d) { 34 return new HistoryNode( 35 1L, // id 36 2L, // version 37 true, // visible 26 38 User.createOsmUser(3, "testuser"), 27 4L, 28 d, 39 4L, // changesetId 40 d, // timestamp 29 41 new LatLon(0, 0) 30 42 ); 43 } 44 45 /** 46 * Unit test for {@link HistoryNode#HistoryNode}. 47 */ 48 @Test 49 public void testHistoryNode() { 50 Date d = new Date(); 51 HistoryNode node = create(d); 31 52 32 53 assertEquals(1, node.getId()); … … 39 60 } 40 61 62 /** 63 * Unit test for {@link HistoryNode#getType}. 64 */ 41 65 @Test 42 public void getType() { 43 Date d = new Date(); 44 HistoryNode node = new HistoryNode( 45 1, 46 2, 47 true, 48 User.createOsmUser(3, "testuser"), 49 4, 50 d, 51 new LatLon(0, 0) 52 ); 66 public void testGetType() { 67 assertEquals(OsmPrimitiveType.NODE, create(new Date()).getType()); 68 } 53 69 54 assertEquals(OsmPrimitiveType.NODE, node.getType()); 70 /** 71 * Unit test for {@link HistoryNode#getCoords}. 72 */ 73 @Test 74 public void testGetCoords() { 75 Node n = new Node(new LatLon(45, 0)); 76 n.setOsmId(1, 2); 77 n.setUser(User.createOsmUser(3, "testuser")); 78 n.setChangesetId(4); 79 assertEquals(n.getCoor(), new HistoryNode(n).getCoords()); 80 } 81 82 /** 83 * Unit test for {@link HistoryNode#getDisplayName}. 84 */ 85 @Test 86 public void testGetDisplayName() { 87 HistoryNode node = create(new Date()); 88 HistoryNameFormatter hnf = DefaultNameFormatter.getInstance(); 89 assertEquals("1 (0.0, 0.0)", node.getDisplayName(hnf)); 90 LatLon ll = node.getCoords(); 91 node.setCoords(null); 92 assertEquals("1", node.getDisplayName(hnf)); 93 node.setCoords(ll); 94 Map<String, String> map = new HashMap<>(); 95 map.put("name", "NodeName"); 96 node.setTags(map); 97 assertEquals("NodeName (0.0, 0.0)", node.getDisplayName(hnf)); 98 node.setCoords(null); 99 assertEquals("NodeName", node.getDisplayName(hnf)); 55 100 } 56 101 } -
trunk/test/unit/org/openstreetmap/josm/data/osm/history/HistoryWayTest.java
r8857 r9203 8 8 import java.util.ArrayList; 9 9 import java.util.Date; 10 import java.util.HashMap; 11 import java.util.Map; 10 12 13 import org.junit.BeforeClass; 11 14 import org.junit.Test; 15 import org.openstreetmap.josm.JOSMFixture; 12 16 import org.openstreetmap.josm.Main; 13 17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 18 import org.openstreetmap.josm.data.osm.User; 19 import org.openstreetmap.josm.gui.DefaultNameFormatter; 15 20 16 21 /** … … 19 24 public class HistoryWayTest { 20 25 26 /** 27 * Setup test. 28 */ 29 @BeforeClass 30 public static void init() { 31 JOSMFixture.createUnitTestFixture().init(); 32 } 33 34 private static HistoryWay create(Date d) { 35 return new HistoryWay( 36 1, // id 37 2, // version 38 true, // visible 39 User.createOsmUser(3, "testuser"), 40 4, // changesetId 41 d // timestamp 42 ); 43 } 44 45 /** 46 * Unit test for {@link HistoryWay#HistoryWay}. 47 */ 21 48 @Test 22 public void wayTest() {49 public void testHistoryWay() { 23 50 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 ); 51 HistoryWay way = create(d); 32 52 33 53 assertEquals(1, way.getId()); … … 42 62 } 43 63 64 /** 65 * Unit test for {@link HistoryWay#getType}. 66 */ 44 67 @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()); 68 public void testGetType() { 69 assertEquals(OsmPrimitiveType.WAY, create(new Date()).getType()); 57 70 } 58 71 59 72 @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 ); 73 public void testNodeManipulation() { 74 HistoryWay way = create(new Date()); 70 75 71 76 way.addNode(1); … … 88 93 89 94 @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 ); 95 public void testIterating() { 96 HistoryWay way = create(new Date()); 100 97 101 98 way.addNode(1); … … 110 107 assertEquals(2, (long) ids.get(1)); 111 108 } 109 110 /** 111 * Unit test for {@link HistoryWay#getDisplayName}. 112 */ 113 @Test 114 public void testGetDisplayName() { 115 HistoryNameFormatter hnf = DefaultNameFormatter.getInstance(); 116 HistoryWay way0 = create(new Date()); // no node 117 HistoryWay way1 = create(new Date()); // 1 node 118 HistoryWay way2 = create(new Date()); // 2 nodes 119 120 way1.addNode(1); 121 way2.addNode(1); 122 way2.addNode(2); 123 124 assertEquals("1 (0 nodes)", way0.getDisplayName(hnf)); 125 assertEquals("1 (1 node)", way1.getDisplayName(hnf)); 126 assertEquals("1 (2 nodes)", way2.getDisplayName(hnf)); 127 128 Map<String, String> map = new HashMap<>(); 129 map.put("name", "WayName"); 130 131 way0.setTags(map); 132 way1.setTags(map); 133 way2.setTags(map); 134 135 assertEquals("WayName (0 nodes)", way0.getDisplayName(hnf)); 136 assertEquals("WayName (1 node)", way1.getDisplayName(hnf)); 137 assertEquals("WayName (2 nodes)", way2.getDisplayName(hnf)); 138 } 112 139 }
Note:
See TracChangeset
for help on using the changeset viewer.