Changeset 32925 in osm for applications/editors/josm/plugins/turnrestrictions
- Timestamp:
- 2016-09-04T13:24:24+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions
- Files:
-
- 1 added
- 4 edited
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/.classpath
r32680 r32925 3 3 <classpathentry kind="src" path="src"/> 4 4 <classpathentry kind="src" path="test/unit"/> 5 <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>6 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 7 6 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 8 7 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 9 <classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>10 8 <classpathentry kind="output" path="build"/> 11 9 </classpath> -
applications/editors/josm/plugins/turnrestrictions/.project
r32519 r32925 23 23 </buildSpec> 24 24 <natures> 25 <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>26 25 <nature>org.eclipse.jdt.core.javanature</nature> 27 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeRenderer.java
r32519 r32925 21 21 public class TurnRestrictionTypeRenderer extends JLabel implements ListCellRenderer<Object> { 22 22 23 privatefinal Map<TurnRestrictionType, ImageIcon> icons = new HashMap<>();23 final Map<TurnRestrictionType, ImageIcon> icons = new HashMap<>(); 24 24 private String iconSet = "set-a"; 25 25 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceEditor.java
r32519 r32925 120 120 * Launches an external browser with the sponsors home page 121 121 */ 122 class SkobblerUrlLauncher extends MouseAdapter implements HyperlinkListener {122 static class SkobblerUrlLauncher extends MouseAdapter implements HyperlinkListener { 123 123 protected void launchBrowser() { 124 124 OpenBrowser.displayUrl("http://www.skobbler.de"); -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilderTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions; 2 3 3 import static org.junit.Assert.* 4 import static org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder.* 5 6 import org.junit.* 7 import org.openstreetmap.josm.data.coor.LatLon 8 import org.openstreetmap.josm.data.osm.Node 9 import org.openstreetmap.josm.data.osm.Relation 10 import org.openstreetmap.josm.data.osm.RelationMember 11 import org.openstreetmap.josm.data.osm.Way 12 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType 13 import org.openstreetmap.josm.testutils.JOSMTestRules 14 15 class TurnRestrictionBuilderTest{ 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNotNull; 7 import static org.junit.Assert.assertNull; 8 import static org.junit.Assert.assertTrue; 9 import static org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder.intersectionAngle; 10 import static org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder.selectToWayAfterSplit; 11 12 import java.util.ArrayList; 13 import java.util.Arrays; 14 import java.util.List; 15 import java.util.Optional; 16 17 import org.junit.Rule; 18 import org.junit.Test; 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.Relation; 23 import org.openstreetmap.josm.data.osm.RelationMember; 24 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder.RelativeWayJoinOrientation; 26 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType; 27 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 29 public class TurnRestrictionBuilderTest { 16 30 17 31 @Rule 18 32 public JOSMTestRules rules = new JOSMTestRules().preferences(); 19 33 20 def TurnRestrictionBuilder builder = new TurnRestrictionBuilder(); 21 22 def boolean hasExactlyOneMemberWithRole(Relation r, String role ){ 23 return r.getMembers().find {RelationMember rm -> rm.getRole() == role} != null 24 } 25 26 def memberWithRole(Relation r, String role) { 27 def RelationMember rm = r.getMembers().find {RelationMember rm -> rm.getRole() == role} 28 return rm.getMember() 29 } 30 31 def void assertEmptyTurnRestriction(Relation r){ 32 assert r != null 33 assert r.get("type") == "restriction" 34 assert r.getMembersCount() == 0 34 TurnRestrictionBuilder builder = new TurnRestrictionBuilder(); 35 36 boolean hasExactlyOneMemberWithRole(Relation r, final String role) { 37 return r.getMembers().stream().filter(rm -> role.equals(rm.getRole())).findFirst().isPresent(); 38 } 39 40 OsmPrimitive memberWithRole(Relation r, final String role) { 41 Optional<RelationMember> opt = r.getMembers().stream().filter(rm -> role.equals(rm.getRole())).findFirst(); 42 if (!opt.isPresent()) 43 return null; 44 return opt.get().getMember(); 45 } 46 47 static void assertEmptyTurnRestriction(Relation r) { 48 assertNotNull(r); 49 assertEquals("restriction", r.get("type")); 50 assertEquals(0, r.getMembersCount()); 35 51 } 36 52 … … 42 58 @Test 43 59 public void noUTurn_1() { 44 Way w = new Way(1) 45 Node n1 = new Node(1) 46 Node n2 = new Node(2) 47 w.setNodes([n1,n2]) 48 49 def sel = [w,n1] 50 TurnRestrictionBuilder builder = new TurnRestrictionBuilder() 51 Relation r = builder.build(sel) 52 53 assert r != null 54 assert r.getMembersCount() == 3 55 assert hasExactlyOneMemberWithRole(r, "from") 56 assert hasExactlyOneMemberWithRole(r, "to") 57 assert hasExactlyOneMemberWithRole(r, "via") 58 assert memberWithRole(r, "from") == w 59 assert memberWithRole(r, "to") == w 60 assert memberWithRole(r, "via") == n1 61 assert r.get("restriction") == "no_u_turn" 62 } 63 60 Way w = new Way(1); 61 Node n1 = new Node(1); 62 Node n2 = new Node(2); 63 w.setNodes(Arrays.asList(n1, n2)); 64 65 List<OsmPrimitive> sel = Arrays.asList(w, n1); 66 TurnRestrictionBuilder builder = new TurnRestrictionBuilder(); 67 Relation r = builder.build(sel); 68 69 assertNotNull(r); 70 assertEquals(3, r.getMembersCount()); 71 assertTrue(hasExactlyOneMemberWithRole(r, "from")); 72 assertTrue(hasExactlyOneMemberWithRole(r, "to")); 73 assertTrue(hasExactlyOneMemberWithRole(r, "via")); 74 assertEquals(w, memberWithRole(r, "from")); 75 assertEquals(w, memberWithRole(r, "to")); 76 assertEquals(n1, memberWithRole(r, "via")); 77 assertEquals("no_u_turn", r.get("restriction")); 78 } 64 79 65 80 /** … … 70 85 @Test 71 86 public void noUTurn_2() { 72 Way w = new Way(1) 73 Node n1 = new Node(1) 74 Node n2 = new Node(2) 75 w.setNodes( [n1,n2])76 77 def sel = [w,n2]78 TurnRestrictionBuilder builder = new TurnRestrictionBuilder() 79 Relation r = builder.build(sel) 80 81 assert r != null82 assert r.getMembersCount() == 383 assert hasExactlyOneMemberWithRole(r, "from")84 assert hasExactlyOneMemberWithRole(r, "to")85 assert hasExactlyOneMemberWithRole(r, "via")86 assert memberWithRole(r, "from") == w87 assert memberWithRole(r, "to") == w88 assert memberWithRole(r, "via") == n289 assert r.get("restriction") == "no_u_turn"87 Way w = new Way(1); 88 Node n1 = new Node(1); 89 Node n2 = new Node(2); 90 w.setNodes(Arrays.asList(n1, n2)); 91 92 List<OsmPrimitive> sel = Arrays.asList(w, n2); 93 TurnRestrictionBuilder builder = new TurnRestrictionBuilder(); 94 Relation r = builder.build(sel); 95 96 assertNotNull(r); 97 assertEquals(3, r.getMembersCount()); 98 assertTrue(hasExactlyOneMemberWithRole(r, "from")); 99 assertTrue(hasExactlyOneMemberWithRole(r, "to")); 100 assertTrue(hasExactlyOneMemberWithRole(r, "via")); 101 assertEquals(w, memberWithRole(r, "from")); 102 assertEquals(w, memberWithRole(r, "to")); 103 assertEquals(n2, memberWithRole(r, "via")); 104 assertEquals("no_u_turn", r.get("restriction")); 90 105 } 91 106 92 107 @Test 93 108 public void nullSelection() { 94 def tr = builder.build(null) 95 assertEmptyTurnRestriction(tr) 109 assertEmptyTurnRestriction(builder.build(null)); 96 110 } 97 111 98 112 @Test 99 113 public void emptySelection() { 100 def tr = builder.build([]) 101 assertEmptyTurnRestriction(tr) 114 assertEmptyTurnRestriction(builder.build(new ArrayList<>())); 102 115 } 103 116 … … 108 121 @Test 109 122 public void oneSelectedWay() { 110 Way w = new Way(1) 111 Relation tr = builder.build( [w])112 assert tr != null113 assert tr.get("type") == "restriction"114 assert tr.getMembersCount() == 1115 assert memberWithRole(tr, "from") == w123 Way w = new Way(1); 124 Relation tr = builder.build(Arrays.asList(w)); 125 assertNotNull(tr); 126 assertEquals("restriction", tr.get("type")); 127 assertEquals(1, tr.getMembersCount()); 128 assertEquals(w, memberWithRole(tr, "from")); 116 129 } 117 130 … … 122 135 @Test 123 136 public void twoUnconnectedWays() { 124 Way w1 = new Way(1) 125 w1.setNodes( [new Node(11), new Node(12)])126 Way w2 = new Way(2) 127 w2.setNodes( [new Node(21), new Node(22)])128 129 Relation tr = builder.build( [w1,w2])130 assert tr != null131 assert tr.get("type") == "restriction"132 assert ! tr.hasKey("restriction")133 assert tr.getMembersCount() == 2134 assert memberWithRole(tr, "from") == w1135 assert memberWithRole(tr, "to") == w2137 Way w1 = new Way(1); 138 w1.setNodes(Arrays.asList(new Node(11), new Node(12))); 139 Way w2 = new Way(2); 140 w2.setNodes(Arrays.asList(new Node(21), new Node(22))); 141 142 Relation tr = builder.build(Arrays.asList(w1, w2)); 143 assertNotNull(tr); 144 assertEquals("restriction", tr.get("type")); 145 assertFalse(tr.hasKey("restriction")); 146 assertEquals(2, tr.getMembersCount()); 147 assertEquals(w1, memberWithRole(tr, "from")); 148 assertEquals(w2, memberWithRole(tr, "to")); 136 149 } 137 150 … … 147 160 @Test 148 161 public void twoConnectedWays_1() { 149 Node n1 = new Node(1) 150 n1.setCoor(new LatLon(1, 1))151 Node n2 = new Node(2) 152 n2.setCoor(new LatLon(2, 1))153 Node n3 = new Node(3) 154 n3.setCoor(new LatLon(2, 2))155 156 Way w1 = new Way(1) 157 w1.setNodes( [n1,n2])158 Way w2 = new Way(2) 159 w2.setNodes( [n2,n3])160 161 assert builder.phi(w1) == Math.toRadians(90)162 assert builder.phi(w2) == Math.toRadians(0)163 164 Relation tr = builder.build( [w1,w2,n2])165 166 assert tr != null167 assert tr.get("type") == "restriction"168 assert tr.getMembersCount() == 3169 assert memberWithRole(tr, "from") == w1170 assert memberWithRole(tr, "to") == w2171 assert memberWithRole(tr, "via") == n2172 173 assert tr.get("restriction") == "no_right_turn"162 Node n1 = new Node(1); 163 n1.setCoor(new LatLon(1, 1)); 164 Node n2 = new Node(2); 165 n2.setCoor(new LatLon(2, 1)); 166 Node n3 = new Node(3); 167 n3.setCoor(new LatLon(2, 2)); 168 169 Way w1 = new Way(1); 170 w1.setNodes(Arrays.asList(n1, n2)); 171 Way w2 = new Way(2); 172 w2.setNodes(Arrays.asList(n2, n3)); 173 174 assertEquals(Math.toRadians(90), TurnRestrictionBuilder.phi(w1), 1e-7); 175 assertEquals(Math.toRadians(0), TurnRestrictionBuilder.phi(w2), 1e-7); 176 177 Relation tr = builder.build(Arrays.asList(w1, w2, n2)); 178 179 assertNotNull(tr); 180 assertEquals("restriction", tr.get("type")); 181 assertEquals(3, tr.getMembersCount()); 182 assertEquals(w1, memberWithRole(tr, "from")); 183 assertEquals(w2, memberWithRole(tr, "to")); 184 assertEquals(n2, memberWithRole(tr, "via")); 185 186 assertEquals("no_right_turn", tr.get("restriction")); 174 187 175 188 /* … … 177 190 */ 178 191 179 tr = builder.build( [w2,w1,n2])180 181 double a = intersectionAngle(w2, w1) 182 println "a=" + Math.toDegrees(a)183 184 assert tr != null185 assert tr.get("type") == "restriction"186 assert tr.getMembersCount() == 3187 assert memberWithRole(tr, "from") == w2188 assert memberWithRole(tr, "to") == w1189 assert memberWithRole(tr, "via") == n2190 191 assert tr.get("restriction") == "no_left_turn"192 tr = builder.build(Arrays.asList(w2, w1, n2)); 193 194 double a = intersectionAngle(w2, w1); 195 System.out.println("a=" + Math.toDegrees(a)); 196 197 assertNotNull(tr); 198 assertEquals("restriction", tr.get("type")); 199 assertEquals(3, tr.getMembersCount()); 200 assertEquals(w2, memberWithRole(tr, "from")); 201 assertEquals(w1, memberWithRole(tr, "to")); 202 assertEquals(n2, memberWithRole(tr, "via")); 203 204 assertEquals("no_left_turn", tr.get("restriction")); 192 205 } 193 206 … … 205 218 @Test 206 219 public void twoConnectedWays_2() { 207 Node n1 = new Node(1) 208 n1.setCoor(new LatLon(5, 5))209 Node n2 = new Node(2) 210 n2.setCoor(new LatLon(7, 5))211 Node n3 = new Node(3) 212 n3.setCoor(new LatLon(7, 2))213 214 Way w1 = new Way(1) 215 w1.setNodes( [n1,n2])216 Way w2 = new Way(2) 217 w2.setNodes( [n3,n2])218 219 assert builder.phi(w1) == Math.toRadians(90)220 assert builder.phi(w2) == Math.toRadians(0)221 assert builder.phi(w2,true) == Math.toRadians(180)222 223 Relation tr = builder.build( [w1,w2,n2])224 225 assert tr != null226 assert tr.get("type") == "restriction"227 assert tr.getMembersCount() == 3228 assert memberWithRole(tr, "from") == w1229 assert memberWithRole(tr, "to") == w2230 assert memberWithRole(tr, "via") == n2231 232 assert tr.get("restriction") == "no_left_turn"220 Node n1 = new Node(1); 221 n1.setCoor(new LatLon(5, 5)); 222 Node n2 = new Node(2); 223 n2.setCoor(new LatLon(7, 5)); 224 Node n3 = new Node(3); 225 n3.setCoor(new LatLon(7, 2)); 226 227 Way w1 = new Way(1); 228 w1.setNodes(Arrays.asList(n1, n2)); 229 Way w2 = new Way(2); 230 w2.setNodes(Arrays.asList(n3, n2)); 231 232 assertEquals(Math.toRadians(90), TurnRestrictionBuilder.phi(w1), 1e-7); 233 assertEquals(Math.toRadians(0), TurnRestrictionBuilder.phi(w2), 1e-7); 234 assertEquals(Math.toRadians(180), TurnRestrictionBuilder.phi(w2, true), 1e-7); 235 236 Relation tr = builder.build(Arrays.asList(w1, w2, n2)); 237 238 assertNotNull(tr); 239 assertEquals("restriction", tr.get("type")); 240 assertEquals(3, tr.getMembersCount()); 241 assertEquals(w1, memberWithRole(tr, "from")); 242 assertEquals(w2, memberWithRole(tr, "to")); 243 assertEquals(n2, memberWithRole(tr, "via")); 244 245 assertEquals("no_left_turn", tr.get("restriction")); 233 246 234 247 /* 235 248 * opposite order, from w2 to w1. In this case we have right turn. 236 249 */ 237 tr = builder.build( [w2,w1,n2])238 239 assert tr != null240 assert tr.get("type") == "restriction"241 assert tr.getMembersCount() == 3242 assert memberWithRole(tr, "from") == w2243 assert memberWithRole(tr, "to") == w1244 assert memberWithRole(tr, "via") == n2245 assert tr.get("restriction") == "no_right_turn"250 tr = builder.build(Arrays.asList(w2, w1, n2)); 251 252 assertNotNull(tr); 253 assertEquals("restriction", tr.get("type")); 254 assertEquals(3, tr.getMembersCount()); 255 assertEquals(w2, memberWithRole(tr, "from")); 256 assertEquals(w1, memberWithRole(tr, "to")); 257 assertEquals(n2, memberWithRole(tr, "via")); 258 assertEquals("no_right_turn", tr.get("restriction")); 246 259 } 247 260 … … 259 272 @Test 260 273 public void twoConnectedWays_3() { 261 Node n1 = new Node(1) 262 n1.setCoor(new LatLon(5, 5))263 Node n2 = new Node(2) 264 n2.setCoor(new LatLon(7, 5))265 Node n3 = new Node(3) 266 n3.setCoor(new LatLon(6, 7))267 268 Way w1 = new Way(1) 269 w1.setNodes( [n1,n2])270 Way w2 = new Way(2) 271 w2.setNodes( [n2,n3])272 273 Relation tr = builder.build( [w1,w2,n2])274 275 assert tr != null276 assert tr.get("type") == "restriction"277 assert tr.getMembersCount() == 3278 assert memberWithRole(tr, "from") == w1279 assert memberWithRole(tr, "to") == w2280 assert memberWithRole(tr, "via") == n2281 282 assert tr.get("restriction") == "no_right_turn"274 Node n1 = new Node(1); 275 n1.setCoor(new LatLon(5, 5)); 276 Node n2 = new Node(2); 277 n2.setCoor(new LatLon(7, 5)); 278 Node n3 = new Node(3); 279 n3.setCoor(new LatLon(6, 7)); 280 281 Way w1 = new Way(1); 282 w1.setNodes(Arrays.asList(n1, n2)); 283 Way w2 = new Way(2); 284 w2.setNodes(Arrays.asList(n2, n3)); 285 286 Relation tr = builder.build(Arrays.asList(w1, w2, n2)); 287 288 assertNotNull(tr); 289 assertEquals("restriction", tr.get("type")); 290 assertEquals(3, tr.getMembersCount()); 291 assertEquals(w1, memberWithRole(tr, "from")); 292 assertEquals(w2, memberWithRole(tr, "to")); 293 assertEquals(n2, memberWithRole(tr, "via")); 294 295 assertEquals("no_right_turn", tr.get("restriction")); 283 296 } 284 285 297 286 298 /** … … 303 315 @Test 304 316 public void twoConnectedWays_4() { 305 Node n1 = new Node(1) 306 n1.setCoor(new LatLon(10,10)) 307 Node n2 = new Node(2) 308 n2.setCoor(new LatLon(8,15)) 309 Node n3 = new Node(3) 310 n3.setCoor(new LatLon(5,11)) 311 312 Way w1 = new Way(1) 313 w1.setNodes([n1,n2]) 314 Way w2 = new Way(2) 315 w2.setNodes([n2,n3]) 316 317 Relation tr = builder.build([w1,w2,n2]) 318 319 assert tr != null 320 assert tr.get("type") == "restriction" 321 assert tr.getMembersCount() == 3 322 assert memberWithRole(tr, "from") == w1 323 assert memberWithRole(tr, "to") == w2 324 assert memberWithRole(tr, "via") == n2 325 326 assert tr.get("restriction") == "no_right_turn" 327 317 Node n1 = new Node(1); 318 n1.setCoor(new LatLon(10, 10)); 319 Node n2 = new Node(2); 320 n2.setCoor(new LatLon(8, 15)); 321 Node n3 = new Node(3); 322 n3.setCoor(new LatLon(5, 11)); 323 324 Way w1 = new Way(1); 325 w1.setNodes(Arrays.asList(n1, n2)); 326 Way w2 = new Way(2); 327 w2.setNodes(Arrays.asList(n2, n3)); 328 329 Relation tr = builder.build(Arrays.asList(w1, w2, n2)); 330 331 assertNotNull(tr); 332 assertEquals("restriction", tr.get("type")); 333 assertEquals(3, tr.getMembersCount()); 334 assertEquals(w1, memberWithRole(tr, "from")); 335 assertEquals(w2, memberWithRole(tr, "to")); 336 assertEquals(n2, memberWithRole(tr, "via")); 337 338 assertEquals("no_right_turn", tr.get("restriction")); 328 339 329 340 /* 330 341 * opposite order, from w2 to w1. In this case we have left turn. 331 342 */ 332 tr = builder.build([w2,w1,n2]) 333 334 assert tr != null 335 assert tr.get("type") == "restriction" 336 assert tr.getMembersCount() == 3 337 assert memberWithRole(tr, "from") == w2 338 assert memberWithRole(tr, "to") == w1 339 assert memberWithRole(tr, "via") == n2 340 341 assert tr.get("restriction") == "no_left_turn" 342 } 343 344 345 def Node nn(id, lat, lon) { 346 Node n = new Node(id) 347 n.setCoor(new LatLon(lat, lon)) 348 return n 349 } 350 351 def Way nw(id, Node... nodes) { 352 Way w = new Way(id) 353 w.setNodes(Arrays.asList(nodes)) 354 return w 343 tr = builder.build(Arrays.asList(w2, w1, n2)); 344 345 assertNotNull(tr); 346 assertEquals("restriction", tr.get("type")); 347 assertEquals(3, tr.getMembersCount()); 348 assertEquals(w2, memberWithRole(tr, "from")); 349 assertEquals(w1, memberWithRole(tr, "to")); 350 assertEquals(n2, memberWithRole(tr, "via")); 351 352 assertEquals("no_left_turn", tr.get("restriction")); 353 } 354 355 static Node nn(long id, double lat, double lon) { 356 Node n = new Node(id); 357 n.setCoor(new LatLon(lat, lon)); 358 return n; 359 } 360 361 static Way nw(long id, Node... nodes) { 362 Way w = new Way(id); 363 w.setNodes(Arrays.asList(nodes)); 364 return w; 355 365 } 356 366 … … 365 375 @Test 366 376 public void intersectionAngle_1() { 367 Node n1 = nn(1, 5,5)368 Node n2 = nn(2, 5,10)369 Node n3 = nn(3, 10,10)370 Way from = nw(1, n1,n2)371 Way to = nw(2, n2,n3)372 373 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 374 RelativeWayJoinOrientation o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to)375 assert Math.toDegrees(a) == -90376 assert o == RelativeWayJoinOrientation.LEFT377 Node n1 = nn(1, 5, 5); 378 Node n2 = nn(2, 5, 10); 379 Node n3 = nn(3, 10, 10); 380 Way from = nw(1, n1, n2); 381 Way to = nw(2, n2, n3); 382 383 double a = TurnRestrictionBuilder.intersectionAngle(from, to); 384 RelativeWayJoinOrientation o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to); 385 assertEquals(-90, Math.toDegrees(a), 1e-7); 386 assertEquals(RelativeWayJoinOrientation.LEFT, o); 377 387 378 388 /* 379 * if reversed from, the intersection angle is still -90 �389 * if reversed from, the intersection angle is still -90 380 390 */ 381 from = nw(1, n2,n1)382 to = nw(2, n2,n3)383 a = TurnRestrictionBuilder.intersectionAngle(from, to) 384 o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to)385 assert Math.toDegrees(a) == -90386 assert o == RelativeWayJoinOrientation.LEFT391 from = nw(1, n2, n1); 392 to = nw(2, n2, n3); 393 a = TurnRestrictionBuilder.intersectionAngle(from, to); 394 o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to); 395 assertEquals(-90, Math.toDegrees(a), 1e-7); 396 assertEquals(RelativeWayJoinOrientation.LEFT, o); 387 397 388 398 /* 389 * if reversed to, the intersection angle is still -90 �399 * if reversed to, the intersection angle is still -90 390 400 */ 391 from = nw(1, n1,n2)392 to = nw(2, n3,n2)393 a = TurnRestrictionBuilder.intersectionAngle(from, to) 394 o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to)395 assert Math.toDegrees(a) == -90396 assert o == RelativeWayJoinOrientation.LEFT401 from = nw(1, n1, n2); 402 to = nw(2, n3, n2); 403 a = TurnRestrictionBuilder.intersectionAngle(from, to); 404 o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to); 405 assertEquals(-90, Math.toDegrees(a), 1e-7); 406 assertEquals(RelativeWayJoinOrientation.LEFT, o); 397 407 398 408 /* 399 * if reversed both, the intersection angle is still -90 �409 * if reversed both, the intersection angle is still -90 400 410 */ 401 from = nw(1, n2,n1)402 to = nw(2, n3,n2)403 a = TurnRestrictionBuilder.intersectionAngle(from, to) 404 o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to)405 assert Math.toDegrees(a) == -90406 assert o == RelativeWayJoinOrientation.LEFT411 from = nw(1, n2, n1); 412 to = nw(2, n3, n2); 413 a = TurnRestrictionBuilder.intersectionAngle(from, to); 414 o = TurnRestrictionBuilder.determineWayJoinOrientation(from, to); 415 assertEquals(-90, Math.toDegrees(a), 1e-7); 416 assertEquals(RelativeWayJoinOrientation.LEFT, o); 407 417 } 408 418 … … 420 430 @Test 421 431 public void intersectionAngle_2() { 422 Node n1 = nn(1, 5,5)423 Node n2 = nn(2, 5,10)424 Node n3 = nn(3, 2,10)425 Way from = nw(1, n1,n2)426 Way to = nw(2, n2,n3)427 428 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 429 assert Math.toDegrees(a) == 90432 Node n1 = nn(1, 5, 5); 433 Node n2 = nn(2, 5, 10); 434 Node n3 = nn(3, 2, 10); 435 Way from = nw(1, n1, n2); 436 Way to = nw(2, n2, n3); 437 438 double a = TurnRestrictionBuilder.intersectionAngle(from, to); 439 assertEquals(90, Math.toDegrees(a), 1e-7); 430 440 431 441 /* 432 * if reversed from, the intersection angle is still 90 �442 * if reversed from, the intersection angle is still 90 433 443 */ 434 from = nw(1, n2,n1)435 to = nw(2, n2,n3)436 a = TurnRestrictionBuilder.intersectionAngle(from, to) 437 assert Math.toDegrees(a) == 90444 from = nw(1, n2, n1); 445 to = nw(2, n2, n3); 446 a = TurnRestrictionBuilder.intersectionAngle(from, to); 447 assertEquals(90, Math.toDegrees(a), 1e-7); 438 448 439 449 /* 440 * if reversed to, the intersection angle is still 90 �450 * if reversed to, the intersection angle is still 90 441 451 */ 442 from = nw(1, n1,n2)443 to = nw(2, n3,n2)444 a = TurnRestrictionBuilder.intersectionAngle(from, to) 445 assert Math.toDegrees(a) == 90452 from = nw(1, n1, n2); 453 to = nw(2, n3, n2); 454 a = TurnRestrictionBuilder.intersectionAngle(from, to); 455 assertEquals(90, Math.toDegrees(a), 1e-7); 446 456 447 457 /* 448 * if reversed both, the intersection angle is still 90 �458 * if reversed both, the intersection angle is still 90 449 459 */ 450 from = nw(1,n2,n1) 451 to = nw(2,n3,n2) 452 a = TurnRestrictionBuilder.intersectionAngle(from, to) 453 assert Math.toDegrees(a) == 90 454 } 455 460 from = nw(1, n2, n1); 461 to = nw(2, n3, n2); 462 a = TurnRestrictionBuilder.intersectionAngle(from, to); 463 assertEquals(90, Math.toDegrees(a), 1e-7); 464 } 456 465 457 466 /** … … 472 481 @Test 473 482 public void intersectionAngle_3() { 474 Node n1 = nn(1, -10,-10)475 Node n2 = nn(2, -5,-10)476 Node n3 = nn(3, -1,-6)477 Way from = nw(1, n1,n2)478 Way to = nw(2, n2,n3)479 480 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 481 assert Math.toDegrees(a) == 45483 Node n1 = nn(1, -10, -10); 484 Node n2 = nn(2, -5, -10); 485 Node n3 = nn(3, -1, -6); 486 Way from = nw(1, n1, n2); 487 Way to = nw(2, n2, n3); 488 489 double a = TurnRestrictionBuilder.intersectionAngle(from, to); 490 assertEquals(45, Math.toDegrees(a), 1e-7); 482 491 483 492 /* 484 493 * if reversed from, the intersection angle is still 45 485 494 */ 486 from = nw(1, n2,n1)487 to = nw(2, n2,n3)488 a = TurnRestrictionBuilder.intersectionAngle(from, to) 489 assert Math.toDegrees(a) == 45495 from = nw(1, n2, n1); 496 to = nw(2, n2, n3); 497 a = TurnRestrictionBuilder.intersectionAngle(from, to); 498 assertEquals(45, Math.toDegrees(a), 1e-7); 490 499 491 500 /* 492 501 * if reversed to, the intersection angle is still 45 493 502 */ 494 from = nw(1, n1,n2)495 to = nw(2, n3,n2)496 a = TurnRestrictionBuilder.intersectionAngle(from, to) 497 assert Math.toDegrees(a) == 45503 from = nw(1, n1, n2); 504 to = nw(2, n3, n2); 505 a = TurnRestrictionBuilder.intersectionAngle(from, to); 506 assertEquals(45, Math.toDegrees(a), 1e-7); 498 507 499 508 /* 500 509 * if reversed both, the intersection angle is still 45 501 510 */ 502 from = nw(1, n2,n1)503 to = nw(2, n3,n2)504 a = TurnRestrictionBuilder.intersectionAngle(from, to) 505 assert Math.toDegrees(a) == 45511 from = nw(1, n2, n1); 512 to = nw(2, n3, n2); 513 a = TurnRestrictionBuilder.intersectionAngle(from, to); 514 assertEquals(45, Math.toDegrees(a), 1e-7); 506 515 } 507 516 … … 523 532 @Test 524 533 public void intersectionAngle_4() { 525 Node n1 = nn(1, -10,-10)526 Node n2 = nn(2, -5,-10)527 Node n3 = nn(3, -1,-14)528 Way from = nw(1, n1,n2)529 Way to = nw(2, n2,n3)530 531 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 532 assert Math.toDegrees(a) == -45534 Node n1 = nn(1, -10, -10); 535 Node n2 = nn(2, -5, -10); 536 Node n3 = nn(3, -1, -14); 537 Way from = nw(1, n1, n2); 538 Way to = nw(2, n2, n3); 539 540 double a = TurnRestrictionBuilder.intersectionAngle(from, to); 541 assertEquals(-45, Math.toDegrees(a), 1e-7); 533 542 534 543 /* 535 544 * if reversed from, the intersection angle is still -45 536 545 */ 537 from = nw(1, n2,n1)538 to = nw(2, n2,n3)539 a = TurnRestrictionBuilder.intersectionAngle(from, to) 540 assert Math.toDegrees(a) == -45546 from = nw(1, n2, n1); 547 to = nw(2, n2, n3); 548 a = TurnRestrictionBuilder.intersectionAngle(from, to); 549 assertEquals(-45, Math.toDegrees(a), 1e-7); 541 550 542 551 /* 543 552 * if reversed to, the intersection angle is still -45 544 553 */ 545 from = nw(1, n1,n2)546 to = nw(2, n3,n2)547 a = TurnRestrictionBuilder.intersectionAngle(from, to) 548 assert Math.toDegrees(a) == -45554 from = nw(1, n1, n2); 555 to = nw(2, n3, n2); 556 a = TurnRestrictionBuilder.intersectionAngle(from, to); 557 assertEquals(-45, Math.toDegrees(a), 1e-7); 549 558 550 559 /* 551 560 * if reversed both, the intersection angle is still 45 552 561 */ 553 from = nw(1, n2,n1)554 to = nw(2, n3,n2)555 a = TurnRestrictionBuilder.intersectionAngle(from, to) 556 assert Math.toDegrees(a) == -45562 from = nw(1, n2, n1); 563 to = nw(2, n3, n2); 564 a = TurnRestrictionBuilder.intersectionAngle(from, to); 565 assertEquals(-45, Math.toDegrees(a), 1e-7); 557 566 } 558 567 … … 572 581 public void splitToWay() { 573 582 Node n11 = new Node(11); 574 n11.setCoor(new LatLon(5, 15));575 576 Node n21 = new Node(21) 577 n21.setCoor(new LatLon(10, 10))578 Node n22 = new Node(22) 579 n22.setCoor(new LatLon(10, 15))580 Node n23 = new Node(23) 581 n23.setCoor(new LatLon(10, 20))582 583 Way w1 = new Way(1) 584 w1.setNodes( [n11,n22])585 Way w21 = new Way(21) 586 w21.setNodes( [n21,n22])587 Way w22 = new Way(22) 588 w22.setNodes( [n22,n23])583 n11.setCoor(new LatLon(5, 15)); 584 585 Node n21 = new Node(21); 586 n21.setCoor(new LatLon(10, 10)); 587 Node n22 = new Node(22); 588 n22.setCoor(new LatLon(10, 15)); 589 Node n23 = new Node(23); 590 n23.setCoor(new LatLon(10, 20)); 591 592 Way w1 = new Way(1); 593 w1.setNodes(Arrays.asList(n11, n22)); 594 Way w21 = new Way(21); 595 w21.setNodes(Arrays.asList(n21, n22)); 596 Way w22 = new Way(22); 597 w22.setNodes(Arrays.asList(n22, n23)); 589 598 590 599 Way adjustedTo = selectToWayAfterSplit( … … 593 602 w22, 594 603 TurnRestrictionType.NO_LEFT_TURN 595 ) 596 597 assert adjustedTo != null598 assert adjustedTo == w21604 ); 605 606 assertNotNull(adjustedTo); 607 assertEquals(w21, adjustedTo); 599 608 600 609 adjustedTo = selectToWayAfterSplit( … … 603 612 w22, 604 613 TurnRestrictionType.NO_RIGHT_TURN 605 ) 606 607 assert adjustedTo != null608 assert adjustedTo == w22614 ); 615 616 assertNotNull(adjustedTo); 617 assertEquals(w22, adjustedTo); 609 618 610 619 adjustedTo = selectToWayAfterSplit( … … 613 622 w22, 614 623 TurnRestrictionType.ONLY_LEFT_TURN 615 ) 616 617 assert adjustedTo != null618 assert adjustedTo == w21624 ); 625 626 assertNotNull(adjustedTo); 627 assertEquals(w21, adjustedTo); 619 628 620 629 adjustedTo = selectToWayAfterSplit( … … 623 632 w22, 624 633 TurnRestrictionType.ONLY_RIGHT_TURN 625 ) 626 627 assert adjustedTo != null628 assert adjustedTo == w22634 ); 635 636 assertNotNull(adjustedTo); 637 assertEquals(w22, adjustedTo); 629 638 630 639 adjustedTo = selectToWayAfterSplit( … … 633 642 w22, 634 643 TurnRestrictionType.NO_STRAIGHT_ON 635 ) 636 637 assert adjustedTo == null644 ); 645 646 assertNull(adjustedTo); 638 647 } 639 648 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/ExceptValueModelTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 3 import static org.junit.Assert.* 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 4 7 5 import org.junit. *8 import org.junit.Test; 6 9 7 class ExceptValueModelTest {10 public class ExceptValueModelTest { 8 11 9 12 @Test 10 public void constructor() { 11 new ExceptValueModel() 12 13 def evm = new ExceptValueModel(null) 14 evm = new ExceptValueModel("") 15 evm = new ExceptValueModel(" ") 16 evm = new ExceptValueModel("hgv") 17 evm = new ExceptValueModel("hgv;psv") 18 evm = new ExceptValueModel("non_standard") 13 public void testConstructors() { 14 new ExceptValueModel(); 15 new ExceptValueModel(null); 16 new ExceptValueModel(""); 17 new ExceptValueModel(" "); 18 new ExceptValueModel("hgv"); 19 new ExceptValueModel("hgv;psv"); 20 new ExceptValueModel("non_standard"); 19 21 } 20 22 21 23 @Test 22 public void setValue() {23 def evm24 public void testSetValue() { 25 ExceptValueModel evm; 24 26 25 27 // null value allowed - means no vehicle exceptions 26 evm = new ExceptValueModel() 27 evm.setValue(null) 28 assert evm.getValue() == ""29 assert evm.isStandard()28 evm = new ExceptValueModel(); 29 evm.setValue(null); 30 assertEquals("", evm.getValue()); 31 assertTrue(evm.isStandard()); 30 32 31 33 // empty string allowed - means no vehicle expections 32 evm = new ExceptValueModel() 33 evm.setValue("") 34 assert evm.getValue() == ""35 assert evm.isStandard()34 evm = new ExceptValueModel(); 35 evm.setValue(""); 36 assertEquals("", evm.getValue()); 37 assertTrue(evm.isStandard()); 36 38 37 39 // a single standard vehicle exeption 38 evm = new ExceptValueModel() 39 evm.setValue("hgv") 40 assert evm.getValue() == "hgv"41 assert evm.isVehicleException("hgv")42 assert ! evm.isVehicleException("psv")43 assert evm.isStandard()40 evm = new ExceptValueModel(); 41 evm.setValue("hgv"); 42 assertEquals("hgv", evm.getValue()); 43 assertTrue(evm.isVehicleException("hgv")); 44 assertFalse(evm.isVehicleException("psv")); 45 assertTrue(evm.isStandard()); 44 46 45 47 // two standard vehicle exceptions 46 evm = new ExceptValueModel() 47 evm.setValue("hgv;psv") 48 assert evm.getValue() == "hgv;psv"49 assert evm.isVehicleException("hgv")50 assert evm.isVehicleException("psv")51 assert evm.isStandard()48 evm = new ExceptValueModel(); 49 evm.setValue("hgv;psv"); 50 assertEquals("hgv;psv", evm.getValue()); 51 assertTrue(evm.isVehicleException("hgv")); 52 assertTrue(evm.isVehicleException("psv")); 53 assertTrue(evm.isStandard()); 52 54 53 55 // white space and lowercase/uppercase mix allowed. Should be normalized 54 56 // by the except value model 55 evm = new ExceptValueModel() 56 evm.setValue(" hGv ; PsV ") 57 assert evm.getValue() == "hgv;psv"58 assert evm.isVehicleException("hgv")59 assert evm.isVehicleException("psv")60 assert evm.isStandard()57 evm = new ExceptValueModel(); 58 evm.setValue(" hGv ; PsV "); 59 assertEquals("hgv;psv", evm.getValue()); 60 assertTrue(evm.isVehicleException("hgv")); 61 assertTrue(evm.isVehicleException("psv")); 62 assertTrue(evm.isStandard()); 61 63 62 64 // non standard value allowed 63 evm = new ExceptValueModel() 64 evm.setValue("Non Standard") 65 assert evm.getValue() == "Non Standard"66 assert !evm.isVehicleException("hgv")67 assert !evm.isVehicleException("psv")68 assert !evm.isStandard()65 evm = new ExceptValueModel(); 66 evm.setValue("Non Standard"); 67 assertEquals("Non Standard", evm.getValue()); 68 assertFalse(evm.isVehicleException("hgv")); 69 assertFalse(evm.isVehicleException("psv")); 70 assertFalse(evm.isStandard()); 69 71 } 70 72 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 3 import static groovy.test.GroovyAssert.shouldFail 4 import static org.junit.Assert.* 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertTrue; 5 7 6 import javax.swing.DefaultListSelectionModel 8 import java.util.ArrayList; 9 import java.util.Arrays; 10 import java.util.Collections; 11 import java.util.HashSet; 12 import java.util.List; 7 13 8 import org.junit.* 9 import org.openstreetmap.josm.Main 10 import org.openstreetmap.josm.data.coor.* 11 import org.openstreetmap.josm.data.osm.* 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer 13 import org.openstreetmap.josm.testutils.JOSMTestRules 14 import javax.swing.ListSelectionModel; 15 16 import org.junit.Rule; 17 import org.junit.Test; 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm.Node; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Relation; 24 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 27 15 28 /** 16 29 * Unit test for {@see JosmSelctionListModel} 17 30 */ 18 class JosmSelectionListModelTest {31 public class JosmSelectionListModelTest { 19 32 20 33 @Rule … … 22 35 23 36 @Test 24 public void test_Constructor(){ 25 DataSet ds = new DataSet() 26 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 27 JosmSelectionListModel model = new JosmSelectionListModel(layer); 37 public void testConstructor() { 38 assertNotNull(new JosmSelectionListModel(new OsmDataLayer(new DataSet(), "test", null))); 39 } 28 40 29 shouldFail(IllegalArgumentException){30 model = new JosmSelectionListModel(null)31 }41 @Test(expected = IllegalArgumentException.class) 42 public void testConstructorNull() { 43 new JosmSelectionListModel(null); 32 44 } 33 45 34 46 @Test 35 47 public void test_setJOSMSelection() { 36 DataSet ds = new DataSet() 37 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 48 DataSet ds = new DataSet(); 49 OsmDataLayer layer = new OsmDataLayer(ds, "test", null); 38 50 JosmSelectionListModel model = new JosmSelectionListModel(layer); 39 51 40 52 // set a selection with three objects 41 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 42 model.setJOSMSelection objects 43 assert model.getSize() == 3 53 model.setJOSMSelection(Arrays.asList(new Node(new LatLon(1, 1)), new Way(), new Relation())); 54 assertEquals(3, model.getSize()); 44 55 45 56 // null is allowed 46 model.setJOSMSelection(null) 47 assert model.getSize() == 048 assert model.getSelected().isEmpty()57 model.setJOSMSelection(null); 58 assertEquals(0, model.getSize()); 59 assertTrue(model.getSelected().isEmpty()); 49 60 50 61 // empty has the same effect 51 model.setJOSMSelection( [])52 assert model.getSize() == 053 assert model.getSelected().isEmpty()62 model.setJOSMSelection(new ArrayList<>()); 63 assertEquals(0, model.getSize()); 64 assertTrue(model.getSelected().isEmpty()); 54 65 } 55 66 56 67 @Test 57 68 public void test_setJOSMSelection_withSelected() { 58 DataSet ds = new DataSet() 59 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 69 DataSet ds = new DataSet(); 70 OsmDataLayer layer = new OsmDataLayer(ds, "test", null); 60 71 JosmSelectionListModel model = new JosmSelectionListModel(layer); 61 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]62 model.setJOSMSelection(objects) 63 model.setSelected(objects [0..1])64 assert model.getSelected().asList() as Set == objects[0..1] as Set72 List<OsmPrimitive> objects = (Arrays.asList(new Node(new LatLon(1, 1)), new Way(), new Relation())); 73 model.setJOSMSelection(objects); 74 model.setSelected(objects.subList(0, 1)); 75 assertEquals(new HashSet<>(objects.subList(0, 1)), model.getSelected()); 65 76 66 77 // set new selection which includes one object which is currently 67 78 // selected in the model. Should still be selected after setting 68 79 // the new JOSM selection 69 objects = objects [1..2]70 model.setJOSMSelection(objects) 71 assert model.getSelected().asList() == [objects[0]]80 objects = objects.subList(1, 2); 81 model.setJOSMSelection(objects); 82 assertEquals(Collections.singleton(objects.get(0)), model.getSelected()); 72 83 } 73 84 74 85 @Test 75 86 public void test_getSelected() { 76 DataSet ds = new DataSet() 77 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 87 DataSet ds = new DataSet(); 88 OsmDataLayer layer = new OsmDataLayer(ds, "test", null); 78 89 79 90 JosmSelectionListModel model = new JosmSelectionListModel(layer); 80 DefaultListSelectionModel selectionModel = model.getListSelectionModel()91 ListSelectionModel selectionModel = model.getListSelectionModel(); 81 92 82 assert model.getSelected() != null83 assert model.getSelected().isEmpty()93 assertNotNull(model.getSelected()); 94 assertTrue(model.getSelected().isEmpty()); 84 95 85 96 // select one element 86 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 87 model.setJOSMSelection(objects) 88 selectionModel.setSelectionInterval(0, 0) 89 assert model.getSelected().asList() == [model.getElementAt(0)]; 97 model.setJOSMSelection(Arrays.asList(new Node(new LatLon(1, 1)), new Way(), new Relation())); 98 selectionModel.setSelectionInterval(0, 0); 99 assertEquals(Collections.singleton(model.getElementAt(0)), model.getSelected()); 90 100 91 101 // select two elements 92 selectionModel.setSelectionInterval(1, 2)93 assert model.getSelected().asList() as Set == [model.getElementAt(1),model.getElementAt(2)] as Set;102 selectionModel.setSelectionInterval(1, 2); 103 assertEquals(new HashSet<>(Arrays.asList(model.getElementAt(1), model.getElementAt(2))), model.getSelected()); 94 104 } 95 105 96 106 @Test 97 107 public void test_setSelected() { 98 DataSet ds = new DataSet()99 OsmDataLayer layer = new OsmDataLayer(ds, "test", null)100 101 108 // set selected with null is OK - nothing selected thereafter 102 JosmSelectionListModel model = new JosmSelectionListModel(layer); 103 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 104 model.setSelected(null) 105 assert model.getSelected().isEmpty() 109 JosmSelectionListModel model = new JosmSelectionListModel(new OsmDataLayer(new DataSet(), "test", null)); 110 model.setSelected(null); 111 assertTrue(model.getSelected().isEmpty()); 106 112 107 113 // set selected with empty list is OK - nothing selected thereafter 108 model.setSelected( [])109 assert model.getSelected().isEmpty()114 model.setSelected(new ArrayList<>()); 115 assertTrue(model.getSelected().isEmpty()); 110 116 111 117 // select an object existing in the list of displayed objects 112 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]113 model.setJOSMSelection(objects) 114 model.setSelected( [objects[0]])115 assert model.getSelected().asList() == [objects[0]];118 List<OsmPrimitive> objects = (Arrays.asList(new Node(new LatLon(1, 1)), new Way(), new Relation())); 119 model.setJOSMSelection(objects); 120 model.setSelected(Arrays.asList(objects.get(0))); 121 assertEquals(Collections.singleton(objects.get(0)), model.getSelected()); 116 122 117 123 // select an object not-existing in the list of displayed objects 118 model.setJOSMSelection(objects) 119 model.setSelected( [new Way()])120 assert model.getSelected().isEmpty()124 model.setJOSMSelection(objects); 125 model.setSelected(Arrays.asList(new Way())); 126 assertTrue(model.getSelected().isEmpty()); 121 127 } 122 128 123 129 @Test 124 130 public void test_editLayerChanged() { 125 DataSet ds = new DataSet() 131 DataSet ds = new DataSet(); 126 132 127 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]128 objects. each {ds.addPrimitive(it)}133 List<OsmPrimitive> objects = (Arrays.asList(new Node(new LatLon(1, 1)), new Way(), new Relation())); 134 objects.stream().forEach(ds::addPrimitive); 129 135 130 OsmDataLayer layer1 = new OsmDataLayer(ds, "layer1", null)131 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "layer2", null)136 OsmDataLayer layer1 = new OsmDataLayer(ds, "layer1", null); 137 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "layer2", null); 132 138 133 Main.getLayerManager().addLayer(layer1) 134 Main.getLayerManager().addLayer(layer2) 139 Main.getLayerManager().addLayer(layer1); 140 Main.getLayerManager().addLayer(layer2); 135 141 136 142 JosmSelectionListModel model = new JosmSelectionListModel(layer1); 137 Main.getLayerManager().addActiveLayerChangeListener(model) 138 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 143 Main.getLayerManager().addActiveLayerChangeListener(model); 139 144 // switch from edit layer1 to edit layer2. content of the JOSM selection 140 145 // should be empty thereafter 141 Main.getLayerManager().setActiveLayer(layer1) 142 Main.getLayerManager().setActiveLayer(layer2) 143 assert model.getSize() == 0146 Main.getLayerManager().setActiveLayer(layer1); 147 Main.getLayerManager().setActiveLayer(layer2); 148 assertEquals(0, model.getSize()); 144 149 145 150 // switch from layer2 to layer1 which has one object selected. Object should 146 151 // be displayed in the JOSM selection list 147 ds.setSelected( [objects[0]])148 Main.getLayerManager().setActiveLayer(layer1) 149 assert model.getSize() == 1150 assert model.getElementAt(0) == objects[0];152 ds.setSelected(Collections.singleton(objects.get(0))); 153 Main.getLayerManager().setActiveLayer(layer1); 154 assertEquals(1, model.getSize()); 155 assertEquals(objects.get(0), model.getElementAt(0)); 151 156 152 157 // switch to a "null" edit layer (i.e. no edit layer)- nothing should 153 158 // be displayed in the selection list 154 Main.getLayerManager().removeLayer(layer2) 155 Main.getLayerManager().removeLayer(layer1) 156 assert model.getSize() == 0159 Main.getLayerManager().removeLayer(layer2); 160 Main.getLayerManager().removeLayer(layer1); 161 assertEquals(0, model.getSize()); 157 162 158 Main.getLayerManager().removeActiveLayerChangeListener(model) 163 Main.getLayerManager().removeActiveLayerChangeListener(model); 159 164 } 160 165 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModelUnitTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 import static groovy.test.GroovyAssert.shouldFail 3 import static org.junit.Assert.* 4 import static org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionLegRole.* 5 6 import org.junit.* 7 import org.openstreetmap.josm.data.coor.* 8 import org.openstreetmap.josm.data.osm.* 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer 10 import org.openstreetmap.josm.testutils.JOSMTestRules 3 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertTrue; 7 import static org.junit.Assert.fail; 8 import static org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionLegRole.FROM; 9 import static org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionLegRole.TO; 10 11 import java.util.ArrayList; 12 import java.util.Arrays; 13 import java.util.Collections; 14 15 import org.junit.Before; 16 import org.junit.Rule; 17 import org.junit.Test; 18 import org.openstreetmap.josm.data.coor.LatLon; 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 23 import org.openstreetmap.josm.data.osm.Relation; 24 import org.openstreetmap.josm.data.osm.RelationMember; 25 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 26 import org.openstreetmap.josm.data.osm.Way; 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 29 12 30 /** 13 31 * This is a unit test for {@link TurnRestrictionEditorModel} 14 32 */ 15 class TurnRestrictionEditorModelUnitTest {33 public class TurnRestrictionEditorModelUnitTest { 16 34 17 35 @Rule 18 36 public JOSMTestRules rules = new JOSMTestRules().preferences(); 19 37 20 def navigationControlerMock = [ 21 gotoBasicEditor:{}, 22 gotoAdvancedEditor: {} 23 ] as NavigationControler 24 25 private DataSet ds 26 private OsmDataLayer layer 27 private TurnRestrictionEditorModel model 28 29 def createNode(id = null, coor = null) { 30 Node n 31 if (id == null){ 32 n = new Node() 38 private final NavigationControler navigationControlerMock = new NavigationControler() { 39 @Override 40 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 41 } 42 43 @Override 44 public void gotoBasicEditor() { 45 } 46 47 @Override 48 public void gotoAdvancedEditor() { 49 } 50 }; 51 52 private DataSet ds; 53 private OsmDataLayer layer; 54 private TurnRestrictionEditorModel model; 55 56 Node createNode(Long id, LatLon coor) { 57 Node n; 58 if (id == null) { 59 n = new Node(); 33 60 } else { 34 n = new Node(id) 35 } 36 if (coor != null) n.setCoor(coor) 37 ds.addPrimitive(n) 38 return n 39 } 40 41 def createWay(id=null) { 42 Way w 43 if (id == null){ 44 w = new Way() 61 n = new Node(id); 62 } 63 if (coor != null) 64 n.setCoor(coor); 65 ds.addPrimitive(n); 66 return n; 67 } 68 69 Way createWay(Long id) { 70 Way w; 71 if (id == null) { 72 w = new Way(); 45 73 } else { 46 w = new Way(id) 47 } 48 ds.addPrimitive(w) 49 return w 50 } 51 52 def node(id){53 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.NODE))54 } 55 56 def way(id) {57 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.WAY))58 } 59 60 def rel(id){61 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.RELATION))62 } 63 64 def rm(role,object){74 w = new Way(id); 75 } 76 ds.addPrimitive(w); 77 return w; 78 } 79 80 Node node(long id) { 81 return (Node) ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.NODE)); 82 } 83 84 Way way(long id) { 85 return (Way) ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.WAY)); 86 } 87 88 Relation rel(long id) { 89 return (Relation) ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.RELATION)); 90 } 91 92 RelationMember rm(String role, OsmPrimitive object) { 65 93 return new RelationMember(role, object); 66 94 } 67 95 68 defbuildDataSet1() {96 void buildDataSet1() { 69 97 // prepare some nodes and ways 70 createNode(21 )71 createNode(22 )72 createNode(31 )73 createNode(32 )74 createWay(2 )75 createWay(3 )76 77 way(2).setNodes( [node(21), node(22)])78 way(3).setNodes( [node(22), node(31)])98 createNode(21L, null); 99 createNode(22L, null); 100 createNode(31L, null); 101 createNode(32L, null); 102 createWay(2L); 103 createWay(3L); 104 105 way(2).setNodes(Arrays.asList(node(21), node(22))); 106 way(3).setNodes(Arrays.asList(node(22), node(31))); 79 107 80 108 // a standard turn restriction with a from, a to and a via 81 Relation r = new Relation(1) 82 r.setMembers( [rm("from", way(2)), rm("to", way(3)), rm("via", node(22))])83 r.put "type", "restriction"84 r.put "restriction", "no_left_turn"85 ds.addPrimitive r109 Relation r = new Relation(1); 110 r.setMembers(Arrays.asList(rm("from", way(2)), rm("to", way(3)), rm("via", node(22)))); 111 r.put("type", "restriction"); 112 r.put("restriction", "no_left_turn"); 113 ds.addPrimitive(r); 86 114 } 87 115 88 116 @Before 89 117 public void setUp() { 90 ds = new DataSet() 91 layer = new OsmDataLayer(ds, "test", null) 118 ds = new DataSet(); 119 layer = new OsmDataLayer(ds, "test", null); 92 120 model = new TurnRestrictionEditorModel(layer, navigationControlerMock); 93 121 } … … 96 124 * Test the constructor 97 125 */ 98 @Test 99 public void test_Constructor() { 100 shouldFail(IllegalArgumentException){ 101 model = new TurnRestrictionEditorModel(null, navigationControlerMock); 102 } 103 104 shouldFail(IllegalArgumentException){ 105 model = new TurnRestrictionEditorModel(layer, null); 106 } 107 } 108 109 @Test 110 public void test_populate_EmptyTurnRestriction() { 126 @Test(expected = IllegalArgumentException.class) 127 public void testConstructor1() { 128 new TurnRestrictionEditorModel(null, navigationControlerMock); 129 } 130 131 /** 132 * Test the constructor 133 */ 134 @Test(expected = IllegalArgumentException.class) 135 public void testConstructor2() { 136 new TurnRestrictionEditorModel(layer, null); 137 } 138 139 @Test 140 public void testPopulateEmptyTurnRestriction() { 111 141 // an "empty" turn restriction with a public id 112 Relation r = new Relation(1) 113 ds.addPrimitive r114 assert model.getTurnRestrictionLeg(FROM).isEmpty()115 assert model.getTurnRestrictionLeg(TO).isEmpty()116 assert model.getVias().isEmpty()117 assert model.getRestrictionTagValue() == ""118 assert model.getExcept().getValue() == ""142 Relation r = new Relation(1); 143 ds.addPrimitive(r); 144 assertTrue(model.getTurnRestrictionLeg(FROM).isEmpty()); 145 assertTrue(model.getTurnRestrictionLeg(TO).isEmpty()); 146 assertTrue(model.getVias().isEmpty()); 147 assertEquals("", model.getRestrictionTagValue()); 148 assertEquals("", model.getExcept().getValue()); 119 149 } 120 150 … … 127 157 @Test 128 158 public void test_populate_SimpleStandardTurnRestriction() { 129 buildDataSet1() 130 model.populate(rel(1)) 131 132 assert model.getTurnRestrictionLeg(FROM).asList() == [way(2)]133 assert model.getTurnRestrictionLeg(TO).asList() == [way(3)]134 assert model.getVias() == [node(22)]135 assert model.getRestrictionTagValue() == "no_left_turn"136 assert model.getExcept().getValue() == ""159 buildDataSet1(); 160 model.populate(rel(1)); 161 162 assertEquals(Collections.singleton(way(2)), model.getTurnRestrictionLeg(FROM)); 163 assertEquals(Collections.singleton(way(3)), model.getTurnRestrictionLeg(TO)); 164 assertEquals(Arrays.asList(node(22)), model.getVias()); 165 assertEquals("no_left_turn", model.getRestrictionTagValue()); 166 assertEquals("", model.getExcept().getValue()); 137 167 } 138 168 139 169 @Test 140 170 public void setFrom() { 141 buildDataSet1() 142 model.populate(rel(1)) 143 144 createNode(41 )145 createNode(42 )146 createWay(4 ).setNodes([node(41),node(42)]);171 buildDataSet1(); 172 model.populate(rel(1)); 173 174 createNode(41L, null); 175 createNode(42L, null); 176 createWay(4L).setNodes(Arrays.asList(node(41), node(42))); 147 177 148 178 // set another way as from 149 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way(4).getPrimitiveId()) 150 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).asList() == [way(4)];179 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way(4).getPrimitiveId()); 180 assertEquals(Collections.singleton(way(4)), model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM)); 151 181 152 182 // delete the/all members with role 'from' 153 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, null) 154 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).isEmpty() 155 156 157 shouldFail(IllegalArgumentException) { 183 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, null); 184 assertTrue(model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).isEmpty()); 185 186 try { 158 187 // can't add a node as 'from' 159 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, node(21).getPrimitiveId()) 160 } 161 162 shouldFail(IllegalStateException) { 188 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, node(21).getPrimitiveId()); 189 fail(); 190 } catch (IllegalArgumentException e) { 191 // OK 192 System.out.println(e.getMessage()); 193 } 194 195 try { 163 196 // can't set a way as 'from' if it isn't part of the dataset 164 Way way = new Way() 165 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way.getPrimitiveId()) 197 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, new Way().getPrimitiveId()); 198 fail(); 199 } catch (IllegalStateException e) { 200 // OK 201 System.out.println(e.getMessage()); 166 202 } 167 203 } … … 169 205 @Test 170 206 public void setTo() { 171 buildDataSet1() 172 model.populate(rel(1)) 173 174 createNode(41 )175 createNode(42 )176 createWay(4 ).setNodes([node(41),node(42)]);207 buildDataSet1(); 208 model.populate(rel(1)); 209 210 createNode(41L, null); 211 createNode(42L, null); 212 createWay(4L).setNodes(Arrays.asList(node(41), node(42))); 177 213 178 214 // set another way as from 179 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way(4).getPrimitiveId()) 180 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).asList() == [way(4)];215 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way(4).getPrimitiveId()); 216 assertEquals(Collections.singleton(way(4)), model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO)); 181 217 182 218 // delete the/all members with role 'from' 183 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, null) 184 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).isEmpty() 185 186 187 shouldFail(IllegalArgumentException) { 219 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, null); 220 assertTrue(model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).isEmpty()); 221 222 try { 188 223 // can't add a node as 'from' 189 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, node(21).getPrimitiveId()) 190 } 191 192 shouldFail(IllegalStateException) { 224 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, node(21).getPrimitiveId()); 225 fail(); 226 } catch (IllegalArgumentException e) { 227 // OK 228 System.out.println(e.getMessage()); 229 } 230 231 try { 193 232 // can't set a way as 'from' if it isn't part of the dataset 194 Way way = new Way() 195 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way.getPrimitiveId()) 233 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, new Way().getPrimitiveId()); 234 fail(); 235 } catch (IllegalStateException e) { 236 // OK 237 System.out.println(e.getMessage()); 196 238 } 197 239 } … … 202 244 @Test 203 245 public void setRestrictionTagValue() { 204 buildDataSet1() 205 model.populate(rel(1)) 206 207 model.setRestrictionTagValue("no_left_turn") 208 assert model.getRestrictionTagValue() == "no_left_turn";209 210 model.setRestrictionTagValue(null) 211 assert model.getRestrictionTagValue() == "";212 213 model.setRestrictionTagValue(" ") 214 assert model.getRestrictionTagValue() == "";215 216 model.setRestrictionTagValue(" no_right_Turn ") 217 assert model.getRestrictionTagValue() == "no_right_turn";246 buildDataSet1(); 247 model.populate(rel(1)); 248 249 model.setRestrictionTagValue("no_left_turn"); 250 assertEquals("no_left_turn", model.getRestrictionTagValue()); 251 252 model.setRestrictionTagValue(null); 253 assertEquals("", model.getRestrictionTagValue()); 254 255 model.setRestrictionTagValue(" "); 256 assertEquals("", model.getRestrictionTagValue()); 257 258 model.setRestrictionTagValue(" no_right_Turn "); 259 assertEquals("no_right_turn", model.getRestrictionTagValue()); 218 260 } 219 261 … … 223 265 @Test 224 266 public void setVias() { 225 buildDataSet1() 226 model.populate(rel(1)) 267 buildDataSet1(); 268 model.populate(rel(1)); 227 269 228 270 // one node as via - OK 229 model.setVias( [node(22)])230 assert model.getVias() == [node(22)];271 model.setVias(Arrays.asList(node(22))); 272 assertEquals(Arrays.asList(node(22)), model.getVias()); 231 273 232 274 // pass in null as vias -> remove all vias 233 model.setVias(null) 234 assert model.getVias().isEmpty()275 model.setVias(null); 276 assertTrue(model.getVias().isEmpty()); 235 277 236 278 // pass in empty list -> remove all vias 237 model.setVias( [])238 assert model.getVias().isEmpty()279 model.setVias(new ArrayList<>()); 280 assertTrue(model.getVias().isEmpty()); 239 281 240 282 // create a list of vias with a way and twice a node (which doesn't 241 283 // make sense but is technically allowed) 242 284 // 243 createNode(41 )244 createNode(42 )245 createWay(4 ).setNodes([node(41), node(42)])246 model.setVias( [way(4), node(22), node(22)])247 assert model.getVias() == [way(4), node(22), node(22)];285 createNode(41L, null); 286 createNode(42L, null); 287 createWay(4L).setNodes(Arrays.asList(node(41), node(42))); 288 model.setVias(Arrays.asList(way(4), node(22), node(22))); 289 assertEquals(Arrays.asList(way(4), node(22), node(22)), model.getVias()); 248 290 249 291 // null values in the list of vias are skipped 250 model.setVias([null, node(22)]) 251 assert model.getVias() == [node(22)] 252 253 shouldFail(IllegalArgumentException) { 254 // an object which doesn't belong to the same dataset can't 255 // be a via 256 Node n = new Node(new LatLon(0,0)) 257 model.setVias([n]) 292 model.setVias(Arrays.asList(null, node(22))); 293 assertEquals(Arrays.asList(node(22)), model.getVias()); 294 295 try { 296 // an object which doesn't belong to the same dataset can't be a via 297 model.setVias(Arrays.asList(new Node(LatLon.ZERO))); 298 fail(); 299 } catch (IllegalArgumentException e) { 300 // OK 301 System.out.println(e.getMessage()); 258 302 } 259 303 } … … 264 308 @Test 265 309 public void submodelsExist() { 266 assert model.getIssuesModel() != null267 assert model.getRelationMemberEditorModel() != null268 assert model.getTagEditorModel() != null269 270 assert model.getLayer() == layer310 assertNotNull(model.getIssuesModel()); 311 assertNotNull(model.getRelationMemberEditorModel()); 312 assertNotNull(model.getTagEditorModel()); 313 314 assertEquals(layer, model.getLayer()); 271 315 } 272 316 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditorUnitTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 3 import static groovy.test.GroovyAssert.shouldFail 4 import static org.junit.Assert.* 4 import static org.junit.Assert.assertEquals; 5 5 6 import org.junit.* 7 import org.openstreetmap.josm.data.osm.DataSet 8 import org.openstreetmap.josm.gui.layer.OsmDataLayer 9 import org.openstreetmap.josm.testutils.JOSMTestRules 6 import org.junit.Before; 7 import org.junit.Rule; 8 import org.junit.Test; 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 12 11 13 /** 12 14 * Unit test for the {@link TurnRestrictionLegEditor} 13 15 */ 14 class TurnRestrictionLegEditorUnitTest{16 public class TurnRestrictionLegEditorUnitTest { 15 17 16 18 @Rule 17 19 public JOSMTestRules rules = new JOSMTestRules().preferences(); 18 20 19 def navigationControlerMock = [ 20 gotoBasicEditor:{}, 21 gotoAdvancedEditor: {} 22 ] as NavigationControler 23 24 private DataSet ds 25 private OsmDataLayer layer 26 private TurnRestrictionEditorModel model 21 private DataSet ds; 22 private OsmDataLayer layer; 23 private TurnRestrictionEditorModel model; 27 24 28 25 @Before 29 26 public void setUp() { 30 ds = new DataSet() 31 layer = new OsmDataLayer(ds, "test", null) 32 model = new TurnRestrictionEditorModel(layer, navigationControlerMock); 27 ds = new DataSet(); 28 layer = new OsmDataLayer(ds, "test", null); 29 model = new TurnRestrictionEditorModel(layer, new NavigationControler() { 30 @Override 31 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 32 } 33 34 @Override 35 public void gotoBasicEditor() { 36 } 37 38 @Override 39 public void gotoAdvancedEditor() { 40 } 41 }); 33 42 } 34 43 35 44 @Test 36 public void test_Constructor() { 45 public void testConstructor1() { 46 TurnRestrictionLegEditor editor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM); 47 assertEquals(model, editor.getModel()); 48 assertEquals(TurnRestrictionLegRole.FROM, editor.getRole()); 49 } 37 50 38 TurnRestrictionLegEditor editor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM) 51 @Test(expected = IllegalArgumentException.class) 52 public void testConstructor2() { 53 new TurnRestrictionLegEditor(null, TurnRestrictionLegRole.FROM); 54 } 39 55 40 assert editor.getModel() == model 41 assert editor.getRole() == TurnRestrictionLegRole.FROM 42 43 shouldFail(IllegalArgumentException) { 44 editor = new TurnRestrictionLegEditor(null, TurnRestrictionLegRole.FROM) 45 } 46 47 shouldFail(IllegalArgumentException) { 48 editor = new TurnRestrictionLegEditor(model, null) 49 } 56 @Test(expected = IllegalArgumentException.class) 57 public void testConstructor3() { 58 new TurnRestrictionLegEditor(model, null); 50 59 } 51 60 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeRendererTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 3 import static org.junit.Assert.* 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertNull; 4 7 5 import org.junit.* 6 import org.openstreetmap.josm.testutils.JOSMTestRules 8 import javax.swing.JLabel; 7 9 8 class TurnRestrictionTypeRendererTest { 10 import org.junit.Rule; 11 import org.junit.Test; 12 import org.openstreetmap.josm.testutils.JOSMTestRules; 13 14 public class TurnRestrictionTypeRendererTest { 9 15 10 16 @Rule … … 15 21 TurnRestrictionTypeRenderer renderer = new TurnRestrictionTypeRenderer(); 16 22 17 assert renderer.@icons != null18 assert renderer.@icons.get(TurnRestrictionType.NO_LEFT_TURN) != null23 assertNotNull(renderer.icons); 24 assertNotNull(renderer.icons.get(TurnRestrictionType.NO_LEFT_TURN)); 19 25 } 20 26 … … 23 29 TurnRestrictionTypeRenderer renderer = new TurnRestrictionTypeRenderer(); 24 30 25 def c = renderer.getListCellRendererComponent(null, null, 0, false, false)26 assert c.getIcon() == null27 assert c.getText() != null31 JLabel c = (JLabel) renderer.getListCellRendererComponent(null, null, 0, false, false); 32 assertNull(c.getIcon()); 33 assertNotNull(c.getText()); 28 34 29 c = renderer.getListCellRendererComponent(null, "non-standard-value", 0, false, false)30 assert c.getIcon() == null31 assert c.getText() == "non-standard-value"35 c = (JLabel) renderer.getListCellRendererComponent(null, "non-standard-value", 0, false, false); 36 assertNull(c.getIcon()); 37 assertEquals("non-standard-value", c.getText()); 32 38 33 c = renderer.getListCellRendererComponent(null, TurnRestrictionType.NO_LEFT_TURN, 0, false, false)34 assert c.getIcon() == renderer.@icons.get(TurnRestrictionType.NO_LEFT_TURN)35 assert c.getText() == TurnRestrictionType.NO_LEFT_TURN.getDisplayName()39 c = (JLabel) renderer.getListCellRendererComponent(null, TurnRestrictionType.NO_LEFT_TURN, 0, false, false); 40 assertEquals(renderer.icons.get(TurnRestrictionType.NO_LEFT_TURN), c.getIcon()); 41 assertEquals(TurnRestrictionType.NO_LEFT_TURN.getDisplayName(), c.getText()); 36 42 } 37 43 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeTest.java
r32923 r32925 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 import static org.junit.Assert.*3 3 4 import org.junit.* 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNull; 5 6 6 class TurnRestrictionTypeTest { 7 import org.junit.Test; 8 9 public class TurnRestrictionTypeTest { 7 10 8 11 @Test 9 12 public void test_fromTagValue() { 10 13 11 TurnRestrictionType type = TurnRestrictionType.fromTagValue("no_left_turn") 12 assert type == TurnRestrictionType.NO_LEFT_TURN14 TurnRestrictionType type = TurnRestrictionType.fromTagValue("no_left_turn"); 15 assertEquals(TurnRestrictionType.NO_LEFT_TURN, type); 13 16 14 type = TurnRestrictionType.fromTagValue("doesnt_exist") 15 assert type == null17 type = TurnRestrictionType.fromTagValue("doesnt_exist"); 18 assertNull(type); 16 19 17 type = TurnRestrictionType.fromTagValue(null) 18 assert type == null20 type = TurnRestrictionType.fromTagValue(null); 21 assertNull(type); 19 22 } 20 23 }
Note:
See TracChangeset
for help on using the changeset viewer.