@Test
public void testGetBundleDependencies() throws Exception {

    
    Bundle bundle = mock(Bundle.class);
    BundleContext context = mock(BundleContext.class);
   
    Bundle b1 = mock(Bundle.class);
    when(b1.getSymbolicName()).thenReturn("b1");
    when(b1.getBundleId()).thenReturn(new Long(44));
    Bundle b2 = mock(Bundle.class);
    when(b2.getSymbolicName()).thenReturn("b2");
    when(b2.getBundleId()).thenReturn(new Long(55));
    Bundle b3 = mock(Bundle.class);
    when(b3.getSymbolicName()).thenReturn("b3");
    when(b3.getBundleId()).thenReturn(new Long(66));
    
    when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
    
    Dictionary<String, String> headers = new Hashtable<String, String>();
    when(bundle.getHeaders()).thenReturn(headers);
    
    PackageAdmin admin = mock(PackageAdmin.class);
    assertEquals(0, getBundleDependencies(context, bundle, admin).length);
    
    RequiredBundle rb1 = mock(RequiredBundle.class);
    when(rb1.getBundle()).thenReturn(b1);
    when(rb1.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b2 });
    RequiredBundle rb2 = mock(RequiredBundle.class);
    when(rb2.getBundle()).thenReturn(b2);
    when(rb2.getRequiringBundles()).thenReturn(new Bundle[] { b1 });
    RequiredBundle rb3 = mock(RequiredBundle.class);
    when(rb3.getBundle()).thenReturn(b3);
    when(rb3.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b1, b2 });
    
    headers.put(Constants.REQUIRE_BUNDLE, "b1;bundle-version=\"1.0.0\",b3;bundle-version=\"2.0.0\"");
    
    when(admin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1 });
    when(admin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
    when(admin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
    
    assertEquals(toSet(new long[] { 44, 66 }), toSet(getBundleDependencies(context, bundle, admin)));
}