@Test public void testProductEqualityComparator() throws Exception { JSONObject product2Json = new JSONObject(mProduct2Json); Product product2 = toProduct(product2Json); assertTrue(isEqual(product2, mProduct2)); product2Json.put("Sku", "00000"); product2 = toProduct(product2Json); assertFalse(isEqual(product2, mProduct2)); }
Product toProduct(JSONObject jsonObject) { if (jsonObject == null) { return null; } try { Product.Builder builder = new Product.Builder(jsonObject.getString(NAME), jsonObject.optString(SKU, null), jsonObject.optDouble(PRICE, 0)); builder.category(jsonObject.optString(CATEGORY, null)); builder.couponCode(jsonObject.optString(COUPON_CODE, null)); if (jsonObject.has(POSITION)) { builder.position(jsonObject.optInt(POSITION, 0)); } if (jsonObject.has(QUANTITY)) { builder.quantity(jsonObject.optDouble(QUANTITY, 1)); } builder.brand(jsonObject.optString(BRAND, null)); builder.variant(jsonObject.optString(VARIANT, null)); Map<String, String> customAttributes = convertToMap(jsonObject.optJSONObject(ATTRIBUTES)); if (customAttributes != null) { builder.customAttributes(customAttributes); } return builder.build(); } catch (JSONException ignore) { return null; } }
MParticleJSInterface { Product toProduct(JSONObject jsonObject) { if (jsonObject == null) { return null; } try { Product.Builder builder = new Product.Builder(jsonObject.getString(NAME), jsonObject.optString(SKU, null), jsonObject.optDouble(PRICE, 0)); builder.category(jsonObject.optString(CATEGORY, null)); builder.couponCode(jsonObject.optString(COUPON_CODE, null)); if (jsonObject.has(POSITION)) { builder.position(jsonObject.optInt(POSITION, 0)); } if (jsonObject.has(QUANTITY)) { builder.quantity(jsonObject.optDouble(QUANTITY, 1)); } builder.brand(jsonObject.optString(BRAND, null)); builder.variant(jsonObject.optString(VARIANT, null)); Map<String, String> customAttributes = convertToMap(jsonObject.optJSONObject(ATTRIBUTES)); if (customAttributes != null) { builder.customAttributes(customAttributes); } return builder.build(); } catch (JSONException ignore) { return null; } } }
MParticleJSInterface { Product toProduct(JSONObject jsonObject) { if (jsonObject == null) { return null; } try { Product.Builder builder = new Product.Builder(jsonObject.getString(NAME), jsonObject.optString(SKU, null), jsonObject.optDouble(PRICE, 0)); builder.category(jsonObject.optString(CATEGORY, null)); builder.couponCode(jsonObject.optString(COUPON_CODE, null)); if (jsonObject.has(POSITION)) { builder.position(jsonObject.optInt(POSITION, 0)); } if (jsonObject.has(QUANTITY)) { builder.quantity(jsonObject.optDouble(QUANTITY, 1)); } builder.brand(jsonObject.optString(BRAND, null)); builder.variant(jsonObject.optString(VARIANT, null)); Map<String, String> customAttributes = convertToMap(jsonObject.optJSONObject(ATTRIBUTES)); if (customAttributes != null) { builder.customAttributes(customAttributes); } return builder.build(); } catch (JSONException ignore) { return null; } } MParticleJSInterface(); }
MParticleJSInterface { Product toProduct(JSONObject jsonObject) { if (jsonObject == null) { return null; } try { Product.Builder builder = new Product.Builder(jsonObject.getString(NAME), jsonObject.optString(SKU, null), jsonObject.optDouble(PRICE, 0)); builder.category(jsonObject.optString(CATEGORY, null)); builder.couponCode(jsonObject.optString(COUPON_CODE, null)); if (jsonObject.has(POSITION)) { builder.position(jsonObject.optInt(POSITION, 0)); } if (jsonObject.has(QUANTITY)) { builder.quantity(jsonObject.optDouble(QUANTITY, 1)); } builder.brand(jsonObject.optString(BRAND, null)); builder.variant(jsonObject.optString(VARIANT, null)); Map<String, String> customAttributes = convertToMap(jsonObject.optJSONObject(ATTRIBUTES)); if (customAttributes != null) { builder.customAttributes(customAttributes); } return builder.build(); } catch (JSONException ignore) { return null; } } MParticleJSInterface(); @JavascriptInterface String getCurrentMpId(); @JavascriptInterface void login(); @JavascriptInterface void login(String json); @JavascriptInterface void logout(); @JavascriptInterface void logout(String json); @JavascriptInterface void modify(String json); @JavascriptInterface void logEvent(String json); @JavascriptInterface void setUserTag(String json); @JavascriptInterface void removeUserTag(String json); @JavascriptInterface void setUserAttribute(String json); @JavascriptInterface void removeUserAttribute(String json); @JavascriptInterface void setSessionAttribute(String json); @JavascriptInterface void setUserIdentity(String json); @JavascriptInterface void removeUserIdentity(String json); @JavascriptInterface void addToCart(String json); @JavascriptInterface void removeFromCart(String json); @JavascriptInterface void clearCart(); @JavascriptInterface void setUserAttributeList(String json); @JavascriptInterface void removeAllUserAttributes(); @JavascriptInterface String getUserAttributesLists(); @JavascriptInterface String getAllUserAttributes(); static void registerWebView(WebView webView, String workspaceToken); }
MParticleJSInterface { Product toProduct(JSONObject jsonObject) { if (jsonObject == null) { return null; } try { Product.Builder builder = new Product.Builder(jsonObject.getString(NAME), jsonObject.optString(SKU, null), jsonObject.optDouble(PRICE, 0)); builder.category(jsonObject.optString(CATEGORY, null)); builder.couponCode(jsonObject.optString(COUPON_CODE, null)); if (jsonObject.has(POSITION)) { builder.position(jsonObject.optInt(POSITION, 0)); } if (jsonObject.has(QUANTITY)) { builder.quantity(jsonObject.optDouble(QUANTITY, 1)); } builder.brand(jsonObject.optString(BRAND, null)); builder.variant(jsonObject.optString(VARIANT, null)); Map<String, String> customAttributes = convertToMap(jsonObject.optJSONObject(ATTRIBUTES)); if (customAttributes != null) { builder.customAttributes(customAttributes); } return builder.build(); } catch (JSONException ignore) { return null; } } MParticleJSInterface(); @JavascriptInterface String getCurrentMpId(); @JavascriptInterface void login(); @JavascriptInterface void login(String json); @JavascriptInterface void logout(); @JavascriptInterface void logout(String json); @JavascriptInterface void modify(String json); @JavascriptInterface void logEvent(String json); @JavascriptInterface void setUserTag(String json); @JavascriptInterface void removeUserTag(String json); @JavascriptInterface void setUserAttribute(String json); @JavascriptInterface void removeUserAttribute(String json); @JavascriptInterface void setSessionAttribute(String json); @JavascriptInterface void setUserIdentity(String json); @JavascriptInterface void removeUserIdentity(String json); @JavascriptInterface void addToCart(String json); @JavascriptInterface void removeFromCart(String json); @JavascriptInterface void clearCart(); @JavascriptInterface void setUserAttributeList(String json); @JavascriptInterface void removeAllUserAttributes(); @JavascriptInterface String getUserAttributesLists(); @JavascriptInterface String getAllUserAttributes(); static void registerWebView(WebView webView, String workspaceToken); static final String INTERFACE_BASE_NAME; }