Ticket #18764: 18764.1.patch

File 18764.1.patch, 4.6 KB (added by taylor.smock, 4 years ago)

Add non-regression test (uses reflection)

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

     
    439439                if (right instanceof OptimizedGeneralSelector
    440440                        && ((OptimizedGeneralSelector) right).matchesBase(OsmPrimitiveType.WAY)) {
    441441                    final CrossingFinder crossingFinder = new CrossingFinder(e);
    442                     crossingFinder.visit(e.osm.getDataSet().searchWays(e.osm.getBBox()));
     442                    if (e.osm.getDataSet() != null)
     443                        crossingFinder.visit(e.osm.getDataSet().searchWays(e.osm.getBBox()));
    443444                }
    444445                return e.children != null;
    445446            } else if (ChildOrParentSelectorType.SIBLING == type) {
  • test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java

     
    33
    44import static org.junit.Assert.assertEquals;
    55import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertNotNull;
    67
     8import java.lang.reflect.Field;
     9import java.lang.reflect.InvocationTargetException;
     10import java.lang.reflect.Method;
    711import java.util.ArrayList;
    812import java.util.Arrays;
     13import java.util.Collections;
    914import java.util.HashMap;
    1015import java.util.List;
    1116import java.util.Map;
     
    1621
    1722import org.junit.Rule;
    1823import org.junit.Test;
     24import org.openstreetmap.josm.TestUtils;
     25import org.openstreetmap.josm.data.coor.LatLon;
     26import org.openstreetmap.josm.data.osm.DataSet;
     27import org.openstreetmap.josm.data.osm.Node;
     28import org.openstreetmap.josm.data.osm.OsmDataManager;
     29import org.openstreetmap.josm.data.osm.Way;
    1930import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
     31import org.openstreetmap.josm.gui.MainApplication;
     32import org.openstreetmap.josm.gui.dialogs.properties.TagEditHelper.AddTagsDialog;
     33import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     34import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     35import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2036import org.openstreetmap.josm.testutils.JOSMTestRules;
    2137
    2238import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    6581        assertFalse(newTagEditHelper().containsDataKey("foo"));
    6682        // TODO: complete test
    6783    }
     84
     85    /**
     86     * Non-regression test for <a
     87     * href="https://josm.openstreetmap.de/ticket/18764>#18764</a>
     88     *
     89     * @throws InvocationTargetException Check logs -- if caused by NPE, a
     90     *                                   regression probably occurred.
     91     * @throws IllegalArgumentException  Check source code
     92     * @throws IllegalAccessException    Check source code
     93     * @throws NoSuchFieldException      Check source code
     94     * @throws SecurityException         Probably shouldn't happen for tests
     95     * @throws NoSuchMethodException     Check source code
     96     */
     97    @Test
     98    public void testTicket18764() throws NoSuchMethodException, SecurityException, IllegalAccessException,
     99            IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
     100        MapCSSStyleSource css = new MapCSSStyleSource(
     101                "*[building] ⧉ *[highway] { text: tr(\"Building crossing highway\"); }");
     102        css.loadStyleSource();
     103        MapPaintStyles.addStyle(css);
     104        DataSet ds = new DataSet();
     105        // This does require a way
     106        Way way = TestUtils.newWay("", new Node(LatLon.NORTH_POLE), new Node(LatLon.SOUTH_POLE));
     107        way.getNodes().forEach(ds::addPrimitive);
     108        ds.addPrimitive(way);
     109        OsmDataManager.getInstance().setActiveDataSet(ds);
     110        MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Layer", null));
     111        TagEditHelper helper = newTagEditHelper();
     112        Field sel = TagEditHelper.class.getDeclaredField("sel");
     113        sel.set(helper, Collections.singletonList(way));
     114        AddTagsDialog addTagsDialog = helper.getAddTagsDialog();
     115        Method findIcon = TagEditHelper.AbstractTagsDialog.class.getDeclaredMethod("findIcon", String.class,
     116                String.class);
     117        findIcon.setAccessible(true);
     118        Object val = findIcon.invoke(addTagsDialog, "highway", "");
     119        assertNotNull(val);
     120    }
    68121}