Ticket #17567: 17567-v2.patch

File 17567-v2.patch, 9.5 KB (added by GerdP, 5 years ago)

Proposed changes

  • src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java

     
    3939public class RelationChecker extends Test {
    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 */
    5555    public static final int RELATION_UNKNOWN = 1707;
    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
    6062    /**
     
    210212    private boolean checkMemberExpressionAndType(Map<Role, String> allroles, RelationMember member, Relation n) {
    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;
    216218        // iterate through all of the role definition within preset
     
    243245                            // we still need to iterate further, as we might have
    244246                            // different present, 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)
    251253                                    .build();
     
    279281
    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)
    285287                        .build());
     
    292294     *
    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) {
    298300        // go through all members of relation
     
    332334                            .build());
    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());
    338340                }
  • test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.java

     
    77
    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;
    1817
     18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     19
    1920/**
    2021 * Unit tests of {@link RelationChecker} class.
    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;
    3835    }
     
    103100
    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    }
    109106
     
    130127
    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
    136133    @Test
     
    140137
    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
    146143    @Test
     
    168165
    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
    174171        r.removeMember(3);
     
    175172        r.addMember(new RelationMember("stop", createPrimitive("way no-rail-way=yes")));
    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
    181178        r.removeMember(3);
    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    }
    188185}