ServiceRegistryContext extends AbstractServiceRegistryContext implements Context { public NamingEnumeration<Binding> listBindings(final Name name) throws NamingException { return new ServiceRegistryListContext(callerContext, env, convert(name)).listBindings(""); } ServiceRegistryContext(BundleContext callerContext, Hashtable<?, ?> environment);  ServiceRegistryContext(BundleContext callerContext, OsgiName validName, Map<String, Object> env); NamingEnumeration<NameClassPair> list(final Name name); NamingEnumeration<NameClassPair> list(String name); NamingEnumeration<Binding> listBindings(final Name name); NamingEnumeration<Binding> listBindings(String name); Object lookup(Name name); Object lookup(String name);  }
@Test public void checkServiceListListBindings() throws NamingException { BundleMock mock = new BundleMock("scooby.doo", new Properties()); Thread.currentThread().setContextClassLoader(mock.getClassLoader()); InitialContext ctx = new InitialContext(); String className = Runnable.class.getName(); MethodCall run = new MethodCall(Runnable.class, "run"); Runnable t = Skeleton.newMock(Runnable.class); Runnable t2 = Skeleton.newMock(Runnable.class); reg.unregister(); ServiceRegistration reg = bc.registerService(className, t, null); ServiceRegistration reg2 = bc.registerService(className, t2, null); NamingEnumeration<Binding> ne = ctx.listBindings("osgi:servicelist/" + className); assertTrue(ne.hasMoreElements()); Binding bnd = ne.nextElement(); assertEquals(String.valueOf(reg.getReference().getProperty(Constants.SERVICE_ID)), bnd.getName()); assertTrue("Class name not correct. Was: " + bnd.getClassName(), bnd.getClassName().contains("Proxy") || bnd.getClassName().contains("EnhancerByCGLIB")); Runnable r = (Runnable) bnd.getObject(); assertNotNull(r); r.run(); Skeleton.getSkeleton(t).assertCalledExactNumberOfTimes(run, 1); Skeleton.getSkeleton(t2).assertNotCalled(run); assertTrue(ne.hasMoreElements()); bnd = ne.nextElement(); assertEquals(String.valueOf(reg2.getReference().getProperty(Constants.SERVICE_ID)), bnd.getName()); assertTrue("Class name not correct. Was: " + bnd.getClassName(), bnd.getClassName().contains("Proxy") || bnd.getClassName().contains("EnhancerByCGLIB")); r = (Runnable) bnd.getObject(); assertNotNull(r); r.run(); Skeleton.getSkeleton(t).assertCalledExactNumberOfTimes(run, 1); Skeleton.getSkeleton(t2).assertCalledExactNumberOfTimes(run, 1); assertFalse(ne.hasMoreElements()); }