@Override public ShippingInformation createFromParcel(Parcel source) { return new ShippingInformation(source); }
@Nullable public static ShippingInformation fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } ShippingInformation shippingInformation = new ShippingInformation(); shippingInformation.mName = optString(jsonObject, FIELD_NAME); shippingInformation.mPhone = optString(jsonObject, FIELD_PHONE); shippingInformation.mAddress = Address.fromJson(jsonObject.optJSONObject(FIELD_ADDRESS)); return shippingInformation; }
public ShippingInformation getShippingInformation() { if (!validateAllFields()) { return null; } Address address = new Address.Builder().setCity(mCityEditText.getText().toString()) .setCountry(mCountryAutoCompleteTextView.getSelectedCountryCode()).setLine1 (mAddressEditText.getText().toString()).setLine2 (mAddressEditText2.getText().toString()).setPostalCode (mPostalCodeEditText.getText().toString()).setState(mStateEditText .getText().toString()).build(); ShippingInformation shippingInformation = new ShippingInformation(address, mNameEditText .getText().toString(), mPhoneNumberEditText.getText().toString()); return shippingInformation; }
private ShippingInformation getExampleShippingInfo() { Address address = new Address.Builder() .setCity("San Francisco") .setCountry("US") .setLine1("123 Market St") .setLine2("#345") .setPostalCode("94107") .setState("CA") .build(); return new ShippingInformation(address, "Fake Name", "(555) 555-5555"); } }
@NonNull private ShippingInformation getExampleShippingInfo() { Address address = new Address.Builder() .setCity("San Francisco") .setCountry("US") .setLine1("123 Market St") .setLine2("#345") .setPostalCode("94107") .setState("CA") .build(); return new ShippingInformation(address, "Fake Name", "(555) 555-5555"); }
@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); } }
.setPostalCode("12345") .build(); mShippingInfo = new ShippingInformation(mAddress, "Fake Name", "(123) 456 - 7890");