| 1 | package org.openstreetmap.josm.data.validation.tests;
|
|---|
| 2 |
|
|---|
| 3 | import static org.hamcrest.CoreMatchers.is;
|
|---|
| 4 | import static org.junit.Assert.assertThat;
|
|---|
| 5 |
|
|---|
| 6 | import java.io.IOException;
|
|---|
| 7 | import java.util.List;
|
|---|
| 8 |
|
|---|
| 9 | import org.junit.BeforeClass;
|
|---|
| 10 | import org.junit.Test;
|
|---|
| 11 | import org.openstreetmap.josm.JOSMFixture;
|
|---|
| 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
|---|
| 14 | import org.openstreetmap.josm.data.validation.TestError;
|
|---|
| 15 | import org.openstreetmap.josm.gui.tagging.TaggingPresets;
|
|---|
| 16 |
|
|---|
| 17 | public class TagCheckerTest {
|
|---|
| 18 | /**
|
|---|
| 19 | * Setup test.
|
|---|
| 20 | */
|
|---|
| 21 | @BeforeClass
|
|---|
| 22 | public static void setUp() {
|
|---|
| 23 | JOSMFixture.createUnitTestFixture().init();
|
|---|
| 24 | TaggingPresets.readFromPreferences();
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | List<TestError> test(OsmPrimitive primitive) throws IOException {
|
|---|
| 28 | final TagChecker checker = new TagChecker();
|
|---|
| 29 | checker.initialize();
|
|---|
| 30 | checker.startTest(null);
|
|---|
| 31 | checker.check(primitive);
|
|---|
| 32 | return checker.getErrors();
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | @Test
|
|---|
| 36 | public void testInvalidKey() throws Exception {
|
|---|
| 37 | final List<TestError> errors = test(OsmUtils.createPrimitive("node Name=Main"));
|
|---|
| 38 | assertThat(errors.size(), is(2));
|
|---|
| 39 | assertThat(errors.get(0).getMessage(), is("Invalid property key"));
|
|---|
| 40 | assertThat(errors.get(0).getDescription(), is("Key 'Name' invalid."));
|
|---|
| 41 | assertThat(errors.get(1).getMessage(), is("Misspelled property key"));
|
|---|
| 42 | assertThat(errors.get(1).getDescription(), is("Key 'Name' looks like 'name'."));
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | @Test
|
|---|
| 46 | public void testMisspelled() throws Exception {
|
|---|
| 47 | final List<TestError> errors = test(OsmUtils.createPrimitive("node landuse;=forest"));
|
|---|
| 48 | assertThat(errors.size(), is(1));
|
|---|
| 49 | assertThat(errors.get(0).getMessage(), is("Misspelled property key"));
|
|---|
| 50 | assertThat(errors.get(0).getDescription(), is("Key 'landuse;' looks like 'landuse'."));
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | }
|
|---|