@Test
public void testListPackages() throws IOException {

    Bundle bundle = Mockito.mock(Bundle.class);
    Bundle impBundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundles()).thenReturn(new Bundle[]{bundle});
    ExportedPackage exported = Mockito.mock(ExportedPackage.class);
    Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
    Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[]{impBundle});
    Mockito.when(exported.getName()).thenReturn("test");
    Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
    Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(4));
    Mockito.when(impBundle.getBundleId()).thenReturn(Long.valueOf(5));
    Mockito.when(admin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[]{exported});
    TabularData table = mbean.listPackages();
    Assert.assertEquals(PackageStateMBean.PACKAGES_TYPE,table.getTabularType());
    Collection values = table.values();
    Assert.assertEquals(1, values.size());
    CompositeData data = (CompositeData) values.iterator().next();
    Long[] exportingBundles = (Long[])data.get(PackageStateMBean.EXPORTING_BUNDLES);
    Assert.assertArrayEquals(new Long[]{Long.valueOf(4)}, exportingBundles);
    String name = (String) data.get(PackageStateMBean.NAME);
    Assert.assertEquals("test", name);
    String version = (String) data.get(PackageStateMBean.VERSION);
    Assert.assertEquals("1.0.0", version);
}