@Test public void contains_packagesWithSameName() throws Exception { Mockito.when(packageA1.getName()).thenReturn("A"); Mockito.when(packageA2.getName()).thenReturn("A"); Mockito.when(packageA1.getPackageState()).thenReturn(PackageState.DOWNLOADED); Mockito.when(packageA2.getPackageState()).thenReturn(PackageState.INSTALLED); Mockito.when(service.getPackages()).thenReturn(packages); assertThat(helper.contains("A")).isTrue(); }
public boolean contains(String name) { try { if (name.contains(":")) { name = name.replace(':', '-'); Package pkg = service.getPackage(name); return pkg != null && isPackageInstalled(pkg); } else { for (Package pkg : service.getPackages()) { if (pkg.getName().equals(name) && isPackageInstalled(pkg)) { return true; } } return false; } } catch (PackageException e) { return false; } }
PackagesHelper { public boolean contains(String name) { try { if (name.contains(":")) { name = name.replace(':', '-'); Package pkg = service.getPackage(name); return pkg != null && isPackageInstalled(pkg); } else { for (Package pkg : service.getPackages()) { if (pkg.getName().equals(name) && isPackageInstalled(pkg)) { return true; } } return false; } } catch (PackageException e) { return false; } } }
PackagesHelper { public boolean contains(String name) { try { if (name.contains(":")) { name = name.replace(':', '-'); Package pkg = service.getPackage(name); return pkg != null && isPackageInstalled(pkg); } else { for (Package pkg : service.getPackages()) { if (pkg.getName().equals(name) && isPackageInstalled(pkg)) { return true; } } return false; } } catch (PackageException e) { return false; } } PackagesHelper(PackageUpdateService service); }
PackagesHelper { public boolean contains(String name) { try { if (name.contains(":")) { name = name.replace(':', '-'); Package pkg = service.getPackage(name); return pkg != null && isPackageInstalled(pkg); } else { for (Package pkg : service.getPackages()) { if (pkg.getName().equals(name) && isPackageInstalled(pkg)) { return true; } } return false; } } catch (PackageException e) { return false; } } PackagesHelper(PackageUpdateService service); boolean contains(String name); }
PackagesHelper { public boolean contains(String name) { try { if (name.contains(":")) { name = name.replace(':', '-'); Package pkg = service.getPackage(name); return pkg != null && isPackageInstalled(pkg); } else { for (Package pkg : service.getPackages()) { if (pkg.getName().equals(name) && isPackageInstalled(pkg)) { return true; } } return false; } } catch (PackageException e) { return false; } } PackagesHelper(PackageUpdateService service); boolean contains(String name);  }