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

see #18798, see #14088 - TagEditHelperTest: share code

File:
1 edited

Legend:

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

    r15946 r15947  
    88import java.awt.GraphicsEnvironment;
    99import java.lang.reflect.Field;
    10 import java.lang.reflect.InvocationTargetException;
    1110import java.lang.reflect.Method;
    1211import java.util.ArrayList;
     
    1615import java.util.List;
    1716import java.util.Map;
     17import java.util.function.Function;
    1818import java.util.stream.Collectors;
    1919
     
    2828import org.openstreetmap.josm.data.osm.Node;
    2929import org.openstreetmap.josm.data.osm.OsmDataManager;
     30import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3031import org.openstreetmap.josm.data.osm.Way;
    3132import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
     
    3738import org.openstreetmap.josm.testutils.JOSMTestRules;
    3839import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    39 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    4040
    4141import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    5151    @Rule
    5252    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    53     public JOSMTestRules test = new JOSMTestRules().territories().projection();
     53    public JOSMTestRules test = new JOSMTestRules().territories().rlTraffic().projection();
    5454
    5555    private static TagEditHelper newTagEditHelper() {
     
    8989     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18764>#18764</a>
    9090     *
    91      * @throws InvocationTargetException Check logs -- if caused by NPE, a
    92      *                                   regression probably occurred.
    93      * @throws IllegalArgumentException  Check source code
    94      * @throws IllegalAccessException    Check source code
    95      * @throws NoSuchFieldException      Check source code
    96      * @throws SecurityException         Probably shouldn't happen for tests
    97      * @throws NoSuchMethodException     Check source code
     91     * @throws Exception if any error occurs
    9892     */
    9993    @Test
    100     public void testTicket18764() throws NoSuchMethodException, SecurityException, IllegalAccessException,
    101             IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
    102         TestUtils.assumeWorkingJMockit();
    103         if (GraphicsEnvironment.isHeadless()) {
    104             new WindowMocker();
    105         }
    106         MapCSSStyleSource css = new MapCSSStyleSource(
    107                 "*[building] ⧉ *[highway] { text: tr(\"Building crossing highway\"); }");
    108         css.loadStyleSource();
    109         MapPaintStyles.addStyle(css);
    110         DataSet ds = new DataSet();
    111         // This does require a way
    112         Way way = TestUtils.newWay("", new Node(LatLon.NORTH_POLE), new Node(LatLon.SOUTH_POLE));
    113         way.getNodes().forEach(ds::addPrimitive);
    114         ds.addPrimitive(way);
    115         OsmDataManager.getInstance().setActiveDataSet(ds);
    116         MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Layer", null));
    117         TagEditHelper helper = newTagEditHelper();
    118         Field sel = TagEditHelper.class.getDeclaredField("sel");
    119         sel.set(helper, Collections.singletonList(way));
    120         AddTagsDialog addTagsDialog = helper.getAddTagsDialog();
    121         Method findIcon = TagEditHelper.AbstractTagsDialog.class.getDeclaredMethod("findIcon", String.class,
    122                 String.class);
    123         findIcon.setAccessible(true);
    124         Object val = findIcon.invoke(addTagsDialog, "highway", "");
    125         assertNotNull(val);
     94    public void testTicket18764() throws Exception {
     95        testIcon("*[building] ⧉ *[highway] { text: tr(\"Building crossing highway\"); }", ds -> {
     96            Way way = TestUtils.newWay("", new Node(LatLon.NORTH_POLE), new Node(LatLon.SOUTH_POLE));
     97            way.getNodes().forEach(ds::addPrimitive);
     98            return way;
     99        }, "highway", "");
    126100    }
    127101
     
    129103     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18798>#18798</a>
    130104     *
    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
     105     * @throws Exception if any error occurs
    138106     */
    139107    @Test
    140     public void testTicket18798() throws NoSuchMethodException, SecurityException, IllegalAccessException,
    141             IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
     108    public void testTicket18798() throws Exception {
     109        testIcon("node:righthandtraffic[junction=roundabout] { text: tr(\"Roundabout node\"); }", ds -> {
     110            Node node = new Node(LatLon.NORTH_POLE);
     111            ds.addPrimitive(node);
     112            return node;
     113        }, "junction", "roundabout");
     114    }
     115
     116    void testIcon(String cssString, Function<DataSet, OsmPrimitive> prepare, String key, String value) throws Exception {
    142117        TestUtils.assumeWorkingJMockit();
    143118        if (GraphicsEnvironment.isHeadless()) {
    144119            new WindowMocker();
    145120        }
    146         RightAndLefthandTraffic.initialize();
    147         MapCSSStyleSource css = new MapCSSStyleSource(
    148                 "node:righthandtraffic[junction=roundabout] { text: tr(\"Roundabout node\"); }");
     121        MapCSSStyleSource css = new MapCSSStyleSource(cssString);
    149122        css.loadStyleSource();
    150123        MapPaintStyles.addStyle(css);
    151         Node node = new Node(LatLon.NORTH_POLE);
    152         DataSet ds = new DataSet(node);
     124        DataSet ds = new DataSet();
     125        final OsmPrimitive primitive = prepare.apply(ds);
    153126        OsmDataManager.getInstance().setActiveDataSet(ds);
    154127        MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Layer", null));
    155128        TagEditHelper helper = newTagEditHelper();
    156129        Field sel = TagEditHelper.class.getDeclaredField("sel");
    157         sel.set(helper, Collections.singletonList(node));
     130        sel.set(helper, Collections.singletonList(primitive));
    158131        AddTagsDialog addTagsDialog = helper.getAddTagsDialog();
    159         Method findIcon = TagEditHelper.AbstractTagsDialog.class.getDeclaredMethod("findIcon", String.class,
    160                 String.class);
     132        Method findIcon = TagEditHelper.AbstractTagsDialog.class.getDeclaredMethod("findIcon", String.class, String.class);
    161133        findIcon.setAccessible(true);
    162         Object val = findIcon.invoke(addTagsDialog, "junction", "roundabout");
     134        Object val = findIcon.invoke(addTagsDialog, key, value);
    163135        assertNotNull(val);
    164136    }
Note: See TracChangeset for help on using the changeset viewer.