### Question:
PentahoWebPackageServiceTracker implements ServiceTrackerCustomizer<IPentahoWebPackage, ServiceRegistration<?>> { @Override public ServiceRegistration<?> addingService( ServiceReference<IPentahoWebPackage> reference ) { Bundle bundle = reference.getBundle(); if ( bundle != null ) { PentahoWebPackageResourceMapping mapping = new PentahoWebPackageResourceMapping( this.context.getService( reference ) ); Dictionary<String, String> serviceProperties = new Hashtable<>( 2 ); serviceProperties.put( RESOURCE_PATTERN_KEY, mapping.getAlias() + "/*" ); serviceProperties.put( RESOURCE_PREFIX_KEY, mapping.getPath() ); return bundle.getBundleContext().registerService( String.class.getName(), "", serviceProperties ); } 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() throws Exception { ServiceRegistration serviceRegistration = pentahoWebPackageServiceTracker.addingService( mockServiceReference ); assertNotNull( serviceRegistration ); ArgumentCaptor<Dictionary> servicePropertiesCaptor = ArgumentCaptor.forClass(Dictionary.class); verify( this.mockBundleContext, times( 1 ) ).registerService( eq( String.class.getName() ), eq( "" ), servicePropertiesCaptor.capture() ); Dictionary serviceProperties = servicePropertiesCaptor.getValue(); assertEquals( this.mockWebRootPath + "/*", serviceProperties.get( RESOURCE_PATTERN_KEY ) ); assertEquals( this.mockResourceRootPath, serviceProperties.get( RESOURCE_PREFIX_KEY ) ); }
@Test public void testAddingServiceWithInvalidServiceReference() throws Exception { doReturn( null ).when( this.mockServiceReference ).getBundle(); ServiceRegistration serviceRegistration = pentahoWebPackageServiceTracker.addingService( mockServiceReference ); assertNull( serviceRegistration ); verify( mockBundleContext, times( 0 ) ).registerService( anyString(), anyObject(), any() ); }