CashierPurchase implements Purchase { public static CashierPurchase create(String json) throws JSONException { return create(new JSONObject(json)); }  abstract Product product(); abstract String orderId(); abstract String token(); abstract String receipt(); abstract String developerPayload(); static CashierPurchase create(String json); static CashierPurchase create(JSONObject json); static CashierPurchase create(Product product,
                                       String orderId,
                                       String token,
                                       String receipt,
                                       String developerPayload); JSONObject toJson(); static final String KEY_ORDER_ID; static final String KEY_TOKEN; static final String KEY_RECEIPT; static final String KEY_DEV_PAYLOAD; }
@Test public void acceptsValidJson() throws JSONException { CashierPurchase.create( "{\"micros-price\":1," + "\"cashier-token\":\"a\"," + "\"vendor-id\":\"a\"," + "\"cashier-developer-payload\":\"a\"," + "\"price\":\"1\"," + "\"name\":\"a\"," + "\"cashier-order-id\":\"a\"," + "\"description\":\"a\"," + "\"currency\":\"a\"," + "\"subscription\":true," + "\"sku\":\"a\"," + "\"cashier-receipt\":\"a\"}" ); }
@Test(expected = JSONException.class) public void rejectsInvalidJson() throws JSONException { CashierPurchase.create("bad json"); }