Ticket #24982: 24982-test.patch

File 24982-test.patch, 2.3 KB (added by GerdP, 6 days ago)

non regression test

  • test/unit/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitorTest.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.data.osm.visitor;
     3
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertTrue;
     6
     7import org.junit.jupiter.api.Test;
     8import org.openstreetmap.josm.data.ProjectionBounds;
     9import org.openstreetmap.josm.data.coor.LatLon;
     10import org.openstreetmap.josm.data.osm.DataSet;
     11import org.openstreetmap.josm.data.osm.Node;
     12import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     13import org.openstreetmap.josm.testutils.annotations.Projection;
     14
     15/**
     16 * Unit tests for class {@link BoundingXYVisitor}.
     17 */
     18@BasicPreferences
     19@Projection
     20public class BoundingXYVisitorTest {
     21
     22    /**
     23     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/24982">#24982</a>
     24     */
     25    @Test
     26     public void testTicket24982() {
     27         DataSet ds = new DataSet();
     28         // two nodes with coordinates as in the example data
     29         Node n1 = new Node(new LatLon(53.1637636, 7.8315384));
     30         Node n2 = new Node(new LatLon(53.1729062, 7.7530235));
     31         ds.addPrimitive(n1);
     32         ds.addPrimitive(n2);
     33
     34         BoundingXYVisitor v = new BoundingXYVisitor();
     35         ds.setSelected(ds.getNodes());
     36         assertEquals(2, ds.getSelectedNodes().size());
     37         ds.getSelectedNodes().forEach(v::visit);
     38         ProjectionBounds boundsBeforeZoom = v.getBounds();
     39         v.enlargeBoundingBoxLogarithmically();
     40         ProjectionBounds boundsAfterZoom = v.getBounds();
     41         // check that the new bounding box isn't smaller than the old one
     42         assertTrue(boundsAfterZoom.contains(boundsBeforeZoom.getMin()));
     43         assertTrue(boundsAfterZoom.contains(boundsBeforeZoom.getMax()));
     44         // check that the new bounding box contains both nodes
     45         assertTrue(boundsAfterZoom.contains(n1.getEastNorth()));
     46         assertTrue(boundsAfterZoom.contains(n2.getEastNorth()));
     47     }
     48
     49}