FrameworkUtils { public static ServiceReference resolveService(BundleContext bundleContext, long serviceId) throws IOException { if (bundleContext == null) { throw new IllegalArgumentException("Argument bundleContext cannot be null"); } ServiceReference result = null; try { ServiceReference[] references = bundleContext.getAllServiceReferences(null, "(" + Constants.SERVICE_ID + "=" + serviceId + ")"); if (references == null || references.length < 1) { throw new IOException("Service with id [" + serviceId + "] not found"); } else { result = references[0]; } } catch (InvalidSyntaxException e) { IOException ioex = new IOException("Failure when resolving service "); ioex.initCause(e); throw ioex; } return result; } private  FrameworkUtils(); static Bundle resolveBundle(BundleContext bundleContext, long bundleId); static long[] getBundleIds(Bundle[] bundles); static long[] getBundleIds(List<Bundle> bundles); static ServiceReference resolveService(BundleContext bundleContext, long serviceId); static long[] getServiceIds(ServiceReference[] serviceReferences); static String[] getBundleExportedPackages(Bundle bundle, PackageAdmin packageAdmin); static long[] getFragmentIds(Bundle bundle, PackageAdmin packageAdmin); static long[] getHostIds(Bundle fragment, PackageAdmin packageAdmin); static String[] getBundleImportedPackages(BundleContext localBundleContext, Bundle bundle,
            PackageAdmin packageAdmin); static long[] getRegisteredServiceIds(Bundle bundle); static long[] getServicesInUseByBundle(Bundle bundle); static boolean isBundlePendingRemoval(Bundle bundle, PackageAdmin packageAdmin); static boolean isBundleRequiredByOthers(Bundle bundle, PackageAdmin packageAdmin); @SuppressWarnings("unchecked") static long[] getBundleDependencies(BundleContext localBundleContext, 
                                               Bundle bundle,
                                               PackageAdmin packageAdmin); static long[] getDependentBundles(Bundle bundle, PackageAdmin packageAdmin); static String getBundleState(Bundle bundle); static boolean arrayContains(Object[] array, Object value); static List<String> extractHeaderDeclaration(String headerStatement);  }
@Test public void testResolveService() throws Exception { BundleContext context = mock(BundleContext.class); ServiceReference reference = mock(ServiceReference.class); when(context.getAllServiceReferences(anyString(), anyString())).thenReturn(new ServiceReference[] { reference }); ServiceReference result = resolveService(context, 998); assertNotNull(result); }