Changeset 18615 in josm for trunk/test/unit


Ignore:
Timestamp:
2022-12-13T22:24:53+01:00 (17 months ago)
Author:
taylor.smock
Message:

Fix #22504: Circularize multiple selected ways (patch by qeef, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/AlignInCircleActionTest.java

    r17394 r18615  
    22package org.openstreetmap.josm.actions;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56import static org.junit.jupiter.api.Assertions.assertFalse;
     
    78import static org.junit.jupiter.api.Assertions.assertNull;
    89import static org.junit.jupiter.api.Assertions.assertTrue;
    9 
     10import static org.junit.jupiter.api.Assertions.fail;
     11
     12import java.io.IOException;
     13import java.io.InputStream;
    1014import java.nio.file.Files;
    1115import java.nio.file.Paths;
     
    1822import org.openstreetmap.josm.actions.AlignInCircleAction.InvalidSelection;
    1923import org.openstreetmap.josm.command.Command;
     24import org.openstreetmap.josm.data.coor.ILatLon;
    2025import org.openstreetmap.josm.data.osm.DataSet;
    2126import org.openstreetmap.josm.data.osm.Node;
    2227import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2328import org.openstreetmap.josm.data.osm.Way;
     29import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     30import org.openstreetmap.josm.io.IllegalDataException;
    2431import org.openstreetmap.josm.io.OsmReader;
    2532import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    182189        }
    183190    }
     191
     192    /**
     193     * Test case: Circularize a batch of (two) buildings.
     194     * @throws IOException if the test file could not be read
     195     * @throws IllegalDataException if the test file has been corrupted
     196     */
     197    @Test
     198    void testMultipleWaysSelected() throws IOException, IllegalDataException {
     199        final DataSet before;
     200        try (InputStream fis = Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "alignCircleBuildingsBefore.osm"))) {
     201            before = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     202        }
     203
     204        Way firstBefore = null;
     205        Way secondBefore = null;
     206
     207        for (Way w : before.getWays()) {
     208            if ("first".equals(w.get("test"))) {
     209                firstBefore = w;
     210            } else if ("second".equals(w.get("test"))) {
     211                secondBefore = w;
     212            } else {
     213                fail("There should only be \"first\" or \"second\" values in the key \"test\"");
     214            }
     215        }
     216
     217        assertNotNull(firstBefore);
     218        assertNotNull(secondBefore);
     219
     220        before.clearSelection();
     221        before.addSelected(firstBefore);
     222        before.addSelected(secondBefore);
     223
     224        Command c = assertDoesNotThrow(() -> AlignInCircleAction.buildCommand(before));
     225        c.executeCommand();
     226
     227        final DataSet after;
     228        try (InputStream fis = Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "alignCircleBuildingsAfter.osm"))) {
     229            after = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     230        }
     231        Way firstAfter = null;
     232        Way secondAfter = null;
     233
     234        for (Way w : after.getWays()) {
     235            if ("first".equals(w.get("test"))) {
     236                firstAfter = w;
     237            } else if ("second".equals(w.get("test"))) {
     238                secondAfter = w;
     239            } else {
     240                fail("There should only be \"first\" or \"second\" values in the key \"test\"");
     241            }
     242        }
     243
     244        assertNotNull(firstAfter);
     245        assertEquals(firstAfter.getNodesCount(), firstBefore.getNodesCount());
     246        for (int i = 0; i < firstAfter.getNodesCount(); i++) {
     247            Node bn = firstBefore.getNode(i);
     248            Node an = firstAfter.getNode(i);
     249            assertEquals(bn.lat(), an.lat(), ILatLon.MAX_SERVER_PRECISION);
     250            assertEquals(bn.lon(), an.lon(), ILatLon.MAX_SERVER_PRECISION);
     251        }
     252
     253        assertNotNull(secondAfter);
     254        assertEquals(secondAfter.getNodesCount(), secondBefore.getNodesCount());
     255        for (int i = 0; i < secondAfter.getNodesCount(); i++) {
     256            Node bn = secondBefore.getNode(i);
     257            Node an = secondAfter.getNode(i);
     258            assertEquals(bn.lat(), an.lat(), ILatLon.MAX_SERVER_PRECISION);
     259            assertEquals(bn.lon(), an.lon(), ILatLon.MAX_SERVER_PRECISION);
     260        }
     261    }
    184262}
Note: See TracChangeset for help on using the changeset viewer.