### Question:
KarafCapabilityProvider extends ServiceTracker<FeaturesService, FeaturesService> implements ICapabilityProvider,
    FeaturesListener { @Override public boolean capabilityExist( String id ) { try { Feature feature = featuresService.getFeature( id ); if ( feature == null ) { return false; } return true; } catch ( Exception e ) { logger.error( "Unknown error retrieving feature: " + id, e ); return false; } } 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 testCapabilityExist() throws Exception { Feature feature = mock( Feature.class ); when( featuresService.getFeature( anyString() )).thenReturn( feature ); karafCapabilityProvider = new KarafCapabilityProvider( bundleContext ); ServiceReference serviceReference = mock( ServiceReference.class ); karafCapabilityProvider.addingService( serviceReference ); boolean exists = karafCapabilityProvider.capabilityExist( TEST_CAPABILITY_ID ); assertTrue( exists ); when( featuresService.getFeature( anyString() )).thenReturn( null ); boolean doesNotExist = karafCapabilityProvider.capabilityExist( "bad" ); assertFalse( doesNotExist ); }