Changeset 14990 in josm


Ignore:
Timestamp:
2019-04-14T17:29:33+02:00 (5 years ago)
Author:
GerdP
Message:

see #17567: improve messages created by RelationChecker

  • new error code 1709 for " Type {0} of relation member with role {1} does not match accepted types {2} in preset {3}"
  • role type -> role
  • replace template by preset where appropriate
  • adapt unit test and improve speed
Location:
trunk
Files:
2 edited

Legend:

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

    r14968 r14990  
    4040
    4141    // CHECKSTYLE.OFF: SingleSpaceSeparator
    42     /** Role {0} unknown in templates {1} */
     42    /** Role ''{0}'' is not in templates ''{1}'' */
    4343    public static final int ROLE_UNKNOWN     = 1701;
    44     /** Empty role type found when expecting one of {0} */
     44    /** Empty role found when expecting one of ''{0}'' */
    4545    public static final int ROLE_EMPTY       = 1702;
    46     /** Role member does not match expression {0} in template {1} */
    47     public static final int WRONG_TYPE       = 1703;
    48     /** Number of {0} roles too high ({1}) */
     46    /** Role of relation member does not match template expression ''{0}'' in preset {1} */
     47    public static final int WRONG_ROLE       = 1708;
     48    /** Number of ''{0}'' roles too high ({1}) */
    4949    public static final int HIGH_COUNT       = 1704;
    50     /** Number of {0} roles too low ({1}) */
     50    /** Number of ''{0}'' roles too low ({1}) */
    5151    public static final int LOW_COUNT        = 1705;
    52     /** Role {0} missing */
     52    /** Role ''{0}'' missing */
    5353    public static final int ROLE_MISSING     = 1706;
    5454    /** Relation type is unknown */
     
    5656    /** Relation is empty */
    5757    public static final int RELATION_EMPTY   = 1708;
     58    /** Type ''{0}'' of relation member with role ''{1}'' does not match accepted types ''{2}'' in preset {3} */
     59    public static final int WRONG_TYPE       = 1709;
    5860    // CHECKSTYLE.ON: SingleSpaceSeparator
    5961
     
    211213        String role = member.getRole();
    212214        String name = null;
    213         // Set of all accepted types in template
     215        // Set of all accepted types in preset
    214216        Collection<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);
    215217        TestError possibleMatchError = null;
     
    242244                            // possible match error
    243245                            // we still need to iterate further, as we might have
    244                             // different present, for which memberExpression will match
     246                            // different preset, for which memberExpression will match
    245247                            // but stash the error in case no better reason will be found later
    246                             possibleMatchError = TestError.builder(this, Severity.WARNING, WRONG_TYPE)
     248                            possibleMatchError = TestError.builder(this, Severity.WARNING, WRONG_ROLE)
    247249                                    .message(ROLE_VERIF_PROBLEM_MSG,
    248                                             marktr("Role of relation member does not match expression ''{0}'' in template {1}"),
     250                                            marktr("Role of relation member does not match template expression ''{0}'' in preset {1}"),
    249251                                            r.memberExpression, name)
    250252                                    .primitives(member.getMember().isUsable() ? member.getMember() : n)
     
    280282                errors.add(TestError.builder(this, Severity.WARNING, WRONG_TYPE)
    281283                        .message(ROLE_VERIF_PROBLEM_MSG,
    282                             marktr("Type ''{0}'' of relation member with role ''{1}'' does not match accepted types ''{2}'' in template {3}"),
     284                            marktr("Type ''{0}'' of relation member with role ''{1}'' does not match accepted types ''{2}'' in preset {3}"),
    283285                            member.getType(), member.getRole(), typesStr, name)
    284286                        .primitives(member.getMember().isUsable() ? member.getMember() : n)
     
    293295     * @param n relation to validate
    294296     * @param allroles contains presets for specified relation
    295      * @param map contains statistics of occurrences of specified role types in relation
     297     * @param map contains statistics of occurrences of specified role in relation
    296298     */
    297299    private void checkRoles(Relation n, Map<Role, String> allroles, Map<String, RoleInfo> map) {
     
    333335                } else {
    334336                    errors.add(TestError.builder(this, Severity.WARNING, ROLE_EMPTY)
    335                             .message(ROLE_VERIF_PROBLEM_MSG, marktr("Empty role type found when expecting one of ''{0}''"), templates)
     337                            .message(ROLE_VERIF_PROBLEM_MSG, marktr("Empty role found when expecting one of ''{0}''"), templates)
    336338                            .primitives(n)
    337339                            .build());
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.java

    r14969 r14990  
    88import java.util.List;
    99
    10 import org.junit.Before;
     10import org.junit.Rule;
    1111import org.junit.Test;
    12 import org.openstreetmap.josm.JOSMFixture;
    1312import org.openstreetmap.josm.data.osm.Relation;
    1413import org.openstreetmap.josm.data.osm.RelationMember;
    1514import org.openstreetmap.josm.data.osm.Way;
    1615import org.openstreetmap.josm.data.validation.TestError;
    17 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
     16import org.openstreetmap.josm.testutils.JOSMTestRules;
     17
     18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1819
    1920/**
     
    2122 */
    2223public class RelationCheckerTest {
    23 
    2424    /**
    2525     * Setup test.
    2626     */
    27     @Before
    28     public void setUp() {
    29         JOSMFixture.createUnitTestFixture().init();
    30         getRelationChecker();
    31     }
     27    @Rule
     28    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     29    public JOSMTestRules rule = new JOSMTestRules().presets();
    3230
    3331    private static RelationChecker getRelationChecker() {
    3432        RelationChecker checker = new RelationChecker();
    35         TaggingPresets.readFromPreferences();
    3633        checker.initialize();
    3734        return checker;
     
    104101        List<TestError> errors = testRelation(r);
    105102        assertEquals(1, errors.size());
    106         assertEquals("Type 'relation' of relation member with role 'via' does not match accepted types 'node/way' in template Turn Restriction",
     103        assertEquals("Type 'relation' of relation member with role 'via' does not match accepted types 'node/way' in preset Turn Restriction",
    107104                errors.get(0).getDescription());
    108105    }
     
    131128        List<TestError> errors = testRelation(r);
    132129        assertEquals(1, errors.size());
    133         assertTrue(errors.get(0).getDescription().startsWith("Empty role type found when expecting one of"));
     130        assertTrue(errors.get(0).getDescription().startsWith("Empty role found when expecting one of"));
    134131    }
    135132
     
    141138        List<TestError> errors = testRelation(r);
    142139        assertEquals(1, errors.size());
    143         assertEquals("Role of relation member does not match expression 'power' in template Power Route", errors.get(0).getDescription());
     140        assertEquals("Role of relation member does not match template expression 'power' in preset Power Route", errors.get(0).getDescription());
    144141    }
    145142
     
    169166        r.addMember(new RelationMember("", createPrimitive("way no-rail-way=yes")));
    170167        assertEquals(1, testRelation(r).size());
    171         assertEquals("Role of relation member does not match expression 'railway' in template Public Transport Route (Rail)",
     168        assertEquals("Role of relation member does not match template expression 'railway' in preset Public Transport Route (Rail)",
    172169                testRelation(r).get(0).getDescription());
    173170
     
    176173        assertEquals(1, testRelation(r).size());
    177174        assertEquals(
    178                 "Type 'way' of relation member with role 'stop' does not match accepted types 'node' in template Public Transport Route (Rail)",
     175                "Type 'way' of relation member with role 'stop' does not match accepted types 'node' in preset Public Transport Route (Rail)",
    179176                testRelation(r).get(0).getDescription());
    180177
     
    182179        r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position bus=yes")));
    183180        assertEquals(1, testRelation(r).size());
    184         assertEquals("Role of relation member does not match expression 'public_transport=stop_position && "+
    185                 "(train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes)' in template Public Transport Route (Rail)",
     181        assertEquals("Role of relation member does not match template expression 'public_transport=stop_position && "+
     182                "(train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes)' in preset Public Transport Route (Rail)",
    186183                testRelation(r).get(0).getDescription());
    187184    }
Note: See TracChangeset for help on using the changeset viewer.