Changeset 13489 in josm
- Timestamp:
- 2018-03-03T20:33:09+01:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r13453 r13489 191 191 * Sets a supplier to obtain a command to fix the error. 192 192 * 193 * @param fixingCommand the fix supplier 193 * @param fixingCommand the fix supplier. Can be null 194 194 * @return {@code this} 195 195 */ -
trunk/src/org/openstreetmap/josm/data/validation/tests/InternetTags.java
r12539 r13489 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.util.function.Supplier; 8 9 import org.openstreetmap.josm.command.ChangePropertyCommand; 10 import org.openstreetmap.josm.command.Command; 7 11 import org.openstreetmap.josm.data.osm.Node; 8 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 97 101 String value = v != null ? v : p.get(k); 98 102 if (!validator.isValid(value)) { 103 Supplier<Command> fix = null; 99 104 String errMsg = validator.getErrorMessage(); 100 // Special treatment to allow URLs without protocol. See UrlValidator#isValid101 105 if (tr("URL contains an invalid protocol: {0}", (String) null).equals(errMsg)) { 106 // Special treatment to allow URLs without protocol. See UrlValidator#isValid 102 107 String proto = validator instanceof EmailValidator ? "mailto://" : "http://"; 103 108 return doValidateTag(p, k, proto+value, validator, code); 109 } else if (tr("URL contains an invalid authority: {0}", (String) null).equals(errMsg) 110 && value.contains("\\") && validator.isValid(value.replaceAll("\\\\", "/"))) { 111 // Special treatment to autofix URLs with backslashes. See UrlValidator#isValid 112 errMsg = tr("URL contains backslashes instead of slashes"); 113 fix = () -> new ChangePropertyCommand(p, k, value.replaceAll("\\\\", "/")); 104 114 } 105 115 error = TestError.builder(this, Severity.WARNING, code) 106 116 .message(validator.getValidatorName(), marktr("''{0}'': {1}"), k, errMsg) 107 117 .primitives(p) 118 .fix(fix) 108 119 .build(); 109 120 } -
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r13413 r13489 260 260 261 261 /** 262 * Makes sure the given primitive belongs to a data set. 263 * @param <T> OSM primitive type 264 * @param osm OSM primitive 265 * @return OSM primitive, attached to a new {@code DataSet} 266 */ 267 public static <T extends OsmPrimitive> T addFakeDataSet(T osm) { 268 new DataSet(osm); 269 return osm; 270 } 271 272 /** 262 273 * Creates a new node with the given tags (see {@link OsmUtils#createPrimitive(java.lang.String)}) 263 274 * -
trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
r13079 r13489 247 247 @Test 248 248 public void testDescription() { 249 Node node = new Node(LatLon.ZERO);249 Node node = TestUtils.addFakeDataSet(new Node(LatLon.ZERO)); 250 250 node.put("name", "xy"); 251 new DataSet(node);252 251 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node); 253 252 assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node")); -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/InternetTagsTest.java
r10945 r13489 2 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertNotNull; 5 6 import static org.junit.Assert.assertNull; 7 import static org.openstreetmap.josm.tools.I18n.tr; 6 8 7 9 import org.junit.Rule; 8 10 import org.junit.Test; 9 import org.openstreetmap.josm. data.osm.OsmUtils;11 import org.openstreetmap.josm.TestUtils; 10 12 import org.openstreetmap.josm.data.validation.TestError; 11 13 import org.openstreetmap.josm.data.validation.routines.AbstractValidator; … … 75 77 } 76 78 77 private static void testKey(String key, String value, boolean valid, AbstractValidator validator, int code) { 78 TestError error = TEST.validateTag(OsmUtils.createPrimitive("node "+key+"="+value+""), key, validator, code); 79 /** 80 * Test of invalid slashes. 81 */ 82 @Test 83 public void testInvalidSlashes() { 84 TestError error = testUrl("website", "http:\\\\www.sjoekurs.no", false); 85 assertEquals(tr("''{0}'': {1}", "website", tr("URL contains backslashes instead of slashes")), error.getDescription()); 86 assertNotNull(error.getFix()); 87 } 88 89 private static TestError testKey(String key, String value, boolean valid, AbstractValidator validator, int code) { 90 TestError error = TEST.validateTag(TestUtils.addFakeDataSet(TestUtils.newNode(key+"="+value+"")), key, validator, code); 79 91 if (valid) { 80 92 assertNull(error != null ? error.getMessage() : null, error); … … 82 94 assertNotNull(error); 83 95 } 96 return error; 84 97 } 85 98 86 private static voidtestUrl(String key, String value, boolean valid) {87 testKey(key, value, valid, UrlValidator.getInstance(), InternetTags.INVALID_URL);99 private static TestError testUrl(String key, String value, boolean valid) { 100 return testKey(key, value, valid, UrlValidator.getInstance(), InternetTags.INVALID_URL); 88 101 } 89 102 90 private static voidtestEmail(String key, String value, boolean valid) {91 testKey(key, value, valid, EmailValidator.getInstance(), InternetTags.INVALID_EMAIL);103 private static TestError testEmail(String key, String value, boolean valid) { 104 return testKey(key, value, valid, EmailValidator.getInstance(), InternetTags.INVALID_EMAIL); 92 105 } 93 106 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r13195 r13489 102 102 @Test 103 103 public void testTicket10913() throws ParseException { 104 final OsmPrimitive p = OsmUtils.createPrimitive("way highway=tertiary construction=yes");104 final OsmPrimitive p = TestUtils.addFakeDataSet(TestUtils.newWay("highway=tertiary construction=yes")); 105 105 final TagCheck check = TagCheck.readMapCSS(new StringReader("way {" + 106 106 "throwError: \"error\";" + … … 108 108 "fixAdd: \"highway=construction\";\n" + 109 109 "}")).parseChecks.get(0); 110 new DataSet(p);111 110 final Command command = check.fixPrimitive(p); 112 111 assertTrue(command instanceof SequenceCommand); -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java
r13435 r13489 12 12 import org.junit.Rule; 13 13 import org.junit.Test; 14 import org.openstreetmap.josm. data.osm.DataSet;14 import org.openstreetmap.josm.TestUtils; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 16 import org.openstreetmap.josm.data.osm.OsmUtils; … … 34 34 35 35 List<TestError> test(OsmPrimitive primitive) throws IOException { 36 new DataSet(primitive);37 36 final TagChecker checker = new TagChecker(); 38 37 checker.initialize(); 39 38 checker.startTest(null); 40 checker.check( primitive);39 checker.check(TestUtils.addFakeDataSet(primitive)); 41 40 return checker.getErrors(); 42 41 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java
r12933 r13489 11 11 import org.junit.Rule; 12 12 import org.junit.Test; 13 import org.openstreetmap.josm.TestUtils; 13 14 import org.openstreetmap.josm.data.osm.DataSet; 14 15 import org.openstreetmap.josm.data.osm.Node; … … 91 92 @Test 92 93 public void testAddPrimitivesToRelation() { 93 Relation r = new Relation(1); 94 new DataSet(r); 94 Relation r = TestUtils.addFakeDataSet(new Relation(1)); 95 95 assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.<OsmPrimitive>emptyList())); 96 96 assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(1))));
Note:
See TracChangeset
for help on using the changeset viewer.