This is one of those times where I feel like the light bulb should have gone on for me years ago. It turns out there is a much easier way to test these things: by writing JUnit Plug-in Tests for them.
What follows is some sample code to do this. Since I'm testing the enablement of launch shortcuts, the configuration elements are specific to that scenario, but you should be able to do this for any expression that appears in a bundle's plugin.xml.
In a @Before method, I read the expression from the plugin.xml and convert it into an Expression object.
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.EXTENSION_POINT_LAUNCH_SHORTCUTS); IConfigurationElement[] infos = extensionPoint.getConfigurationElements(); for (IConfigurationElement elem : infos) { String id = elem.getAttribute("id"); IConfigurationElement contextLaunch = null; IConfigurationElement enablement = null; if ("myShortcutId".equals(id)) { contextLaunch = elem.getChildren("contextualLaunch")[0]; enablement = contextLaunch.getChildren("enablement")[0]; expression = ExpressionConverter.getDefault().perform(enablement); }
And in a @Test method, I set up the context I'm trying to mimic and evaluate the expression.
@Test public void ui() throws Exception { List<object> ctxt = new ArrayList<object>(); ctxt.add(selectedObject /*Some IResource, perhaps*/); IEvaluationContext context = new EvaluationContext(null, ctxt); context.addVariable("selection", ctxt); //$NON-NLS-1$ assertEquals(EvaluationResult.valueOf(m_uiEnabled), expression.evaluate(context)); }
Now I can muck around in those delicately constructed XML expressions and rest assured that I have a test suite watching my back.
ReplyDeleteImpressive article dude! Thank you
https://decor-ksa.com/iron-fences/
http://mchaabaty.com/dawadmi/
http://mchaabaty.com/templates/
http://mchaabaty.com/riyadh/
http://mchaabaty.com/stone/
http://mchaabaty.com/heritage/
kobe sneakers
ReplyDeletemoncler jackets
supreme shirt
nike off white
hermes online
kawhi leonard shoes
yeezy 500
supreme new york
yeezy
offwhite
g2o38k9l66 c2b06f5u94 j1x04g4s08 m2s35a9b36 u6t49j4q98 a7e23e3p55
ReplyDelete