コード例 #1
0
  @SmallTest
  public void testOnRequestPurchaseResponse() throws Exception {
    final String testItemId = TransactionTest.TRANSACTION_1.productId;
    final ResponseCode testResponse = ResponseCode.RESULT_OK;
    final Set<Boolean> flags = new HashSet<Boolean>();
    final IBillingObserver observer =
        new IBillingObserver() {

          public void onTransactionsRestored() {}

          public void onPurchaseIntent(String itemId, PendingIntent purchaseIntent) {}

          public void onBillingChecked(boolean supported) {}

          public void onRequestPurchaseResponse(String itemId, ResponseCode response) {
            flags.add(true);
            assertEquals(testItemId, itemId);
            assertEquals(testResponse, response);
          }

          @Override
          public void onPurchaseStateChanged(String itemId, PurchaseState state) {}
        };
    BillingController.registerObserver(observer);
    BillingController.onRequestPurchaseResponse(testItemId, testResponse);
    assertEquals(flags.size(), 1);
    BillingController.unregisterObserver(observer);
  }
コード例 #2
0
  @SmallTest
  public void testOnTransactionRestored() throws Exception {
    final Set<Boolean> flags = new HashSet<Boolean>();
    final IBillingObserver observer =
        new IBillingObserver() {
          public void onTransactionsRestored() {
            flags.add(true);
          }

          public void onPurchaseIntent(String itemId, PendingIntent purchaseIntent) {}

          public void onBillingChecked(boolean supported) {}

          public void onRequestPurchaseResponse(String itemId, ResponseCode response) {}

          public void onPurchaseStateChanged(String itemId, PurchaseState state) {}
        };
    BillingController.registerObserver(observer);
    BillingController.onTransactionsRestored();
    assertEquals(flags.size(), 1);
    BillingController.unregisterObserver(observer);
  }