Changeset 15947 in josm for trunk/test/unit
- Timestamp:
- 2020-02-27T19:52:42+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java
r15946 r15947 8 8 import java.awt.GraphicsEnvironment; 9 9 import java.lang.reflect.Field; 10 import java.lang.reflect.InvocationTargetException;11 10 import java.lang.reflect.Method; 12 11 import java.util.ArrayList; … … 16 15 import java.util.List; 17 16 import java.util.Map; 17 import java.util.function.Function; 18 18 import java.util.stream.Collectors; 19 19 … … 28 28 import org.openstreetmap.josm.data.osm.Node; 29 29 import org.openstreetmap.josm.data.osm.OsmDataManager; 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 30 31 import org.openstreetmap.josm.data.osm.Way; 31 32 import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem; … … 37 38 import org.openstreetmap.josm.testutils.JOSMTestRules; 38 39 import org.openstreetmap.josm.testutils.mockers.WindowMocker; 39 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;40 40 41 41 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 51 51 @Rule 52 52 @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(); 54 54 55 55 private static TagEditHelper newTagEditHelper() { … … 89 89 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18764>#18764</a> 90 90 * 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 98 92 */ 99 93 @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", ""); 126 100 } 127 101 … … 129 103 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18798>#18798</a> 130 104 * 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 138 106 */ 139 107 @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 { 142 117 TestUtils.assumeWorkingJMockit(); 143 118 if (GraphicsEnvironment.isHeadless()) { 144 119 new WindowMocker(); 145 120 } 146 RightAndLefthandTraffic.initialize(); 147 MapCSSStyleSource css = new MapCSSStyleSource( 148 "node:righthandtraffic[junction=roundabout] { text: tr(\"Roundabout node\"); }"); 121 MapCSSStyleSource css = new MapCSSStyleSource(cssString); 149 122 css.loadStyleSource(); 150 123 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); 153 126 OsmDataManager.getInstance().setActiveDataSet(ds); 154 127 MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Layer", null)); 155 128 TagEditHelper helper = newTagEditHelper(); 156 129 Field sel = TagEditHelper.class.getDeclaredField("sel"); 157 sel.set(helper, Collections.singletonList( node));130 sel.set(helper, Collections.singletonList(primitive)); 158 131 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); 161 133 findIcon.setAccessible(true); 162 Object val = findIcon.invoke(addTagsDialog, "junction", "roundabout");134 Object val = findIcon.invoke(addTagsDialog, key, value); 163 135 assertNotNull(val); 164 136 }
Note:
See TracChangeset
for help on using the changeset viewer.