BestPackageFinder { @WorkerThread public String findBestPackage(Context context) { PackageManager packageManager = context.getPackageManager(); List<String> packagesSupportingCustomTabs = getPackagesSupportingCustomTabs(packageManager); if (packagesSupportingCustomTabs.isEmpty()) { return NO_PACKAGE_FOUND; } String defaultPackage = getDefaultPackage(packageManager); if (packagesSupportingCustomTabs.contains(defaultPackage)) { return defaultPackage; } return packagesSupportingCustomTabs.get(0); }  @WorkerThread String findBestPackage(Context context);  }
@Test public void returnsEmptyPackageIfNoPackageSupportingCustomTabsIsFound() { givenThatThereIsNoPackagesSupportingCustomTabs(); assertThat(bestPackageFinder.findBestPackage(mockActivity)).isEmpty(); }
@Test public void returnsDefaultPackageIfPresentOnTheListOfPackagesSupportingCustomTabs() { givenThatDefaultPackageIs(DEFAULT_PACKAGE); givenThatPackagesSupportingCustomTabsIs(DEFAULT_PACKAGE); assertThat(bestPackageFinder.findBestPackage(mockActivity)).isEqualTo(DEFAULT_PACKAGE); }
@Test public void returnsFirstInListOfPackagesSupportingCustomTabsIfDefaultNotPresent() { givenThatDefaultPackageIs(DEFAULT_PACKAGE); givenThatPackagesSupportingCustomTabsIs(OTHER_PACKAGE); assertThat(bestPackageFinder.findBestPackage(mockActivity)).isEqualTo(OTHER_PACKAGE); }