Changeset 18664 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2023-02-15T18:22:07+01:00 (3 years ago)
Author:
taylor.smock
Message:

Fix #22704: Add parent_way_angle mapcss function (patch by Woazboat)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/FunctionsTest.java

    r17613 r18664  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertNotNull;
    56import static org.junit.jupiter.api.Assertions.assertNull;
    67import static org.junit.jupiter.api.Assertions.assertTrue;
     
    89
    910import java.util.Collections;
     11import java.util.Objects;
    1012
    11 import org.junit.jupiter.api.extension.RegisterExtension;
    1213import org.junit.jupiter.api.Test;
    1314import org.openstreetmap.josm.TestUtils;
     15import org.openstreetmap.josm.data.coor.LatLon;
     16import org.openstreetmap.josm.data.osm.Node;
    1417import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1518import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1619import org.openstreetmap.josm.data.osm.User;
     20import org.openstreetmap.josm.data.osm.Way;
    1721import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    1822import org.openstreetmap.josm.gui.mappaint.Environment;
    1923import org.openstreetmap.josm.gui.util.GuiHelper;
    2024import org.openstreetmap.josm.spi.preferences.Config;
    21 import org.openstreetmap.josm.testutils.JOSMTestRules;
    22 
    23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     25import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     26import org.openstreetmap.josm.testutils.annotations.Projection;
    2427
    2528/**
    2629 * Unit tests of {@link Functions}.
    2730 */
     31@BasicPreferences
     32@Projection
    2833class FunctionsTest {
    29 
    30     /**
    31      * Setup rule
    32      */
    33     @RegisterExtension
    34     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    35     public JOSMTestRules test = new JOSMTestRules();
    36 
    3734    private static class EnvBuilder {
    3835        private final OsmPrimitive osm;
     
    108105
    109106    /**
     107     * Test for {@link Functions#parent_way_angle(Environment)}
     108     */
     109    @Test
     110    void testParentWayAngle() {
     111        assertNull(Functions.parent_way_angle(new EnvBuilder(NODE).build()));
     112        final Environment environment = new EnvBuilder(NODE).build();
     113        ((Node) environment.osm).setCoor(LatLon.ZERO);
     114        final Way parent = TestUtils.newWay("", new Node(new LatLon(-.1, 0)), (Node) environment.osm, new Node(new LatLon(.1, 0)));
     115        environment.parent = parent;
     116        Double actual = Functions.parent_way_angle(environment);
     117        assertNotNull(actual);
     118        assertEquals(Math.toRadians(0), actual, 1e-9);
     119        // Reverse node order
     120        Objects.requireNonNull(parent.firstNode()).setCoor(LatLon.NORTH_POLE);
     121        Objects.requireNonNull(parent.lastNode()).setCoor(LatLon.SOUTH_POLE);
     122        actual = Functions.parent_way_angle(environment);
     123        assertNotNull(actual);
     124        assertEquals(Math.toRadians(180), actual, 1e-9);
     125    }
     126
     127    /**
    110128     * Unit test of {@code Functions#to_xxx}
    111129     */
     
    163181        Config.getPref().put(colorKey, null);
    164182    }
    165 
    166183}
Note: See TracChangeset for help on using the changeset viewer.