Changeset 36280 in osm
- Timestamp:
- 2024-06-07T09:51:18+02:00 (5 months ago)
- Location:
- applications/editors/josm/plugins/reltoolbox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/.classpath
r32680 r36280 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 4 <classpathentry kind="src" output="buildtest" path="test/unit"> 5 <attributes> 6 <attribute name="test" value="true"/> 7 </attributes> 8 </classpathentry> 9 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 5 10 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 11 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 6 12 <classpathentry kind="output" path="build"/> 7 13 </classpath> -
applications/editors/josm/plugins/reltoolbox/.project
r32395 r36280 25 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 27 <nature>org.apache.ivyde.eclipse.ivynature</nature> 27 28 </natures> 28 29 </projectDescription> -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/MultipolygonFixer.java
r36217 r36280 50 50 public Command fixRelation(Relation rel) { 51 51 List<RelationMember> members = fixMultipolygonRoles(rel.getMembers()); 52 if (!members.equals(rel.getMembers())) { 53 final DataSet ds = Utils.firstNonNull(rel.getDataSet(), MainApplication.getLayerManager().getEditDataSet()); 54 return new ChangeMembersCommand(ds, rel, members); 55 } 56 return null; 52 if (members.isEmpty() || members.equals(rel.getMembers())) 53 return null; 54 final DataSet ds = Utils.firstNonNull(rel.getDataSet(), MainApplication.getLayerManager().getEditDataSet()); 55 return new ChangeMembersCommand(ds, rel, members); 57 56 } 58 57 -
applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix/AssociatedStreetFixerTest.java
r36103 r36280 45 45 new RelationMember("street", TestUtils.newWay("highway=residential name=FooBar", TestUtils.newNode(""), TestUtils.newNode(""))), 46 46 new RelationMember("house", TestUtils.newNode(""))); 47 final DataSet ds = new DataSet(); 48 ds.addPrimitiveRecursive(relation); 47 49 return Stream.of(relation); 48 50 } -
applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix/BoundaryFixerTest.java
r36103 r36280 61 61 new RelationMember("outer", TestUtils.newWay("", TestUtils.newNode(""), TestUtils.newNode("")))); 62 62 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"))); 64 64 final Relation relationRelation = TestUtils.newRelation("type=boundary boundary=administrative", 65 65 new RelationMember("subarea", TestUtils.newRelation(""))); -
applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/relationfix/RelationFixerTest.java
r36103 r36280 6 6 import static org.junit.jupiter.api.Assertions.assertFalse; 7 7 import static org.junit.jupiter.api.Assertions.assertNotNull; 8 import static org.junit.jupiter.api.Assertions.assertNull; 8 9 import static org.junit.jupiter.api.Assertions.assertSame; 9 10 import static org.junit.jupiter.api.Assertions.assertTrue; … … 15 16 import org.junit.jupiter.params.ParameterizedTest; 16 17 import org.junit.jupiter.params.provider.MethodSource; 18 import org.openstreetmap.josm.TestUtils; 17 19 import org.openstreetmap.josm.command.Command; 20 import org.openstreetmap.josm.data.coor.LatLon; 18 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.osm.Node; 19 23 import org.openstreetmap.josm.data.osm.Relation; 24 import org.openstreetmap.josm.data.osm.RelationMember; 25 import org.openstreetmap.josm.data.osm.Way; 20 26 import org.openstreetmap.josm.testutils.annotations.Projection; 21 27 … … 25 31 @TestInstance(TestInstance.Lifecycle.PER_CLASS) 26 32 interface RelationFixerTest { 27 28 29 30 31 33 /** 34 * Get the instance to use for checking 35 * @return The fixer instance 36 */ 37 RelationFixer getInstance(); 32 38 33 34 35 36 37 39 /** 40 * A relation that should be fixed by the fixer 41 * @return The bad relation 42 */ 43 Stream<Relation> getBadRelations(); 38 44 39 40 41 42 43 45 /** 46 * A relation that should not be fixed by the fixer 47 * @return The good relation 48 */ 49 Stream<Relation> getGoodRelations(); 44 50 45 46 47 51 default Stream<Relation> getRelations() { 52 return Stream.concat(getBadRelations(), getGoodRelations()); 53 } 48 54 49 50 51 52 53 54 55 @ParameterizedTest 56 @MethodSource("getRelations") 57 default void testIsFixerApplicable(Relation relation) { 58 final RelationFixer fixer = getInstance(); 59 assertTrue(fixer.isFixerApplicable(relation)); 60 } 55 61 56 57 58 59 62 @Test 63 default void testIsFixerApplicableEmptyRelation() { 64 assertFalse(getInstance().isFixerApplicable(new Relation())); 65 } 60 66 61 62 63 64 65 66 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 } 68 74 69 70 71 72 73 75 @ParameterizedTest 76 @MethodSource("getGoodRelations") 77 default void testIsRelationGoodGoodRelation(Relation goodRelation) { 78 assertTrue(getInstance().isRelationGood(goodRelation)); 79 } 74 80 75 76 77 78 79 81 @ParameterizedTest 82 @MethodSource("getBadRelations") 83 default void testIsRelationGoodBadRelation(Relation badRelation) { 84 assertFalse(getInstance().isRelationGood(badRelation)); 85 } 80 86 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 94 127 }
Note:
See TracChangeset
for help on using the changeset viewer.