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; }
void setShippingMethod(@NonNull ShippingMethod shippingMethod) { mLabel.setText(shippingMethod.getLabel()); mDetail.setText(shippingMethod.getDetail()); mAmount.setText(PaymentUtils.formatPriceStringUsingFree( shippingMethod.getAmount(), shippingMethod.getCurrency(), getContext().getString(R.string.price_free))); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PaymentSessionData that = (PaymentSessionData) o; if (mCartTotal != that.mCartTotal) return false; if (mIsPaymentReadyToCharge != that.mIsPaymentReadyToCharge) return false; if (mShippingTotal != that.mShippingTotal) return false; if (!mSelectedPaymentMethodId.equals(that.mSelectedPaymentMethodId)) return false; if (!mPaymentResult.equals(that.mPaymentResult)) return false; if (mShippingInformation != null ? !mShippingInformation.equals(that.mShippingInformation) : that.mShippingInformation != null) { return false; } return mShippingMethod != null ? mShippingMethod.equals(that.mShippingMethod) : that.mShippingMethod == null; }
@Override public int hashCode() { int result = (int) (mCartTotal ^ (mCartTotal >>> 32)); result = 31 * result + (mIsPaymentReadyToCharge ? 1 : 0); result = 31 * result + mSelectedPaymentMethodId.hashCode(); result = 31 * result + (int) (mShippingTotal ^ (mShippingTotal >>> 32)); result = 31 * result + mPaymentResult.hashCode(); result = 31 * result + (mShippingInformation != null ? mShippingInformation.hashCode() : 0); result = 31 * result + (mShippingMethod != null ? mShippingMethod.hashCode() : 0); return result; }
@Test public void testMapCreation() { assertMapEquals(mShippingMethod.toMap(), EXAMPLE_MAP_SHIPPING_ADDRESS); } }
@Test public void testJSONConversion() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_SHIPPING_ADDRESS); assertJsonEquals(mShippingMethod.toJson(), rawConversion); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
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); } }