### Question:
PentahoWebPackageBundleListener implements BundleListener { List<BundleCapability> getWebPackageCapabilities( Bundle bundle ) { BundleWiring wiring = bundle.adapt( BundleWiring.class ); if ( wiring != null ) { return wiring.getCapabilities( CAPABILITY_NAMESPACE ); } return Collections.emptyList(); }  @Override void bundleChanged( BundleEvent bundleEvent ); void registerWebPackageServices( Bundle bundle ); void unregisterWebPackageServices( Bundle bundle );  }### Answer:
@Test public void testGetWebPackageCapabilitiesWhenBundleWiringIsNull() { Bundle mockBundle = mock( Bundle.class ); BundleWiring mockBundleWiring = mock( BundleWiring.class ); PentahoWebPackageBundleListener listener = new PentahoWebPackageBundleListener(); List<BundleCapability> bundleCapabilityList = new ArrayList<>(); int expectedCapabilitiesSize = 0; when( mockBundleWiring.getCapabilities( PentahoWebPackageConstants.CAPABILITY_NAMESPACE ) ).thenReturn( bundleCapabilityList ); when( mockBundle.adapt( BundleWiring.class ) ).thenReturn( null ); int actualCapabilitiesSize = listener.getWebPackageCapabilities( mockBundle ).size(); assertEquals( expectedCapabilitiesSize, actualCapabilitiesSize ); }
@Test public void testGetWebPackageCapabilitiesWhenBundleWiringHasNoCapabilities() { Bundle mockBundle = mock( Bundle.class ); BundleWiring mockBundleWiring = mock( BundleWiring.class ); PentahoWebPackageBundleListener listener = new PentahoWebPackageBundleListener(); List<BundleCapability> bundleCapabilityList = new ArrayList<>(); int expectedCapabilitiesSize = 0; when( mockBundleWiring.getCapabilities( PentahoWebPackageConstants.CAPABILITY_NAMESPACE ) ).thenReturn( bundleCapabilityList ); when( mockBundle.adapt( BundleWiring.class ) ).thenReturn( mockBundleWiring ); int actualCapabilitiesSize = listener.getWebPackageCapabilities( mockBundle ).size(); assertEquals( expectedCapabilitiesSize, actualCapabilitiesSize ); }
@Test public void testGetWebPackageCapabilitiesWhenBundleWiringHasCapabilities() { Bundle mockBundle = mock( Bundle.class ); BundleWiring mockBundleWiring = mock( BundleWiring.class ); PentahoWebPackageBundleListener listener = new PentahoWebPackageBundleListener(); BundleCapability mockBundleCapability = mock( BundleCapability.class ); List<BundleCapability> bundleCapabilityList = new ArrayList<>(); bundleCapabilityList.add( mockBundleCapability ); int expectedCapabilitiesSize = 1; when( mockBundleWiring.getCapabilities( PentahoWebPackageConstants.CAPABILITY_NAMESPACE ) ).thenReturn( bundleCapabilityList ); when( mockBundle.adapt( BundleWiring.class ) ).thenReturn( mockBundleWiring ); int actualCapabilitiesSize = listener.getWebPackageCapabilities( mockBundle ).size(); assertEquals( expectedCapabilitiesSize, actualCapabilitiesSize ); }