@Test(expected=IllegalStateException.class) public void testRegisterService_BCNull (){ Object service = mock(Object.class); Properties props = mock (Properties.class); Map<Class, Map<Object,ServiceRegistration>> sr = new HashMap<Class, Map<Object,ServiceRegistration>>(); ServiceRegistration s = mock(ServiceRegistration.class); when(bc.registerService(eq(Object.class.getName()), same(service), any(Dictionary.class))).thenReturn(s); Map<Object, ServiceRegistration> registrations = new HashMap<Object, ServiceRegistration>(); sr.put(Object.class, registrations); ServiceUtil.registerService(null, service, Object.class, props, sr); }
public static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations) { if ( service == null ) throw new NullPointerException( "service object is null" ); if ( serviceClass == null ) throw new NullPointerException( "class is null" ); if ( props == null ) throw new NullPointerException( "props are null" ); if ( bc == null ) throw new IllegalStateException( "BundleContext is null" ); ServiceRegistration s = bc.registerService( serviceClass.getName(), service, getDictionary(props)); Map<Object, ServiceRegistration> registrations = serviceRegistrations.get(serviceClass); if ( registrations == null ) { registrations = new HashMap<Object,ServiceRegistration>(); serviceRegistrations.put(serviceClass, registrations ); } registrations.put(service,s); }
ServiceUtil { public static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations) { if ( service == null ) throw new NullPointerException( "service object is null" ); if ( serviceClass == null ) throw new NullPointerException( "class is null" ); if ( props == null ) throw new NullPointerException( "props are null" ); if ( bc == null ) throw new IllegalStateException( "BundleContext is null" ); ServiceRegistration s = bc.registerService( serviceClass.getName(), service, getDictionary(props)); Map<Object, ServiceRegistration> registrations = serviceRegistrations.get(serviceClass); if ( registrations == null ) { registrations = new HashMap<Object,ServiceRegistration>(); serviceRegistrations.put(serviceClass, registrations ); } registrations.put(service,s); } }
ServiceUtil { public static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations) { if ( service == null ) throw new NullPointerException( "service object is null" ); if ( serviceClass == null ) throw new NullPointerException( "class is null" ); if ( props == null ) throw new NullPointerException( "props are null" ); if ( bc == null ) throw new IllegalStateException( "BundleContext is null" ); ServiceRegistration s = bc.registerService( serviceClass.getName(), service, getDictionary(props)); Map<Object, ServiceRegistration> registrations = serviceRegistrations.get(serviceClass); if ( registrations == null ) { registrations = new HashMap<Object,ServiceRegistration>(); serviceRegistrations.put(serviceClass, registrations ); } registrations.put(service,s); } private  ServiceUtil(); }
ServiceUtil { public static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations) { if ( service == null ) throw new NullPointerException( "service object is null" ); if ( serviceClass == null ) throw new NullPointerException( "class is null" ); if ( props == null ) throw new NullPointerException( "props are null" ); if ( bc == null ) throw new IllegalStateException( "BundleContext is null" ); ServiceRegistration s = bc.registerService( serviceClass.getName(), service, getDictionary(props)); Map<Object, ServiceRegistration> registrations = serviceRegistrations.get(serviceClass); if ( registrations == null ) { registrations = new HashMap<Object,ServiceRegistration>(); serviceRegistrations.put(serviceClass, registrations ); } registrations.put(service,s); } private  ServiceUtil(); static S getService(BundleContext bc, Class<S> serviceClass, List<ServiceReference<?>> gottenServices); static S getService(BundleContext bc, Class<S> serviceClass, String filter, List<ServiceReference<?>> gottenServices); static void registerServiceListener(BundleContext bc, Object listener, String registerMethodName, 
			String unregisterMethodName, Class<?> serviceClass, Class<?> methodClass, String additionalFilter, List<CyServiceListener> serviceListeners); static void registerServiceListener(BundleContext bc, BiConsumer<S,Map<String,String>> registerConsumer, 
			BiConsumer<S,Map<String,String>> unregisterConsumer, Class<S> serviceClass, String additionalFilter, List<CyServiceListener> serviceListeners); static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, 
			Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations); static Dictionary<String, ?> getDictionary(Properties props); static void registerAllServices(final BundleContext bc, final Object service, final Properties props, 
			Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations); }
ServiceUtil { public static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations) { if ( service == null ) throw new NullPointerException( "service object is null" ); if ( serviceClass == null ) throw new NullPointerException( "class is null" ); if ( props == null ) throw new NullPointerException( "props are null" ); if ( bc == null ) throw new IllegalStateException( "BundleContext is null" ); ServiceRegistration s = bc.registerService( serviceClass.getName(), service, getDictionary(props)); Map<Object, ServiceRegistration> registrations = serviceRegistrations.get(serviceClass); if ( registrations == null ) { registrations = new HashMap<Object,ServiceRegistration>(); serviceRegistrations.put(serviceClass, registrations ); } registrations.put(service,s); } private  ServiceUtil(); static S getService(BundleContext bc, Class<S> serviceClass, List<ServiceReference<?>> gottenServices); static S getService(BundleContext bc, Class<S> serviceClass, String filter, List<ServiceReference<?>> gottenServices); static void registerServiceListener(BundleContext bc, Object listener, String registerMethodName, 
			String unregisterMethodName, Class<?> serviceClass, Class<?> methodClass, String additionalFilter, List<CyServiceListener> serviceListeners); static void registerServiceListener(BundleContext bc, BiConsumer<S,Map<String,String>> registerConsumer, 
			BiConsumer<S,Map<String,String>> unregisterConsumer, Class<S> serviceClass, String additionalFilter, List<CyServiceListener> serviceListeners); static void registerService(final BundleContext bc, final Object service, final Class<?> serviceClass, final Properties props, 
			Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations); static Dictionary<String, ?> getDictionary(Properties props); static void registerAllServices(final BundleContext bc, final Object service, final Properties props, 
			Map<Class,Map<Object,ServiceRegistration>> serviceRegistrations);  }