PackageManagerOperationResolverImpl implements PackageManagerOperationResolver { protected Stream<InstallPlanStep> findPackageChanges(Collection<Package> packagesToInstall, Collection<Package> installedPackages) { return packagesToInstall.stream().flatMap( packageToInstall -> { final String name = packageToInstall.getName(); return installedPackages.stream().filter(pkg -> { return pkg.getName().equals(name); }).map( pkg -> new InstallPlanStep.PackageVersionChangeStep(pkg, packageToInstall)); }); } PackageManagerOperationResolverImpl(Supplier<Collection<Package>> installedPackagesSupplier,
                                             Supplier<Collection<Package>> availablePackagesSupplier); @Override ResolveState resolve(Collection<Package> packagesToInstall, Collection<Package> packagesToUninstall); @Override boolean isValid(ResolveState resolveState);  }
@Test public void testFindPackageChangesWithNonMatchingInstalledPackage() throws Exception { final Package pkg1 = createPackage("pkg1", "1.0-2"); final Package pkg2 = createPackage("pkg2", "1.0-2"); final Stream<InstallPlanStep> stream = resolver().findPackageChanges( singleton(pkg1), singleton(pkg2)); assertEquals(0, stream.count()); }
@Test public void testFindPackageChangesWithSingleInstalledPackageInOdlerVersion() throws Exception { final Package pkg_new = createPackage("pkg1", "1.0-2"); final Package pkg_old = createPackage("pkg1", "1.0-1"); final Stream<InstallPlanStep> stream = resolver().findPackageChanges( singleton(pkg_new), singleton(pkg_old)); final InstallPlanStep step = stream.findFirst().get(); assertThat(step, instanceOf(InstallPlanStep.PackageVersionChangeStep.class)); final InstallPlanStep.PackageVersionChangeStep modification = (InstallPlanStep.PackageVersionChangeStep) step; assertEquals(createVersion("1.0", "1"), modification.getInstalledPackage().getVersion()); assertEquals(createVersion("1.0", "2"), modification.getTargetPackage().getVersion()); }
@Test public void testFindPackageChangesWithMultipleInstalledPackagesNonMatching() throws Exception { final Package pkg_new = createPackage("pkg1", "1.0-2"); final Stream<InstallPlanStep> stream = resolver().findPackageChanges( singleton(pkg_new), Arrays.asList( createPackage("pkg2", "12.0-1"), createPackage("pkg3", "12.0-1"), createPackage("pkg4", "12.0-1"), createPackage("pkg5", "12.0-1") )); assertEquals(0, stream.count()); }
@Test public void testFindPackageChangesWithMultipleInstalledPackagesAndOneInOlderVersion() throws Exception { final Package pkg_new = createPackage("pkg1", "1.0-2"); final Stream<InstallPlanStep> stream = resolver().findPackageChanges( singleton(pkg_new), Arrays.asList( createPackage("pkg2", "12.0-1"), createPackage("pkg3", "12.0-1"), createPackage("pkg4", "12.0-1"), createPackage("pkg1", "1.0-1"), createPackage("pkg5", "12.0-1") )); final InstallPlanStep step = stream.findFirst().get(); assertThat(step, instanceOf(InstallPlanStep.PackageVersionChangeStep.class)); final InstallPlanStep.PackageVersionChangeStep modification = (InstallPlanStep.PackageVersionChangeStep) step; assertEquals(createVersion("1.0", "1"), modification.getInstalledPackage().getVersion()); assertEquals(createVersion("1.0", "2"), modification.getTargetPackage().getVersion()); }
@Test public void testFindPackageChangesWithNoInstalledPackages() throws Exception { final Package pkg1 = createPackage("pkg1", "1.0-2"); final Stream<InstallPlanStep> stream = resolver().findPackageChanges( singleton(pkg1), emptyList()); assertEquals(0, stream.count()); }