@Test
public void testGetBundleImportedPackages() throws Exception {

    
    Bundle bundle = mock(Bundle.class);
    BundleContext context = mock(BundleContext.class);
    
    Bundle b1 = mock(Bundle.class);
    Bundle b2 = mock(Bundle.class);
    Bundle b3 = mock(Bundle.class);
    when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
    
    ExportedPackage ep1 = mock(ExportedPackage.class);
    when(ep1.getImportingBundles()).thenReturn(new Bundle[] { bundle, b2, b3 });
    when(ep1.getName()).thenReturn("org.apache.aries.jmx.b1");
    when(ep1.getVersion()).thenReturn(Version.emptyVersion);
    ExportedPackage ep2 = mock(ExportedPackage.class);
    when(ep2.getImportingBundles()).thenReturn(new Bundle[] { bundle, b3 });
    when(ep2.getName()).thenReturn("org.apache.aries.jmx.b2");
    when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
    
    PackageAdmin admin = mock(PackageAdmin.class);
    when(admin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
    when(admin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2 });
    when(admin.getExportedPackages(b3)).thenReturn(null);
    
    //check first with DynamicImport
    Dictionary<String, String> headers = new Hashtable<String, String>();
    headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
    when(bundle.getHeaders()).thenReturn(headers);
    assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"} 
                , getBundleImportedPackages(context, bundle, admin));
    
    //check with ImportPackage statement
    headers.remove(Constants.DYNAMICIMPORT_PACKAGE);
    String importPackageStatement = "org.apache.aries.jmx.b1;version=0.0.0;resolution:=optional,org.apache.aries.jmx.b2;attribute:=value;version=\"[2.0, 3.0)\""; 
    headers.put(Constants.IMPORT_PACKAGE, importPackageStatement);
    when(admin.getExportedPackages("org.apache.aries.jmx.b1")).thenReturn(new ExportedPackage[] { ep1 });
    when(admin.getExportedPackages("org.apache.aries.jmx.b2")).thenReturn(new ExportedPackage[] { ep2 });
    
    assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"} 
                , getBundleImportedPackages(context, bundle, admin));
    
    
}