Ignore:
Timestamp:
2024-06-07T09:51:18+02:00 (4 months ago)
Author:
GerdP
Message:

fix #23715: Plugin Relation Toolbox began to remove multipuligons

  • don't change member list to empty list if relation is not valid
  • add/improve unit tests
  • fix project files to allow running unit tests in Eclipse
Location:
applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix/AssociatedStreetFixerTest.java

    r36103 r36280  
    4545                new RelationMember("street", TestUtils.newWay("highway=residential name=FooBar", TestUtils.newNode(""), TestUtils.newNode(""))),
    4646                new RelationMember("house", TestUtils.newNode("")));
     47        final DataSet ds = new DataSet();
     48        ds.addPrimitiveRecursive(relation);
    4749        return Stream.of(relation);
    4850    }
  • applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix/BoundaryFixerTest.java

    r36103 r36280  
    6161                new RelationMember("outer", TestUtils.newWay("", TestUtils.newNode(""), TestUtils.newNode(""))));
    6262        final Relation nodeRelation = TestUtils.newRelation("type=boundary boundary=administrative",
    63                 new RelationMember("admin_centre", TestUtils.newNode("")));
     63                new RelationMember("admin_centre", TestUtils.newNode("place=city")));
    6464        final Relation relationRelation = TestUtils.newRelation("type=boundary boundary=administrative",
    6565                new RelationMember("subarea", TestUtils.newRelation("")));
  • applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix/RelationFixerTest.java

    r36103 r36280  
    66import static org.junit.jupiter.api.Assertions.assertFalse;
    77import static org.junit.jupiter.api.Assertions.assertNotNull;
     8import static org.junit.jupiter.api.Assertions.assertNull;
    89import static org.junit.jupiter.api.Assertions.assertSame;
    910import static org.junit.jupiter.api.Assertions.assertTrue;
     
    1516import org.junit.jupiter.params.ParameterizedTest;
    1617import org.junit.jupiter.params.provider.MethodSource;
     18import org.openstreetmap.josm.TestUtils;
    1719import org.openstreetmap.josm.command.Command;
     20import org.openstreetmap.josm.data.coor.LatLon;
    1821import org.openstreetmap.josm.data.osm.DataSet;
     22import org.openstreetmap.josm.data.osm.Node;
    1923import org.openstreetmap.josm.data.osm.Relation;
     24import org.openstreetmap.josm.data.osm.RelationMember;
     25import org.openstreetmap.josm.data.osm.Way;
    2026import org.openstreetmap.josm.testutils.annotations.Projection;
    2127
     
    2531@TestInstance(TestInstance.Lifecycle.PER_CLASS)
    2632interface RelationFixerTest {
    27     /**
    28     * Get the instance to use for checking
    29     * @return The fixer instance
    30     */
    31     RelationFixer getInstance();
     33        /**
     34        * Get the instance to use for checking
     35        * @return The fixer instance
     36        */
     37        RelationFixer getInstance();
    3238
    33     /**
    34     * A relation that should be fixed by the fixer
    35     * @return The bad relation
    36     */
    37     Stream<Relation> getBadRelations();
     39        /**
     40        * A relation that should be fixed by the fixer
     41        * @return The bad relation
     42        */
     43        Stream<Relation> getBadRelations();
    3844
    39     /**
    40     * A relation that should not be fixed by the fixer
    41     * @return The good relation
    42     */
    43     Stream<Relation> getGoodRelations();
     45        /**
     46        * A relation that should not be fixed by the fixer
     47        * @return The good relation
     48        */
     49        Stream<Relation> getGoodRelations();
    4450
    45     default Stream<Relation> getRelations() {
    46         return Stream.concat(getBadRelations(), getGoodRelations());
    47     }
     51        default Stream<Relation> getRelations() {
     52                return Stream.concat(getBadRelations(), getGoodRelations());
     53        }
    4854
    49     @ParameterizedTest
    50     @MethodSource("getRelations")
    51     default void testIsFixerApplicable(Relation relation) {
    52         final RelationFixer fixer = getInstance();
    53         assertTrue(fixer.isFixerApplicable(relation));
    54     }
     55        @ParameterizedTest
     56        @MethodSource("getRelations")
     57        default void testIsFixerApplicable(Relation relation) {
     58                final RelationFixer fixer = getInstance();
     59                assertTrue(fixer.isFixerApplicable(relation));
     60        }
    5561
    56     @Test
    57     default void testIsFixerApplicableEmptyRelation() {
    58         assertFalse(getInstance().isFixerApplicable(new Relation()));
    59     }
     62        @Test
     63        default void testIsFixerApplicableEmptyRelation() {
     64                assertFalse(getInstance().isFixerApplicable(new Relation()));
     65        }
    6066
    61     @ParameterizedTest
    62     @MethodSource("getGoodRelations")
    63     default void testGoodRelationMatches(Relation goodRelation) {
    64         final RelationFixer fixer = getInstance();
    65         assertTrue(fixer.isFixerApplicable(goodRelation));
    66         assertFalse(fixer.isFixerApplicable(new Relation()));
    67     }
     67        @ParameterizedTest
     68        @MethodSource("getGoodRelations")
     69        default void testGoodRelationMatches(Relation goodRelation) {
     70                final RelationFixer fixer = getInstance();
     71                assertTrue(fixer.isFixerApplicable(goodRelation));
     72                assertFalse(fixer.isFixerApplicable(new Relation()));
     73        }
    6874
    69     @ParameterizedTest
    70     @MethodSource("getGoodRelations")
    71     default void testIsRelationGoodGoodRelation(Relation goodRelation) {
    72         assertTrue(getInstance().isRelationGood(goodRelation));
    73     }
     75        @ParameterizedTest
     76        @MethodSource("getGoodRelations")
     77        default void testIsRelationGoodGoodRelation(Relation goodRelation) {
     78                assertTrue(getInstance().isRelationGood(goodRelation));
     79        }
    7480
    75     @ParameterizedTest
    76     @MethodSource("getBadRelations")
    77     default void testIsRelationGoodBadRelation(Relation badRelation) {
    78         assertFalse(getInstance().isRelationGood(badRelation));
    79     }
     81        @ParameterizedTest
     82        @MethodSource("getBadRelations")
     83        default void testIsRelationGoodBadRelation(Relation badRelation) {
     84                assertFalse(getInstance().isRelationGood(badRelation));
     85        }
    8086
    81     @MethodSource("getBadRelations")
    82     @ParameterizedTest
    83     @Projection
    84     default void testFixBadRelation(Relation badRelation) {
    85         final DataSet ds = badRelation.getDataSet();
    86         final RelationFixer fixer = getInstance();
    87         final Command command = fixer.fixRelation(badRelation);
    88         assertNotNull(command);
    89         assertDoesNotThrow(command::executeCommand);
    90         final Relation relation = ds.getRelations().stream().filter(fixer::isFixerApplicable).findFirst().orElseThrow(AssertionError::new);
    91         assertAll(relation.getMemberPrimitives().stream()
    92                 .map(member -> () -> assertSame(ds, member.getDataSet(), member + " does not have the same dataset as " + relation)));
    93     }
     87        @MethodSource("getBadRelations")
     88        @ParameterizedTest
     89        @Projection
     90        default void testFixBadRelation(Relation badRelation) {
     91                final DataSet ds = badRelation.getDataSet();
     92                final RelationFixer fixer = getInstance();
     93                final Command command = fixer.fixRelation(badRelation);
     94                assertNotNull(command);
     95                assertDoesNotThrow(command::executeCommand);
     96                final Relation relation = ds.getRelations().stream().filter(fixer::isFixerApplicable).findFirst().orElseThrow(AssertionError::new);
     97                assertAll(relation.getMemberPrimitives().stream()
     98                                .map(member -> () -> assertSame(ds, member.getDataSet(), member + " does not have the same dataset as " + relation)));
     99        }
     100
     101        @ParameterizedTest
     102        @MethodSource("getGoodRelations")
     103        default void testGoodRelationNotFixed(Relation goodRelation) {
     104                assertTrue(getInstance().isRelationGood(goodRelation));
     105                final DataSet ds = goodRelation.getDataSet();
     106                final RelationFixer fixer = getInstance();
     107                final Command command = fixer.fixRelation(goodRelation);
     108                assertNull(command);
     109        }
     110
     111        @ParameterizedTest
     112        @MethodSource("getGoodRelations")
     113        default void testAddBadMember(Relation goodRelation) {
     114                // regression test for #23715
     115                final DataSet ds = goodRelation.getDataSet();
     116                assertTrue(getInstance().isRelationGood(goodRelation));
     117                Node n1 = new Node(new LatLon(2.0, 2.0));
     118                Node n2 = new Node(new LatLon(2.0, 3.0));
     119                Way w1 = TestUtils.newWay("", n1, n2);
     120                ds.addPrimitiveRecursive(w1);
     121                goodRelation.addMember(new RelationMember("", w1));
     122                final RelationFixer fixer = getInstance();
     123                final Command command = fixer.fixRelation(goodRelation);
     124                assertNull(command);
     125        }
     126
    94127}
Note: See TracChangeset for help on using the changeset viewer.