Changeset 6533 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r6494 r6533 198 198 errors.add(new OpeningHoursTestError(i.toString().trim(), Severity.WARNING, prettifiedValue)); 199 199 } 200 if (errors.isEmpty() && prettifiedValue != null && !value.equals(prettifiedValue)) { 201 errors.add(new OpeningHoursTestError(tr("opening_hours value can be prettified"), Severity.OTHER, prettifiedValue)); 202 } 200 203 return errors; 201 204 } catch (final Exception ex) { -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
r6471 r6533 5 5 import org.junit.Test; 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.data.Preferences;8 7 import org.openstreetmap.josm.data.validation.Severity; 9 8 10 9 import java.util.List; 11 10 11 import static org.CustomMatchers.hasSize; 12 import static org.CustomMatchers.isEmpty; 12 13 import static org.hamcrest.CoreMatchers.is; 14 import static org.hamcrest.CoreMatchers.not; 13 15 import static org.junit.Assert.assertThat; 14 16 … … 30 32 final String key = "opening_hours"; 31 33 // frequently used tags according to http://taginfo.openstreetmap.org/keys/opening_hours#values 32 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "24/7").isEmpty(), is(true)); 33 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00").isEmpty(), is(true)); 34 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "09:00-21:00").isEmpty(), is(true)); 35 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").isEmpty(), is(true)); 34 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "24/7"), isEmpty()); 35 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00"), isEmpty()); 36 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty()); 37 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty()); 38 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1)); 39 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity(), is(Severity.OTHER)); 40 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue(), is("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise")); 36 41 } 37 42 … … 40 45 final String key = "opening_hours"; 41 46 final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Tue"); 42 assertThat(errors .size(), is(1));47 assertThat(errors, hasSize(1)); 43 48 assertThat(errors.get(0).getMessage(), is("Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)")); 44 49 assertThat(errors.get(0).getSeverity(), is(Severity.WARNING)); … … 49 54 final String key = "opening_hours"; 50 55 final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00"); 51 assertThat(errors .size(), is(2));56 assertThat(errors, hasSize(2)); 52 57 assertThat(errors.get(0).getMessage(), is("Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)")); 53 58 assertThat(errors.get(0).getSeverity(), is(Severity.WARNING)); … … 59 64 @Test 60 65 public void testCheckOpeningHourSyntax4() throws Exception { 61 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, null) .isEmpty(), is(true));62 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, "") .isEmpty(), is(true));63 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, " ") .isEmpty(), is(true));66 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, null), isEmpty()); 67 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, ""), isEmpty()); 68 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, " "), isEmpty()); 64 69 } 65 70 … … 67 72 public void testCheckOpeningHourSyntax5() throws Exception { 68 73 final String key = "opening_hours"; 69 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext") .size(), is(1));74 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1)); 70 75 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage(), 71 76 is("opening_hours - ba <--- (Unexpected token: \"b\" This means that the syntax is not valid at that point or it is currently not supported.)")); 72 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m") .size(), is(1));77 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1)); 73 78 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage(), 74 79 is("opening_hours - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)")); … … 78 83 public void testCheckOpeningHourSyntax6() throws Exception { 79 84 final String key = "opening_hours"; 80 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\"").isEmpty(), is(true)); 85 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\""), isEmpty()); 86 } 87 88 @Test 89 public void testCheckOpeningHourSyntax7() throws Exception { 90 final String key = "opening_hours"; 91 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1)); 92 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity(), is(Severity.OTHER)); 93 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue(), is("09:00-18:00")); 81 94 } 82 95 … … 93 106 final String key = "service_times"; 94 107 // frequently used tags according to http://taginfo.openstreetmap.org/keys/service_times#values 95 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(true)); 96 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(false)); 97 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(true)); 98 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(true)); 99 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(true)); 108 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH), isEmpty()); 109 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH), not(isEmpty())); 110 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH), isEmpty()); 111 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH), isEmpty()); 112 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00", OpeningHourTest.CheckMode.BOTH), isEmpty()); 113 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH), hasSize(1)); 114 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00")); 115 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00")); 100 116 } 101 117 … … 104 120 final String key = "collection_times"; 105 121 // frequently used tags according to http://taginfo.openstreetmap.org/keys/collection_times#values 106 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(true)); 107 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(false)); 108 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(false)); 109 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).isEmpty(), is(true)); 122 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH), isEmpty()); 123 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH), not(isEmpty())); 124 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH), not(isEmpty())); 125 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH), isEmpty()); 126 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH), hasSize(1)); 127 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).get(0).getSeverity(), is(Severity.OTHER)); 128 assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00")); 110 129 } 111 130 }
Note:
See TracChangeset
for help on using the changeset viewer.