@Test public void execute_whenUberAppInsalled_shouldPointToUberApp() throws IOException { String expectedUri = readUriResourceWithUserAgentParam( "src/test/resources/deeplinkuris/just_client_provided", USER_AGENT_DEEPLINK); Activity activity = Robolectric.setupActivity(Activity.class); ShadowActivity shadowActivity = shadowOf(activity); RobolectricPackageManager packageManager = (RobolectricPackageManager) shadowActivity.getPackageManager(); PackageInfo uberPackage = new PackageInfo(); uberPackage.packageName = UBER_PACKAGE_NAME; packageManager.addPackage(uberPackage); RideParameters rideParameters = new RideParameters.Builder().build(); RequestDeeplink requestDeeplink = new RequestDeeplink.Builder() .setClientId(CLIENT_ID) .setRideParameters(rideParameters) .build(); requestDeeplink.execute(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); assertEquals(expectedUri, startedIntent.getData().toString()); }
@Test public void execute_whenNoUberApp_shouldPointToMobileSite() throws IOException { String expectedUri = readUriResourceWithUserAgentParam( "src/test/resources/deeplinkuris/no_app_installed", USER_AGENT_DEEPLINK); Activity activity = Robolectric.setupActivity(Activity.class); ShadowActivity shadowActivity = shadowOf(activity); RideParameters rideParameters = new RideParameters.Builder().build(); RequestDeeplink requestDeeplink = new RequestDeeplink.Builder() .setClientId(CLIENT_ID) .setRideParameters(rideParameters) .build(); requestDeeplink.execute(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); assertEquals(expectedUri, startedIntent.getData().toString()); }