### Question:
KarafCapabilityProvider extends ServiceTracker<FeaturesService, FeaturesService> implements ICapabilityProvider,
    FeaturesListener { @Override public void featureEvent( FeatureEvent featureEvent ) { String feature = featureEvent.getFeature().getId(); InstallFuture installFutureWrapper = futures.getIfPresent( feature ); if ( installFutureWrapper == null ) { return; } switch ( featureEvent.getType() ) { case FeatureInstalled: SettableFuture<Boolean> future = installFutureWrapper.future; if ( future != null ) { futures.invalidate( feature ); future.set( installFutureWrapper.install ); } break; case FeatureUninstalled: future = installFutureWrapper.future; if ( future != null ) { futures.invalidate( feature ); future.set( !installFutureWrapper.install ); } break; } } KarafCapabilityProvider( BundleContext bundleContext ); @Override FeaturesService addingService( ServiceReference<FeaturesService> reference ); @Override String getId(); @Override Set<String> listCapabilities(); @Override ICapability getCapabilityById( String id ); @Override boolean capabilityExist( String id ); @Override Set<ICapability> getAllCapabilities(); void watchForInstall( Feature feature, SettableFuture<Boolean> future ); void watchForUnInstall( Feature feature, SettableFuture<Boolean> uninstallFuture ); @Override void featureEvent( FeatureEvent featureEvent ); @Override void repositoryEvent( RepositoryEvent repositoryEvent ); static final String KARAF; }### Answer:
@Test public void testFeatureEvent() throws Exception { FeaturesService featuresService = mock( FeaturesService.class ); when( bundleContext.getService( (ServiceReference) anyObject() ) ).thenReturn( featuresService ); karafCapabilityProvider = new KarafCapabilityProvider( bundleContext ); ServiceReference serviceReference = mock( ServiceReference.class ); karafCapabilityProvider.addingService( serviceReference ); karafCapabilityProvider = new KarafCapabilityProvider( bundleContext ); Feature feature = mock( Feature.class ); when( feature.getId() ).thenReturn( TEST_FEATURE_ID ); FeatureEvent featureEvent = mock( FeatureEvent.class ); when( featureEvent.getFeature() ).thenReturn( feature ); when( featureEvent.getType() ).thenReturn( FeatureEvent.EventType.FeatureInstalled ); SettableFuture settableFuture = SettableFuture.<Boolean> create(); karafCapabilityProvider.watchForInstall( feature, settableFuture ); karafCapabilityProvider.featureEvent( featureEvent ); verify( featureEvent ).getFeature(); verify( featureEvent ).getType(); }