### Question:
OsgiScriptingEngines extends ScriptingEngines { ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException { Collection<ServiceReference<ScriptEngineResolver>> refs = getBundleContext().getServiceReferences( ScriptEngineResolver.class, null); if (refs == null) { LOGGER.info("No OSGi script engine resolvers available!"); return null; } LOGGER.fine("Found " + refs.size() + " OSGi ScriptEngineResolver services"); for (ServiceReference<ScriptEngineResolver> ref : refs) { ScriptEngineResolver resolver = getBundleContext().getService(ref); ScriptEngine engine = resolver .resolveScriptEngine(scriptEngineName); getBundleContext().ungetService(ref); LOGGER.fine("OSGi resolver " + resolver + " produced " + scriptEngineName + " engine " + engine); if (engine != null) { return engine; } } return null; } OsgiScriptingEngines(ScriptBindingsFactory scriptBindingsFactory); @Override ScriptEngine getScriptEngineForLanguage(String language);  }### Answer:
@Test public void resolveScriptEngineWhenNoScriptEngineResolverIsPresent() throws InvalidSyntaxException { ScriptBindingsFactory mock = mock(ScriptBindingsFactory.class); TestOsgiScriptingEngines osgiScriptingEngines = new TestOsgiScriptingEngines(mock); BundleContext context = mock(BundleContext.class); osgiScriptingEngines.ctx = context; ScriptEngine scriptEngine = osgiScriptingEngines.resolveScriptEngine("foo"); assertThat(scriptEngine, is(nullValue())); }
@SuppressWarnings("unchecked") @Test public void resolveScriptEngine() throws InvalidSyntaxException { ScriptBindingsFactory mock = mock(ScriptBindingsFactory.class); TestOsgiScriptingEngines osgiScriptingEngines = new TestOsgiScriptingEngines(mock); BundleContext context = mock(BundleContext.class); ServiceReference<ScriptEngineResolver> serviceRef = mock(ServiceReference.class); when(context.getServiceReferences(eq(ScriptEngineResolver.class), isNull(String.class))).thenReturn(Collections.singleton(serviceRef)); ScriptEngineResolver scriptEngineResolver = mock(ScriptEngineResolver.class); when(context.getService(eq(serviceRef))).thenReturn(scriptEngineResolver); ScriptEngine scriptEngine = new TestScriptEngineFactory.TestScriptEngine(); when(scriptEngineResolver.resolveScriptEngine(eq("foo"))).thenReturn(scriptEngine); osgiScriptingEngines.ctx = context; ScriptEngine resolvedScriptEngine = osgiScriptingEngines.resolveScriptEngine("foo"); assertThat(resolvedScriptEngine, is(scriptEngine)); }