InstallSource { @NonNull static InstallSource fromInstallerPackageName(@Nullable final String installerPackageName) { if (GOOGLE_PLAY_STORE_PACKAGE_NAME.equalsIgnoreCase(installerPackageName)) { return new GooglePlayStoreInstallSource(); } else if (AMAZON_APP_STORE_PACKAGE_NAME.equalsIgnoreCase(installerPackageName)) { return new AmazonAppStoreInstallSource(); } else if (AMAZON_UNDERGROUND_PACKAGE_NAME.equalsIgnoreCase(installerPackageName)) { return new AmazonUndergroundInstallSource(); } else if (PACKAGE_INSTALLER_PACKAGE_NAME.equalsIgnoreCase(installerPackageName)) { return new PackageInstallerInstallSource(); } else if (installerPackageName != null) { return new UnrecognizedInstallSource(installerPackageName); } else { return new UnknownInstallSource(); } } private  InstallSource();   }
@Test public void testGooglePlayStoreInstallSourceIsParsedCorrectly() { final InstallSource installSource = InstallSource.fromInstallerPackageName("com.android.vending"); assertTrue( "Package name is correctly identified as belonging to the Google Play Store", installSource instanceof GooglePlayStoreInstallSource); assertEquals( "Google Play Store install source has correct description", "Google Play Store", installSource.toString()); }
@Test public void testAmazonAppStoreInstallSourceIsParsedCorrectly() { InstallSource installSource = InstallSource.fromInstallerPackageName("com.amazon.venezia"); assertTrue( "Package name is correctly identified as belonging to the Amazon Appstore", installSource instanceof AmazonAppStoreInstallSource); assertEquals( "Amazon Appstore install source has correct description", "Amazon Appstore", installSource.toString()); }
@Test public void testAmazonUndergroundInstallSourceIsParsedCorrectly() { final InstallSource installSource = InstallSource.fromInstallerPackageName("com.amazon.mshop.android"); assertTrue( "Package name is correctly identified as belonging to Amazon Underground", installSource instanceof AmazonUndergroundInstallSource); assertEquals( "Amazon Underground install source has correct description", "Amazon Underground", installSource.toString()); }
@Test public void testPackageInstallerInstallSourceIsParsedCorrectly() { final InstallSource installSource = InstallSource.fromInstallerPackageName("com.google.android.packageinstaller"); assertTrue( "Package name is correctly identified as belonging to the Android Package Installer", installSource instanceof PackageInstallerInstallSource); assertEquals( "Package Installer install source has correct description", "Package Installer", installSource.toString()); }
@Test public void testUnrecognizedInstallSourceIsParsedCorrectly() { final String unrecognizedInstallerPackageName = "com.unrecognized"; final InstallSource installSource = InstallSource.fromInstallerPackageName(unrecognizedInstallerPackageName); assertTrue( "Non-null package name is correctly identified as an unrecognized install source", installSource instanceof UnrecognizedInstallSource); assertEquals( "Unrecognized install source returns raw package name as description", unrecognizedInstallerPackageName, installSource.toString()); }
@Test public void testUnknownInstallSourceIsParsedCorrectly() { final InstallSource installSource = InstallSource.fromInstallerPackageName(null); assertTrue( "null package name is correctly identified as an unknown install source", installSource instanceof UnknownInstallSource); assertEquals( "Unknown install source has correct description", "Unknown", installSource.toString()); }