BundleInfoServiceImpl implements BundleInfoService { @Override @SuppressWarnings("null") public @NotNull Collection<BundleInfo> getBundles() { return Arrays.stream(bundleContext.getBundles()) .map(bundle -> (BundleInfo)new BundleInfoImpl(bundle)) .collect(Collectors.toCollection(() -> new TreeSet<BundleInfo>())); }  @Override @SuppressWarnings("null") @NotNull Collection<BundleInfo> getBundles();  }
@Test void testEmpty() { when(bundleContext.getBundles()).thenReturn(new Bundle[0]); assertTrue(underTest.getBundles().isEmpty()); }
@Test void testBundles() { bundles( bundle("bundle1", BundleState.ACTIVE, BUNDLE_NAME, "Bundle 1", BUNDLE_VERSION, "1.2.3"), bundle("minimalBundle2", BundleState.RESOLVED), bundle("fragmentBundle3", BundleState.INSTALLED, BUNDLE_NAME, "Fragment 1", BUNDLE_VERSION, "1.0", FRAGMENT_HOST, "fragment")); List<BundleInfo> result = ImmutableList.copyOf(underTest.getBundles()); assertEquals(3, result.size()); BundleInfo bundle1 = result.get(0); assertEquals("bundle1", bundle1.getSymbolicName()); assertEquals("Bundle 1", bundle1.getName()); assertEquals(BundleState.ACTIVE, bundle1.getState()); assertEquals("1.2.3", bundle1.getVersion()); assertNotNull(bundle1.getLastModified()); assertFalse(bundle1.isFragment()); BundleInfo fragmentBundle3 = result.get(1); assertEquals("fragmentBundle3", fragmentBundle3.getSymbolicName()); assertEquals("Fragment 1", fragmentBundle3.getName()); assertEquals(BundleState.FRAGMENT, fragmentBundle3.getState()); assertEquals("1.0", fragmentBundle3.getVersion()); assertNotNull(bundle1.getLastModified()); assertTrue(fragmentBundle3.isFragment()); BundleInfo minimalBundle2 = result.get(2); assertEquals("minimalBundle2", minimalBundle2.getSymbolicName()); assertEquals("minimalBundle2", minimalBundle2.getName()); assertEquals(BundleState.RESOLVED, minimalBundle2.getState()); assertEquals("", minimalBundle2.getVersion()); assertNotNull(bundle1.getLastModified()); assertFalse(minimalBundle2.isFragment()); }