Changeset 8857 in josm for trunk/test/unit/org/openstreetmap/josm/data/validation/tests
- Timestamp:
- 2015-10-11T17:28:19+02:00 (9 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r8741 r8857 2 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import static org.hamcrest.CoreMatchers.is; 5 import static org.hamcrest.CoreMatchers.notNullValue; 4 import static org.junit.Assert.assertEquals; 6 5 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assert That;6 import static org.junit.Assert.assertNotNull; 8 7 import static org.junit.Assert.assertTrue; 9 8 … … 33 32 34 33 /** 35 * JUnit Test of MapCSSTagChecker.34 * JUnit Test of {@link MapCSSTagChecker}. 36 35 */ 37 36 public class MapCSSTagCheckerTest { … … 53 52 @Test 54 53 public void testNaturalMarsh() throws Exception { 55 56 54 final List<MapCSSTagChecker.TagCheck> checks = MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" + 57 55 "*[natural=marsh] {\n" + … … 61 59 " fixAdd: \"wetland=marsh\";\n" + 62 60 "}")); 63 assert That(checks.size(), is(1));61 assertEquals(1, checks.size()); 64 62 final MapCSSTagChecker.TagCheck check = checks.get(0); 65 assert That(check, notNullValue());66 assert That(check.getDescription(null), is("{0.key}=null is deprecated"));67 assert That(check.fixCommands.get(0).toString(), is("fixRemove: {0.key}"));68 assert That(check.fixCommands.get(1).toString(), is("fixAdd: natural=wetland"));69 assert That(check.fixCommands.get(2).toString(), is("fixAdd: wetland=marsh"));63 assertNotNull(check); 64 assertEquals("{0.key}=null is deprecated", check.getDescription(null)); 65 assertEquals("fixRemove: {0.key}", check.fixCommands.get(0).toString()); 66 assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString()); 67 assertEquals("fixAdd: wetland=marsh", check.fixCommands.get(2).toString()); 70 68 final Node n1 = new Node(); 71 69 n1.put("natural", "marsh"); 72 70 assertTrue(check.evaluate(n1)); 73 assertThat(check.getErrorForPrimitive(n1).getMessage(), is("natural=marsh is deprecated")); 74 assertThat(check.getErrorForPrimitive(n1).getSeverity(), is(Severity.WARNING)); 75 assertThat(check.fixPrimitive(n1).getDescriptionText(), is("Sequence: Fix of natural=marsh is deprecated")); 76 assertThat(((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString(), 77 is("{natural=}")); 71 assertEquals("natural=marsh is deprecated", check.getErrorForPrimitive(n1).getMessage()); 72 assertEquals(Severity.WARNING, check.getErrorForPrimitive(n1).getSeverity()); 73 assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText()); 74 assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString()); 78 75 final Node n2 = new Node(); 79 76 n2.put("natural", "wood"); 80 77 assertFalse(check.evaluate(n2)); 81 assert That(MapCSSTagChecker.TagCheck.insertArguments(check.rule.selectors.get(0),"The key is{0.key}and the value is{0.value}", null),82 is("The key isnaturaland the value ismarsh"));78 assertEquals("The key is natural and the value is marsh", 79 MapCSSTagChecker.TagCheck.insertArguments(check.rule.selectors.get(0), "The key is {0.key} and the value is {0.value}", null)); 83 80 } 84 81 … … 92 89 "}")).get(0); 93 90 final Command command = check.fixPrimitive(p); 94 assertT hat(command instanceof SequenceCommand, is(true));91 assertTrue(command instanceof SequenceCommand); 95 92 final Iterator<PseudoCommand> it = command.getChildren().iterator(); 96 assertT hat(it.next() instanceof ChangePropertyKeyCommand, is(true));97 assertT hat(it.next() instanceof ChangePropertyCommand, is(true));93 assertTrue(it.next() instanceof ChangePropertyKeyCommand); 94 assertTrue(it.next() instanceof ChangePropertyCommand); 98 95 } 99 96 … … 104 101 final OsmPrimitive p = OsmUtils.createPrimitive("way alt_name=Foo"); 105 102 final Collection<TestError> errors = test.getErrorsForPrimitive(p, false); 106 assert That(errors.size(), is(1));107 assert That(errors.iterator().next().getMessage(), is("has alt_name but not name"));108 assert That(errors.iterator().next().getIgnoreSubGroup(), is("3000_*[.+_name][!name]"));103 assertEquals(1, errors.size()); 104 assertEquals("has alt_name but not name", errors.iterator().next().getMessage()); 105 assertEquals("3000_*[.+_name][!name]", errors.iterator().next().getIgnoreSubGroup()); 109 106 } 110 107 … … 115 112 final OsmPrimitive p = OsmUtils.createPrimitive("way highway=footway foot=no"); 116 113 final Collection<TestError> errors = test.getErrorsForPrimitive(p, false); 117 assert That(errors.size(), is(1));118 assert That(errors.iterator().next().getMessage(), is("footway used with foot=no"));119 assert That(errors.iterator().next().getIgnoreSubGroup(), is("3000_way[highway=footway][foot]"));114 assertEquals(1, errors.size()); 115 assertEquals("footway used with foot=no", errors.iterator().next().getMessage()); 116 assertEquals("3000_way[highway=footway][foot]", errors.iterator().next().getIgnoreSubGroup()); 120 117 } 121 118 … … 125 122 "@media (min-josm-version: 1) { *[foo] { throwWarning: \"!\"; } }\n" + 126 123 "@media (min-josm-version: 2147483647) { *[bar] { throwWarning: \"!\"; } }\n"); 127 assert That(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way foo=1"), false).size(), is(1));128 assert That(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way bar=1"), false).size(), is(0));124 assertEquals(1, test.getErrorsForPrimitive(OsmUtils.createPrimitive("way foo=1"), false).size()); 125 assertEquals(0, test.getErrorsForPrimitive(OsmUtils.createPrimitive("way bar=1"), false).size()); 129 126 } 130 127 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
r8680 r8857 4 4 import static org.CustomMatchers.hasSize; 5 5 import static org.CustomMatchers.isEmpty; 6 import static org.hamcrest.CoreMatchers.is;7 6 import static org.hamcrest.CoreMatchers.not; 7 import static org.junit.Assert.assertEquals; 8 8 import static org.junit.Assert.assertFalse; 9 9 import static org.junit.Assert.assertThat; … … 56 56 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty()); 57 57 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1)); 58 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise")59 .get(0).getSeverity( ), is(Severity.OTHER));60 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise")61 .get(0).getPrettifiedValue(), is("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"));62 } 63 64 @Test 65 public void testI18n() throws Exception{58 assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax( 59 key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity()); 60 assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", OPENING_HOUR_TEST.checkOpeningHourSyntax( 61 key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue()); 62 } 63 64 @Test 65 public void testI18n() { 66 66 assertTrue(OPENING_HOUR_TEST.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "de") 67 67 .get(0).toString().contains("Unerwartetes Zeichen")); … … 78 78 final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Tue"); 79 79 assertThat(errors, hasSize(2)); 80 assert That(errors.get(0).getMessage(), is(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)"));81 assert That(errors.get(0).getSeverity(), is(Severity.WARNING));82 assert That(errors.get(1).getMessage(), is(key +80 assertEquals(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)", errors.get(0).getMessage()); 81 assertEquals(Severity.WARNING, errors.get(0).getSeverity()); 82 assertEquals(key + 83 83 " - Mo-Tue <--- (This rule is not very explicit because there is no time selector being used."+ 84 " Please add a time selector to this rule or use a comment to make it more explicit.)")); 85 assert That(errors.get(1).getSeverity(), is(Severity.WARNING));84 " Please add a time selector to this rule or use a comment to make it more explicit.)", errors.get(1).getMessage()); 85 assertEquals(Severity.WARNING, errors.get(1).getSeverity()); 86 86 } 87 87 … … 94 94 final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00"); 95 95 assertThat(errors, hasSize(2)); 96 assert That(errors.get(0).getMessage(), is(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)"));97 assert That(errors.get(0).getSeverity(), is(Severity.WARNING));98 assert That(errors.get(0).getPrettifiedValue(), is("Sa-Su 10:00-20:00"));99 assert That(errors.get(1).getMessage(), is(key + " - Sa-Su 10.00-20. <--- (Please use \":\" as hour/minute-separator)"));100 assert That(errors.get(1).getSeverity(), is(Severity.WARNING));96 assertEquals(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)", errors.get(0).getMessage()); 97 assertEquals(Severity.WARNING, errors.get(0).getSeverity()); 98 assertEquals("Sa-Su 10:00-20:00", errors.get(0).getPrettifiedValue()); 99 assertEquals(key + " - Sa-Su 10.00-20. <--- (Please use \":\" as hour/minute-separator)", errors.get(1).getMessage()); 100 assertEquals(Severity.WARNING, errors.get(1).getSeverity()); 101 101 } 102 102 … … 118 118 final String key = "opening_hours"; 119 119 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1)); 120 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage(),121 is(key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)"));120 assertEquals(key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)", 121 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage()); 122 122 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1)); 123 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage(),124 is(key + " - 5.00 p <--- (hyphen (-) or open end (+)in timerange expected. "125 + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)"));123 assertEquals(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. " 124 + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)", 125 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage()); 126 126 } 127 127 … … 142 142 final String key = "opening_hours"; 143 143 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1)); 144 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity(), is(Severity.OTHER));145 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue(), is("09:00-18:00"));144 assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity()); 145 assertEquals("09:00-18:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue()); 146 146 } 147 147 … … 152 152 public void testCheckOpeningHourSyntaxTicket9367() { 153 153 final String key = "opening_hours"; 154 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity(), is(Severity.WARNING));155 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage(),156 is(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. "157 + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)"));158 assert That(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue(), is("Mo,Tu 04:00-17:00"));154 assertEquals(Severity.WARNING, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity()); 155 assertEquals(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. " 156 + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)", 157 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage()); 158 assertEquals("Mo,Tu 04:00-17:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue()); 159 159 } 160 160 … … 174 174 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", 175 175 OpeningHourTest.CheckMode.BOTH), hasSize(1)); 176 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", 177 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00")); 178 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", 179 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00")); 176 assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00", 177 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", 178 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue()); 179 assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00", 180 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", 181 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue()); 180 182 } 181 183 … … 194 196 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", 195 197 OpeningHourTest.CheckMode.BOTH), hasSize(1)); 196 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", 197 OpeningHourTest.CheckMode.BOTH).get(0).getSeverity(), is(Severity.OTHER)); 198 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", 199 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00")); 198 assertEquals(Severity.OTHER, 199 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", 200 OpeningHourTest.CheckMode.BOTH).get(0).getSeverity()); 201 assertEquals("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00", 202 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", 203 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue()); 200 204 } 201 205 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java
r8753 r8857 2 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import static org.hamcrest.CoreMatchers.is; 5 import static org.junit.Assert.assertThat; 4 import static org.junit.Assert.assertEquals; 6 5 7 6 import java.io.IOException; … … 16 15 import org.openstreetmap.josm.gui.tagging.TaggingPresets; 17 16 17 /** 18 * JUnit Test of {@link TagChecker}. 19 */ 18 20 public class TagCheckerTest { 21 19 22 /** 20 23 * Setup test. … … 37 40 public void testInvalidKey() throws Exception { 38 41 final List<TestError> errors = test(OsmUtils.createPrimitive("node Name=Main")); 39 assert That(errors.size(), is(1));40 assert That(errors.get(0).getMessage(), is("Misspelled property key"));41 assert That(errors.get(0).getDescription(), is("Key 'Name' looks like 'name'."));42 assertEquals(1, errors.size()); 43 assertEquals("Misspelled property key", errors.get(0).getMessage()); 44 assertEquals("Key 'Name' looks like 'name'.", errors.get(0).getDescription()); 42 45 } 43 46 … … 45 48 public void testMisspelledKey() throws Exception { 46 49 final List<TestError> errors = test(OsmUtils.createPrimitive("node landuse;=forest")); 47 assert That(errors.size(), is(1));48 assert That(errors.get(0).getMessage(), is("Misspelled property key"));49 assert That(errors.get(0).getDescription(), is("Key 'landuse;' looks like 'landuse'."));50 assertEquals(1, errors.size()); 51 assertEquals("Misspelled property key", errors.get(0).getMessage()); 52 assertEquals("Key 'landuse;' looks like 'landuse'.", errors.get(0).getDescription()); 50 53 } 51 54 … … 53 56 public void testTranslatedNameKey() throws Exception { 54 57 final List<TestError> errors = test(OsmUtils.createPrimitive("node namez=Baz")); 55 assert That(errors.size(), is(1));56 assert That(errors.get(0).getMessage(), is("Presets do not contain property key"));57 assert That(errors.get(0).getDescription(), is("Key 'namez' not in presets."));58 assertEquals(1, errors.size()); 59 assertEquals("Presets do not contain property key", errors.get(0).getMessage()); 60 assertEquals("Key 'namez' not in presets.", errors.get(0).getDescription()); 58 61 } 59 62 … … 61 64 public void testMisspelledTag() throws Exception { 62 65 final List<TestError> errors = test(OsmUtils.createPrimitive("node landuse=forrest")); 63 assert That(errors.size(), is(1));64 assert That(errors.get(0).getMessage(), is("Presets do not contain property value"));65 assert That(errors.get(0).getDescription(), is("Value 'forrest' for key 'landuse' not in presets."));66 assertEquals(1, errors.size()); 67 assertEquals("Presets do not contain property value", errors.get(0).getMessage()); 68 assertEquals("Value 'forrest' for key 'landuse' not in presets.", errors.get(0).getDescription()); 66 69 } 67 68 70 }
Note:
See TracChangeset
for help on using the changeset viewer.