SSOAuthHandler extends AuthHandler { @Override public boolean authorize(Activity activity) { return startAuthActivityForResult(activity); } 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 testAuthorize_twitterInstalled() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupTwitterInstalled(mockActivity, SSOAuthHandler.TWITTER_SIGNATURE); assertTrue(ssoAuthHandler.authorize(mockActivity)); }
@Test public void testAuthorize_twitterInstalledInvalidSignature() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupTwitterInstalled(mockActivity, INVALID_SIGNATURE); assertFalse(ssoAuthHandler.authorize(mockActivity)); }
@Test public void testAuthorize_twitterDogfoodInstalled() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupTwitterDogfoodInstalled(mockActivity, SSOAuthHandler.DOGFOOD_SIGNATURE); assertTrue(ssoAuthHandler.authorize(mockActivity)); }
@Test public void testAuthorize_twitterDogfoodInstalledInvalidSignature() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupTwitterDogfoodInstalled(mockActivity, INVALID_SIGNATURE); assertFalse(ssoAuthHandler.authorize(mockActivity)); }
@Test public void testAuthorize_twitterInstalledNoSsoActivity() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupTwitterInstalled(mockActivity, SSOAuthHandler.TWITTER_SIGNATURE); when(mockActivity.getPackageManager().queryIntentActivities(any(Intent.class), anyInt())).thenReturn(Collections.emptyList()); assertFalse(ssoAuthHandler.authorize(mockActivity)); }
@Test public void testAuthorize_noSSOAppsInstalled() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupNoSSOAppInstalled(mockActivity); assertFalse(ssoAuthHandler.authorize(mockActivity)); }
@Test public void testAuthorize_startActivityForResultThrowsException() throws PackageManager.NameNotFoundException { final Activity mockActivity = mock(Activity.class); TestUtils.setupTwitterInstalled(mockActivity, SSOAuthHandler.TWITTER_SIGNATURE); doThrow(new RuntimeException()).when(mockActivity) .startActivityForResult(any(Intent.class), eq(REQUEST_CODE)); assertFalse(ssoAuthHandler.authorize(mockActivity)); }