@Nonnull static Skus fromBundle(@Nonnull Bundle bundle, @Nonnull String product) throws RequestException { final List<String> list = extractList(bundle); final List<Sku> skus = new ArrayList<>(list.size()); for (String response : list) { try { skus.add(Sku.fromJson(response, product)); } catch (JSONException e) { throw new RequestException(e); } } return new Skus(product, skus); }
protected void populateSkus() throws Exception { final List<Sku> expectedInAppSkus = asList(Sku.fromJson(SkuTest.newInAppJson("1"), IN_APP), Sku.fromJson(SkuTest.newInAppJson("2"), IN_APP), Sku.fromJson(SkuTest.newInAppJson("3"), IN_APP), Sku.fromJson(SkuTest.newInAppJson("4"), IN_APP), Sku.fromJson(SkuTest.newInAppJson("6"), IN_APP)); insertSkus(IN_APP, expectedInAppSkus); final List<Sku> expectedSubSkus = asList( Sku.fromJson(SkuTest.newSubscriptionJson("sub1"), SUBSCRIPTION), Sku.fromJson(SkuTest.newSubscriptionJson("sub2"), SUBSCRIPTION), Sku.fromJson(SkuTest.newSubscriptionJson("sub3"), SUBSCRIPTION), Sku.fromJson(SkuTest.newSubscriptionJson("sub4"), SUBSCRIPTION)); insertSkus(SUBSCRIPTION, expectedSubSkus); }
@Test public void testShouldReadIntroductoryPrice() throws Exception { final JSONObject json = newInAppJsonObject("1"); json.put("introductoryPrice", "1 000 000EUR"); final Sku sku = Sku.fromJson(json.toString(), "test"); assertEquals("1 000 000EUR", sku.introductoryPrice); }
@Test public void testShouldReadIntroductoryPriceCycles() throws Exception { final JSONObject json = newInAppJsonObject("1"); json.put("introductoryPriceCycles", 42); final Sku sku = Sku.fromJson(json.toString(), "test"); assertEquals(sku.introductoryPriceCycles, 42); } }
private void testDetailedPrice(long amount, @Nonnull String currency) throws JSONException { final JSONObject json = newInAppJsonObject("1"); json.put("price_amount_micros", amount); json.put("price_currency_code", currency); final Sku sku = Sku.fromJson(json.toString(), "test"); assertTrue(sku.detailedPrice.isValid()); assertEquals(currency, sku.detailedPrice.currency); assertEquals(amount, sku.detailedPrice.amount); }
@Test public void testShouldStripSimpleAppNameWithBracketsFromTitleWithBrackets() throws Exception { final JSONObject json = newInAppJsonObject("1"); json.put("title", "Test #1 (test) (Test App name (test))"); final Sku sku = Sku.fromJson(json.toString(), "test"); final String displayTitle = sku.getDisplayTitle(); assertEquals("Test #1 (test)", displayTitle); }
@Test public void testShouldStripSimpleAppNameFromTitleWithBrackets() throws Exception { final JSONObject json = newInAppJsonObject("1"); json.put("title", "Test #1 (test) (Test App name)"); final Sku sku = Sku.fromJson(json.toString(), "test"); final String displayTitle = sku.getDisplayTitle(); assertEquals("Test #1 (test)", displayTitle); }
@Test public void testShouldStripSimpleAppNameFromTitle() throws Exception { final JSONObject json = newInAppJsonObject("1"); json.put("title", "Test #1 (Test App name)"); final Sku sku = Sku.fromJson(json.toString(), "test"); final String displayTitle = sku.getDisplayTitle(); assertEquals("Test #1", displayTitle); }
private void testIntroductoryPrice(long amount, @Nonnull String currency) throws JSONException { final JSONObject json = newSubscriptionJsonObject("1"); json.put("introductoryPriceAmountMicros", amount); json.put("price_currency_code", currency); final Sku sku = Sku.fromJson(json.toString(), "test"); assertNotNull(sku.detailedIntroductoryPrice); assertTrue(sku.detailedIntroductoryPrice.isValid()); assertEquals(currency, sku.detailedIntroductoryPrice.currency); assertEquals(amount, sku.detailedIntroductoryPrice.amount); }
@Test public void testShouldNotPutEmptyFieldsInJson() throws Exception { final Sku sku = Sku.fromJson(newInAppJsonObject("1").toString(), "test"); final JSONObject json = sku.toJsonObject(); assertTrue(!json.has("subscriptionPeriod")); assertTrue(!json.has("freeTrialPeriod")); assertTrue(!json.has("introductoryPricePeriod")); assertTrue(!json.has("introductoryPriceAmountMicros")); }
@Test public void testInAppSkuShouldBeCreatedFromJson() throws Exception { final Sku sku = Sku.fromJson(newInAppJson("1"), ProductTypes.IN_APP); verifySku(sku, "1"); }
@Test public void testShouldNotCreateIfNoId() throws Exception { final JSONObject json = newInAppJsonObject("2"); json.remove("productId"); try { Sku.fromJson(json.toString(), "test"); fail(); } catch (JSONException e) { } }
@Test public void testSubscriptionSkuShouldBeCreatedFromJson() throws Exception { final Sku sku = Sku.fromJson(newSubscriptionJson("1"), ProductTypes.SUBSCRIPTION); verifySku(sku, "1"); }
@Test public void testShouldHaveNotValidPriceIfNoDetailedDataAvailable() throws Exception { final Sku sku = Sku.fromJson(newInAppJson("1"), "test"); assertFalse(sku.detailedPrice.isValid()); }
@Test public void testShouldCreateWithoutDescription() throws Exception { final JSONObject json = newInAppJsonObject("3"); json.remove("description"); final Sku sku = Sku.fromJson(json.toString(), "test"); assertEquals("3", sku.id.code); assertEquals("price_3", sku.price); assertEquals("", sku.description); assertEquals("title_3", sku.title); }
@Test public void testShouldHaveNotValidIntroductoryPriceIfNoDetailedDataAvailable() throws Exception { final Sku sku = Sku.fromJson(newSubscriptionJson("1"), "test"); assertNotNull(sku.detailedIntroductoryPrice); assertFalse(sku.detailedIntroductoryPrice.isValid()); }