SSOAuthHandler extends AuthHandler { public static boolean isAvailable(Context context) { final PackageManager pm = context.getPackageManager(); return checkAppSignature(pm, TWITTER_PACKAGE_NAME, TWITTER_SIGNATURE) || checkAppSignature(pm, DOGFOOD_PACKAGE_NAME, DOGFOOD_SIGNATURE); } SSOAuthHandler(TwitterAuthConfig authConfig, Callback<TwitterSession> callback,
            int requestCode); @Override boolean authorize(Activity activity); static String availableSSOPackage(PackageManager pm); static boolean isAvailable(Context context);  }
@Test public void testIsAvailable_twitterInstalled() throws PackageManager.NameNotFoundException { final Context mockContext = mock(Context.class); TestUtils.setupTwitterInstalled(mockContext, SSOAuthHandler.TWITTER_SIGNATURE); assertTrue(SSOAuthHandler.isAvailable(mockContext)); }
@Test public void testIsAvailable_twitterInstalledInvalidSignature() throws PackageManager.NameNotFoundException { final Context mockContext = mock(Context.class); TestUtils.setupTwitterInstalled(mockContext, INVALID_SIGNATURE); assertFalse(SSOAuthHandler.isAvailable(mockContext)); }
@Test public void testIsAvailable_twitterInstalledWithValidAndInvalidSignature() throws PackageManager.NameNotFoundException { final Context mockContext = mock(Context.class); TestUtils.setupTwitterInstalled(mockContext, SSOAuthHandler.TWITTER_SIGNATURE, INVALID_SIGNATURE); assertFalse(SSOAuthHandler.isAvailable(mockContext)); }
@Test public void testIsAvailable_twitterDogfoodInstalled() throws PackageManager.NameNotFoundException { final Context mockContext = mock(Context.class); TestUtils.setupTwitterDogfoodInstalled(mockContext, SSOAuthHandler.DOGFOOD_SIGNATURE); assertTrue(SSOAuthHandler.isAvailable(mockContext)); }
@Test public void testIsAvailable_twitterDogfoodInstalledInvalidSignature() throws PackageManager.NameNotFoundException { final Context mockContext = mock(Context.class); TestUtils.setupTwitterDogfoodInstalled(mockContext, INVALID_SIGNATURE); assertFalse(SSOAuthHandler.isAvailable(mockContext)); }
@Test public void testIsAvailable_noSSOAppsInstalled() throws PackageManager.NameNotFoundException { final Context mockContext = mock(Context.class); TestUtils.setupNoSSOAppInstalled(mockContext); assertFalse(SSOAuthHandler.isAvailable(mockContext)); }