SsoDeeplink implements Deeplink { @Override public boolean isSupported() { return isSupported(FlowVersion.DEFAULT); } private  SsoDeeplink(
            @NonNull Activity activity,
            @NonNull AppProtocol appProtocol,
            @NonNull String clientId,
            @NonNull String redirectUri,
            @NonNull Collection<Scope> requestedScopes,
            @NonNull Collection<String> requestedCustomScopes,
            @NonNull Collection<SupportedAppType> productFlowPriority,
            int requestCode); @Override void execute(); @Override boolean isSupported(); static final int DEFAULT_REQUEST_CODE; }
@Test public void isSupported_ridesNotInstalled_withoutProductPriority_shouldBeFalse() { when(appProtocol.isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED)).thenReturn(false); assertThat(ssoDeeplink.isSupported()).isFalse(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER_EATS), anyInt()); }
@Test public void isSupported_ridesNotInstalled_withoutProductPriority_andRedirectToSdkFlowVersion_shouldBeFalse() { when(appProtocol.isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED)).thenReturn(false); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isFalse(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER_EATS), anyInt()); }
@Test public void isSupported_ridesInstalled_withoutProductPriority_shouldBeTrue() { enableSupport(DEFAULT); assertThat(ssoDeeplink.isSupported()).isTrue(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER_EATS), anyInt()); }
@Test public void isSupported_ridesInstalled_withoutProductPriority_andRedirectToSdkFlowVersion_shouldBeTrue() { enableSupport(REDIRECT_TO_SDK); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isTrue(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER_EATS), anyInt()); }
@Test public void isSupported_eatsNotInstalled_withEatsProductPriority_shouldBeFalse() { when(appProtocol.isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED)).thenReturn(false); ssoDeeplink = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .activityRequestCode(REQUEST_CODE) .redirectUri(REDIRECT_URI) .productFlowPriority(ImmutableList.of(UBER_EATS)) .build(); assertThat(ssoDeeplink.isSupported()).isFalse(); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isFalse(); verify(appProtocol, times(2)).isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER), anyInt()); }
@Test public void isSupported_eatsInstalled_withEatsProductPriority_shouldBeTrue() { when(appProtocol.isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED)).thenReturn(true); ssoDeeplink = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .activityRequestCode(REQUEST_CODE) .redirectUri(REDIRECT_URI) .productFlowPriority(ImmutableList.of(UBER_EATS)) .build(); assertThat(ssoDeeplink.isSupported()).isTrue(); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isTrue(); verify(appProtocol, times(2)).isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER), anyInt()); }
@Test public void isSupported_noneInstalled_withCombinedProductPriority_shouldBeFalse() { when(appProtocol.isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED)).thenReturn(false); when(appProtocol.isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED)).thenReturn(false); ssoDeeplink = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .activityRequestCode(REQUEST_CODE) .redirectUri(REDIRECT_URI) .productFlowPriority(ImmutableList.of(UBER, UBER_EATS)) .build(); assertThat(ssoDeeplink.isSupported()).isFalse(); InOrder orderVerifier = inOrder(appProtocol); orderVerifier.verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED); orderVerifier.verify(appProtocol).isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED); }
@Test public void isSupported_noneInstalled_withCombinedProductPriority_andRedirectToSdkFlowVersion_shouldBeFalse() { when(appProtocol.isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED)).thenReturn(false); when(appProtocol.isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED)).thenReturn(false); ssoDeeplink = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .activityRequestCode(REQUEST_CODE) .redirectUri(REDIRECT_URI) .productFlowPriority(ImmutableList.of(UBER, UBER_EATS)) .build(); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isFalse(); InOrder orderVerifier = inOrder(appProtocol); orderVerifier.verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED); orderVerifier.verify(appProtocol).isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED); }
@Test public void isSupported_bothAppsInstalled_withCombinedProductPriority_shouldBeTrue() { enableSupport(DEFAULT); ssoDeeplink = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .activityRequestCode(REQUEST_CODE) .redirectUri(REDIRECT_URI) .productFlowPriority(ImmutableList.of(UBER, UBER_EATS)) .build(); assertThat(ssoDeeplink.isSupported()).isTrue(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER_EATS), anyInt()); }
@Test public void isSupported_bothAppsInstalled_withCombinedProductPriority_andRedirectToSdkFlowVersion_shouldBeTrue() { enableSupport(REDIRECT_TO_SDK); ssoDeeplink = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .activityRequestCode(REQUEST_CODE) .redirectUri(REDIRECT_URI) .productFlowPriority(ImmutableList.of(UBER, UBER_EATS)) .build(); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isTrue(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED); verify(appProtocol, never()).isInstalled(any(Context.class), eq(UBER_EATS), anyInt()); }
@Test public void isSupported_eatsAppInstalled_withProductPriority_shouldBeTrue() { when(appProtocol.isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED)).thenReturn(false); when(appProtocol.isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED)).thenReturn(true); final SsoDeeplink link = new SsoDeeplink.Builder(activity) .clientId(CLIENT_ID) .scopes(GENERAL_SCOPES) .appProtocol(appProtocol) .productFlowPriority(ImmutableList.of(UBER_EATS)) .build(); assertThat(link.isSupported()).isTrue(); }
@Test public void isSupported_withRidesAppInstalled_andDefaultFlowVersion_andAboveMinDefaultFlowVersion_shouldBeTrue() { when(appProtocol.isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED)).thenReturn(true); when(appProtocol.isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED)).thenReturn(false); assertThat(ssoDeeplink.isSupported()).isTrue(); verify(appProtocol).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_SUPPORTED); }
@Test public void isSupported_withRedirectToSdkFlowVersion_andCantResolveRedirectIntent_shouldBeFalse() { enableSupport(REDIRECT_TO_SDK); packageManager.removeResolveInfosForIntent(redirectIntent, activity.getPackageName()); assertThat(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).isFalse(); verify(appProtocol, never()).isInstalled(activity, UBER, MIN_UBER_RIDES_VERSION_REDIRECT_FLOW_SUPPORTED); verify(appProtocol, never()).isInstalled(activity, UBER_EATS, MIN_UBER_EATS_VERSION_SUPPORTED); }