Changeset 16178 in josm


Ignore:
Timestamp:
2020-03-20T21:06:06+01:00 (2 years ago)
Author:
Don-vip
Message:

fix #18956 - allow TestError to be built with an empty list of primitives + make OpeningHourTestTest work on Windows

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r15939 r16178  
    220220         *
    221221         * @return a new test error with the specified values
    222          * @throws IllegalArgumentException when {@link #message} or {@link #primitives} is null/empty.
     222         * @throws IllegalArgumentException when {@link #message} or {@link #primitives} is null.
    223223         */
    224224        public TestError build() {
    225225            CheckParameterUtil.ensureParameterNotNull(message, "message not set");
    226226            CheckParameterUtil.ensureParameterNotNull(primitives, "primitives not set");
    227             CheckParameterUtil.ensureThat(!primitives.isEmpty(), "primitives is empty");
    228227            if (this.highlighted == null) {
    229228                this.highlighted = Collections.emptySet();
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r16154 r16178  
    4646     * @param message The error message
    4747     * @param key The incriminated key, used for display.
     48     * @param value The incriminated value, used for comparison with prettified value.
    4849     * @param prettifiedValue The prettified value
    4950     * @param p The incriminated OSM primitive.
    5051     * @return The real test error given to JOSM validator. Can be fixable or not if a prettified values has been determined.
    5152     */
    52     private TestError createTestError(Severity severity, String message, String key, String prettifiedValue, OsmPrimitive p) {
     53    private TestError createTestError(Severity severity, String message, String key, String value, String prettifiedValue, OsmPrimitive p) {
    5354        final TestError.Builder error = TestError.builder(this, severity, 2901)
    5455                .message(tr("Opening hours syntax"), message) // todo obtain English message for ignore functionality
    55                 .primitives(p);
    56         if (prettifiedValue == null || prettifiedValue.equals(p.get(key))) {
     56                .primitives(p != null ? new OsmPrimitive[] {p} : new OsmPrimitive[] {});
     57        if (p == null || prettifiedValue == null || prettifiedValue.equals(value)) {
    5758            return error.build();
    5859        } else {
     
    9697            }
    9798        } catch (ParseException e) {
    98             return Collections.singletonList(createTestError(Severity.WARNING, e.getMessage(), key, prettifiedValue, p));
     99            return Collections.singletonList(createTestError(Severity.WARNING, e.getMessage(), key, value, prettifiedValue, p));
    99100        }
    100101
    101         if (!includeOtherSeverityChecks() || Objects.equals(value, prettifiedValue) || p == null) {
     102        if (!includeOtherSeverityChecks() || Objects.equals(value, prettifiedValue)) {
    102103            return Collections.emptyList();
    103104        } else {
    104105            final String message = tr("{0} value can be prettified", key);
    105             return Collections.singletonList(createTestError(Severity.OTHER, message, key, prettifiedValue, p));
     106            return Collections.singletonList(createTestError(Severity.OTHER, message, key, value, prettifiedValue, p));
    106107        }
    107108    }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r16114 r16178  
    8383        final String key = "opening_hours";
    8484        String value = ".";
    85         assertEquals("Vorgefunden wurde:  \".\" \". \" in Zeile 0, Spalte 0\nErwartet wurde: <EOF>",
     85        assertEquals(String.format("Vorgefunden wurde:  \".\" \". \" in Zeile 0, Spalte 0%nErwartet wurde: <EOF>"),
    8686                checkOpeningHourSyntax(key, value, Locale.GERMAN).get(0).getDescription());
    87         assertEquals("Encountered:  \".\" \". \" at line 0, column 0\nWas expecting: <EOF>",
     87        assertEquals(String.format("Encountered:  \".\" \". \" at line 0, column 0%nWas expecting: <EOF>"),
    8888                checkOpeningHourSyntax(key, value, Locale.ENGLISH).get(0).getDescription());
    8989        value = "Mon-Thu 12-18";
     
    140140        final String key = "opening_hours";
    141141        assertThat(checkOpeningHourSyntax(key, "badtext"), hasSize(1));
    142         assertEquals("Encountered:  <UNEXPECTED_CHAR> \"b \" at line 0, column 0\nWas expecting: <EOF>",
     142        assertEquals(String.format("Encountered:  <UNEXPECTED_CHAR> \"b \" at line 0, column 0%nWas expecting: <EOF>"),
    143143                checkOpeningHourSyntax(key, "badtext").get(0).getDescription().trim());
    144144        assertThat(checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
    145         assertEquals("Encountered:  <UNEXPECTED_CHAR> \"p \" at line 1, column 2\nWas expecting: <EOF>",
     145        assertEquals(String.format("Encountered:  <UNEXPECTED_CHAR> \"p \" at line 1, column 2%nWas expecting: <EOF>"),
    146146                checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getDescription());
    147147    }
Note: See TracChangeset for help on using the changeset viewer.