FrameworkUtils { public static long[] getServicesInUseByBundle(Bundle bundle) throws IllegalArgumentException, IllegalStateException { if (bundle == null) { throw new IllegalArgumentException("Argument bundle cannot be null"); } long[] serviceIds; ServiceReference[] serviceReferences = bundle.getServicesInUse(); if (serviceReferences != null) { serviceIds = new long[serviceReferences.length]; for (int i = 0; i < serviceReferences.length; i++) { serviceIds[i] = (Long) serviceReferences[i].getProperty(Constants.SERVICE_ID); } } else { serviceIds = new long[0]; } return serviceIds; } 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 testGetServicesInUseByBundle() throws Exception { Bundle bundle = mock(Bundle.class); ServiceReference s1 = mock(ServiceReference.class); when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15)); ServiceReference s2 = mock(ServiceReference.class); when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(16)); ServiceReference s3 = mock(ServiceReference.class); when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(17)); when(bundle.getServicesInUse()).thenReturn(new ServiceReference[] { s1, s2, s3 }); assertArrayEquals(new long[] { 15, 16, 17 }, getServicesInUseByBundle(bundle)); }