### Question:
PentahoWebPackageServiceTracker implements ServiceTrackerCustomizer<IPentahoWebPackage, ServiceRegistration<?>> { @Override public ServiceRegistration<?> addingService( ServiceReference<IPentahoWebPackage> reference ) { Bundle bundle = reference.getBundle(); if ( bundle != null ) { IPentahoWebPackage pentahoWebPackage = this.context.getService( reference ); URI resourceRootUri = null; try { URL resourceRootUrl = bundle.getResource( pentahoWebPackage.getResourceRootPath() ); if ( resourceRootUrl != null ) { resourceRootUri = resourceRootUrl.toURI(); } } catch ( URISyntaxException ignored ) { } IRequireJsPackage packageInfo = new RequireJsPackageImpl( pentahoWebPackage, resourceRootUri ); return bundle.getBundleContext().registerService( IRequireJsPackage.class.getName(), packageInfo, null ); } return null; } PentahoWebPackageServiceTracker( BundleContext context ); @Override ServiceRegistration<?> addingService( ServiceReference<IPentahoWebPackage> reference ); @Override void modifiedService( ServiceReference<IPentahoWebPackage> reference, ServiceRegistration<?> serviceRegistration ); @Override void removedService( ServiceReference<IPentahoWebPackage> reference, ServiceRegistration<?> serviceRegistration );  }### Answer:
@Test public void testAddingServiceWithValidServiceReference() { this.pentahoWebPackageServiceTracker = new PentahoWebPackageServiceTracker( this.mockBundleContext ); ServiceRegistration serviceRegistration = this.pentahoWebPackageServiceTracker.addingService( this.mockServiceReference ); assertNotNull( "Should return valid ServiceRegistration object", serviceRegistration ); verify( this.mockBundleContext, times( 1 ) ).registerService( eq( IRequireJsPackage.class.getName() ), any( IRequireJsPackage.class ), eq( null ) ); }
@Test public void testAddingServiceWithInvalidServiceReference() { doReturn( null ).when( this.mockServiceReference ).getBundle(); ServiceRegistration serviceRegistration = this.pentahoWebPackageServiceTracker.addingService( mockServiceReference ); assertNull( "Should return null", serviceRegistration ); verify( mockBundleContext, times( 0 ) ).registerService( anyString(), anyObject(), eq( null ) ); }