### Question:
Purchases { @Nonnull static Purchases fromBundle(@Nonnull Bundle bundle, @Nonnull String product) throws JSONException { final String continuationToken = getContinuationTokenFromBundle(bundle); final List<Purchase> purchases = getListFromBundle(bundle); return new Purchases(product, purchases, continuationToken); } Purchases(@Nonnull String product, @Nonnull List<Purchase> list, @Nullable String continuationToken); @Nonnull String toJson(); @Nonnull String toJson(boolean withSignatures); @Nullable Purchase getPurchase(@Nonnull String sku); boolean hasPurchase(@Nonnull String sku); boolean hasPurchaseInState(@Nonnull String sku, @Nonnull Purchase.State state); @Nullable Purchase getPurchaseInState(@Nonnull String sku, @Nonnull Purchase.State state); @Nonnull
    final String product; @Nonnull
    final List<Purchase> list; @Nullable
    final String continuationToken; }### Answer:
@Test public void testShouldReadEmptyList() throws Exception { final Bundle bundle = new Bundle(); bundle.putStringArrayList(Purchases.BUNDLE_DATA_LIST, new ArrayList<String>()); final Purchases purchases = Purchases.fromBundle(bundle, "test"); assertTrue(purchases.list.isEmpty()); }
@Test public void testShouldReadNullList() throws Exception { final Bundle bundle = new Bundle(); final Purchases purchases = Purchases.fromBundle(bundle, "test"); assertTrue(purchases.list.isEmpty()); }
@Test public void testShouldReadList() throws Exception { final Purchases purchases = Purchases.fromBundle(prepareBundle(), "test"); assertEquals(3, purchases.list.size()); verifyPurchase(purchases.list.get(0), 1, Purchase.State.REFUNDED); verifyPurchase(purchases.list.get(1), 2, Purchase.State.CANCELLED); verifyPurchase(purchases.list.get(2), 3, Purchase.State.PURCHASED); }
@Test public void testShouldReadListWithSignatures() throws Exception { final Bundle bundle = prepareBundle(); final ArrayList<String> signatures = new ArrayList<String>(); signatures.add("sig_1"); signatures.add("sig_2"); signatures.add("sig_3"); bundle.putStringArrayList(Purchases.BUNDLE_SIGNATURE_LIST, signatures); final Purchases purchases = Purchases.fromBundle(bundle, "test"); assertEquals(3, purchases.list.size()); assertEquals("sig_1", purchases.list.get(0).signature); assertEquals("sig_2", purchases.list.get(1).signature); assertEquals("sig_3", purchases.list.get(2).signature); }
@Test public void testShouldReadContinuationToken() throws Exception { final Bundle bundle = prepareBundle(); bundle.putString(Purchases.BUNDLE_CONTINUATION_TOKEN, "token"); final Purchases purchases = Purchases.fromBundle(bundle, "test"); assertEquals("token", purchases.continuationToken); }