RideRequestDeeplink implements Deeplink { @NonNull public Uri getUri() { return uri; } RideRequestDeeplink(@NonNull Context context,
            @NonNull Uri uri,
            @NonNull AppProtocol appProtocol,
            @NonNull CustomTabsHelper customTabsHelper); void execute(); @Override boolean isSupported(); @NonNull Uri getUri();  }
@Test public void onBuildDeeplink_whenClientIdAndDefaultRideParamsProvided_shouldHaveDefaults() throws IOException { String expectedUri = readUriResourceWithUserAgentParam("src/test/resources/deeplinkuris/just_client_provided", USER_AGENT_DEEPLINK); RideParameters rideParameters = new RideParameters.Builder().build(); RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertEquals("URI does not match.", expectedUri, deeplink.getUri().toString()); }
@Test public void onBuildDeeplink_whenFullRideParamsProvided_shouldCompleteUri() throws IOException { String expectedUri = readUriResourceWithUserAgentParam("src/test/resources/deeplinkuris/full_details_uri", USER_AGENT_DEEPLINK); RideParameters rideParameters = new RideParameters.Builder() .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR) .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR) .setProductId(PRODUCT_ID) .build(); RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertEquals("URI does not match.", expectedUri, deeplink.getUri().toString()); }
@Test public void onBuildDeeplink_whenPickupAndClientIdProvided_shouldNotHaveDropoffOrProduct() throws IOException { String path = "src/test/resources/deeplinkuris/pickup_and_client_provided"; String expectedUri = readUriResourceWithUserAgentParam(path, USER_AGENT_DEEPLINK); RideParameters rideParameters = new RideParameters.Builder() .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR) .build(); RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertEquals("URI does not match.", expectedUri, deeplink.getUri().toString()); }
@Test public void onBuildDeeplink_whenDropoffClientIdAndProductIdProvided_shouldHaveDefaultPickupAndFullDropoff() throws IOException { String path = "src/test/resources/deeplinkuris/dropoff_client_and_product_provided"; String expectedUri = readUriResourceWithUserAgentParam(path, USER_AGENT_DEEPLINK); RideParameters rideParameters = new RideParameters.Builder() .setProductId(PRODUCT_ID) .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR) .build(); RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertEquals("URI does not match.", expectedUri, deeplink.getUri().toString()); }
@Test public void onBuildDeeplink_whenNoNicknameOrAddressProvided_shouldNotHaveNicknameAndAddress() throws IOException { String expectedUri = readUriResourceWithUserAgentParam("src/test/resources/deeplinkuris/missing_nickname_or_address", USER_AGENT_DEEPLINK); RideParameters rideParameters = new RideParameters.Builder() .setProductId(PRODUCT_ID) .setPickupLocation(PICKUP_LAT, PICKUP_LONG, null, null) .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, null, null) .build(); RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertEquals("URI does not match.", expectedUri, deeplink.getUri().toString()); }
@Test public void getUri_whenUberAppInstalledAndAppLinkSupported_shouldUseAppLink() throws IOException { String expectedUri = readUriResourceWithUserAgentParam ("src/test/resources/deeplinkuris/mobile_web_ul_just_client_provided", USER_AGENT_DEEPLINK); when(appProtocol.isAppLinkSupported()).thenReturn(true); RideParameters rideParameters = new RideParameters.Builder().build(); RideRequestDeeplink rideRequestDeeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertThat(rideRequestDeeplink.getUri().toString()).isEqualTo(expectedUri); }
@Test public void getUri_whenUberAppInstalledAndAppLinkNotSupported_shouldUseNativeLink() throws IOException { String expectedUri = readUriResourceWithUserAgentParam ("src/test/resources/deeplinkuris/just_client_provided", USER_AGENT_DEEPLINK); when(appProtocol.isAppLinkSupported()).thenReturn(false); RideParameters rideParameters = new RideParameters.Builder().build(); RideRequestDeeplink rideRequestDeeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertThat(rideRequestDeeplink.getUri().toString()).isEqualTo(expectedUri); }
@Test public void getUri_whenUberAppNotInstalledAndFallbackMobileWeb_shouldUseMobileWeb() throws IOException { String expectedUri = readUriResourceWithUserAgentParam ("src/test/resources/deeplinkuris/mobile_web_just_client_provided", USER_AGENT_DEEPLINK); when(appProtocol.isInstalled(eq(context), eq(UBER))).thenReturn(false); RideParameters rideParameters = new RideParameters.Builder().build(); RideRequestDeeplink rideRequestDeeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .setFallback(Deeplink.Fallback.MOBILE_WEB) .build(); assertThat(rideRequestDeeplink.getUri().toString()).isEqualTo(expectedUri); }
@Test public void getUri_whenUberAppNotInstalledAndFallbackAppInstall_shouldUseAppInstall() throws IOException { String expectedUri = readUriResourceWithUserAgentParam ("src/test/resources/deeplinkuris/mobile_web_ul_just_client_provided", USER_AGENT_DEEPLINK); when(appProtocol.isInstalled(eq(context), eq(UBER))).thenReturn(false); RideParameters rideParameters = new RideParameters.Builder().build(); RideRequestDeeplink rideRequestDeeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .setFallback(Deeplink.Fallback.APP_INSTALL) .build(); assertThat(rideRequestDeeplink.getUri().toString()).isEqualTo(expectedUri); }
@Test public void getUri_whenUberAppNotInstalledAndFallbackNotSet_shouldUseAppInstall() throws IOException { String expectedUri = readUriResourceWithUserAgentParam ("src/test/resources/deeplinkuris/mobile_web_ul_just_client_provided", USER_AGENT_DEEPLINK); when(appProtocol.isInstalled(eq(context), eq(UBER))).thenReturn(false); RideParameters rideParameters = new RideParameters.Builder().build(); RideRequestDeeplink rideRequestDeeplink = new RideRequestDeeplink.Builder(context) .setAppProtocol(appProtocol) .setRideParameters(rideParameters) .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build()) .build(); assertThat(rideRequestDeeplink.getUri().toString()).isEqualTo(expectedUri); }