private ArrayList<ShippingMethod> createSampleShippingMethods() { ArrayList<ShippingMethod> shippingMethods = new ArrayList<>(); shippingMethods.add(new ShippingMethod("UPS Ground", "ups-ground", "Arrives in 3-5 days", 0, "USD")); shippingMethods.add(new ShippingMethod("FedEx", "fedex", "Arrives tomorrow", 599, "USD")); return shippingMethods; }
private ArrayList<ShippingMethod> getValidShippingMethods(ShippingInformation shippingInformation) { ArrayList<ShippingMethod> shippingMethods = new ArrayList<>(); shippingMethods.add(new ShippingMethod("UPS Ground", "ups-ground", "Arrives in 3-5 days", 0, "USD")); shippingMethods.add(new ShippingMethod("FedEx", "fedex", "Arrives tomorrow", 599, "USD")); if (shippingInformation.getAddress() != null && shippingInformation.getAddress().getPostalCode().equals("94110")) { shippingMethods.add(new ShippingMethod("1 Hour Courier", "courier", "Arrives in the next hour", 1099, "USD")); } return shippingMethods; }
@Before public void setup() { Locale.setDefault(Locale.US); ActivityController<SelectShippingMethodTestActivity> activityController = Robolectric.buildActivity(SelectShippingMethodTestActivity.class).create().start(); mSelectShippingMethodWidget = activityController.get().getSelectShippingMethodWidget(); mShippingMethods = new ArrayList<>(); ShippingMethod ups = new ShippingMethod("UPS Ground", "ups-ground", "Arrives in 3-5 days", 0, "USD"); ShippingMethod fedEx = new ShippingMethod("FedEx", "fedex", "Arrives tomorrow", 599, "USD"); mShippingMethods.add(ups); mShippingMethods.add(fedEx); mSelectShippingMethodWidget.setShippingMethods(mShippingMethods, ups); mShippingMethodAdapter = mSelectShippingMethodWidget.mShippingMethodAdapter; }
@Test public void onShippingInfoProcessed_whenValidShippingInfoSubmitted_rendersCorrectly() { Intent intent = new Intent(ApplicationProvider.getApplicationContext(), PaymentFlowActivity.class); PaymentSessionConfig paymentSessionConfig = new PaymentSessionConfig.Builder() .setPrepopulatedShippingInfo(getExampleShippingInfo()) .build(); intent.putExtra(PAYMENT_SESSION_CONFIG, paymentSessionConfig); PaymentSessionData paymentSessionData = new PaymentSessionData(); intent.putExtra(PAYMENT_SESSION_DATA_KEY, paymentSessionData); PaymentFlowActivity paymentFlowActivity = createActivity(intent); // valid result paymentFlowActivity.onActionSave(); Intent onShippingInfoProcessedValid = new Intent(EVENT_SHIPPING_INFO_PROCESSED); onShippingInfoProcessedValid.putExtra(EXTRA_IS_SHIPPING_INFO_VALID, true); ArrayList<ShippingMethod> shippingMethods = new ArrayList<>(); shippingMethods.add(new ShippingMethod("label", "id", 0, "USD")); onShippingInfoProcessedValid.putExtra(EXTRA_VALID_SHIPPING_METHODS, shippingMethods); LocalBroadcastManager.getInstance(ApplicationProvider.getApplicationContext()) .sendBroadcast(onShippingInfoProcessedValid); assertEquals(View.VISIBLE, paymentFlowActivity.mProgressBar.getVisibility()); Intent shippingInfoSaved = new Intent(EVENT_SHIPPING_INFO_SAVED); LocalBroadcastManager.getInstance(ApplicationProvider.getApplicationContext()) .sendBroadcast(shippingInfoSaved); assertEquals(View.GONE, paymentFlowActivity.mProgressBar.getVisibility()); }
@Test public void writeToParcel_withoutNulls_readsFromParcelCorrectly() { PaymentSessionData data = new PaymentSessionData(); data.setCartTotal(100L); data.setShippingTotal(150L); data.setSelectedPaymentMethodId("abc123"); data.setPaymentReadyToCharge(false); data.setShippingInformation(new ShippingInformation()); data.setShippingMethod(new ShippingMethod("UPS", "SuperFast", 10000L, "usd")); Parcel parcel = Parcel.obtain(); data.writeToParcel(parcel, 0); parcel.setDataPosition(0); PaymentSessionData parceledData = PaymentSessionData.CREATOR.createFromParcel(parcel); assertEquals(data, parceledData); } }