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


Ignore:
Timestamp:
2020-02-27T19:52:40+01:00 (5 years ago)
Author:
simon04
Message:

fix #18798, see #14088 - Crash when adding junction=roundabout to a node (patch by taylor.smock)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java

    r15927 r15946  
    3737import org.openstreetmap.josm.testutils.JOSMTestRules;
    3838import org.openstreetmap.josm.testutils.mockers.WindowMocker;
     39import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    3940
    4041import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    5051    @Rule
    5152    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    52     public JOSMTestRules test = new JOSMTestRules();
     53    public JOSMTestRules test = new JOSMTestRules().territories().projection();
    5354
    5455    private static TagEditHelper newTagEditHelper() {
     
    124125        assertNotNull(val);
    125126    }
     127
     128    /**
     129     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18798>#18798</a>
     130     *
     131     * @throws InvocationTargetException Check logs -- if caused by NPE, a
     132     *                                   regression probably occurred.
     133     * @throws IllegalArgumentException  Check source code
     134     * @throws IllegalAccessException    Check source code
     135     * @throws NoSuchFieldException      Check source code
     136     * @throws SecurityException         Probably shouldn't happen for tests
     137     * @throws NoSuchMethodException     Check source code
     138     */
     139    @Test
     140    public void testTicket18798() throws NoSuchMethodException, SecurityException, IllegalAccessException,
     141            IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
     142        TestUtils.assumeWorkingJMockit();
     143        if (GraphicsEnvironment.isHeadless()) {
     144            new WindowMocker();
     145        }
     146        RightAndLefthandTraffic.initialize();
     147        MapCSSStyleSource css = new MapCSSStyleSource(
     148                "node:righthandtraffic[junction=roundabout] { text: tr(\"Roundabout node\"); }");
     149        css.loadStyleSource();
     150        MapPaintStyles.addStyle(css);
     151        Node node = new Node(LatLon.NORTH_POLE);
     152        DataSet ds = new DataSet(node);
     153        OsmDataManager.getInstance().setActiveDataSet(ds);
     154        MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Layer", null));
     155        TagEditHelper helper = newTagEditHelper();
     156        Field sel = TagEditHelper.class.getDeclaredField("sel");
     157        sel.set(helper, Collections.singletonList(node));
     158        AddTagsDialog addTagsDialog = helper.getAddTagsDialog();
     159        Method findIcon = TagEditHelper.AbstractTagsDialog.class.getDeclaredMethod("findIcon", String.class,
     160                String.class);
     161        findIcon.setAccessible(true);
     162        Object val = findIcon.invoke(addTagsDialog, "junction", "roundabout");
     163        assertNotNull(val);
     164    }
    126165}
Note: See TracChangeset for help on using the changeset viewer.