RealPosClient implements PosClient { @Override public void openPointOfSalePlayStoreListing() { Uri uri = isPlayStoreInstalled() ? PLAY_STORE_APP_URL : PLAY_STORE_WEB_URL; Intent playStoreIntent = new Intent(ACTION_VIEW, uri); playStoreIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); context.startActivity(playStoreIntent); } RealPosClient(Context context, String clientId); @NonNull @Override Intent createChargeIntent(@NonNull ChargeRequest chargeRequest); @Override boolean isPointOfSaleInstalled(); @Override void launchPointOfSale(); @Override void openPointOfSalePlayStoreListing(); @NonNull @Override ChargeRequest.Success parseChargeSuccess(@NonNull Intent data); @NonNull @Override ChargeRequest.Error parseChargeError(@NonNull Intent data);  }
@Test public void opensPlayStoreWhenInstalled() throws Exception { client.openPointOfSalePlayStoreListing(); Intent expectedIntent = new Intent(ACTION_VIEW, Uri.parse("market: expectedIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); verify(context).startActivity(expectedIntent); }
@Test public void opensUrlWhenPlayStoreNotInstalled() throws Exception { when(context.getPackageManager().getPackageInfo("com.android.vending", 0)).thenThrow( new PackageManager.NameNotFoundException()); client.openPointOfSalePlayStoreListing(); Intent expectedIntent = new Intent(ACTION_VIEW, Uri.parse("https: expectedIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); verify(context).startActivity(expectedIntent); }