DonationActivity extends ThemeActivity implements
        SkuDetailsResponseListener,
        PurchasesUpdatedListener,
        SkuSelectionListener { @Override public void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases) { log("onPurchasesUpdated(" + result + ", " + purchases + ")"); String message; switch (result.getResponseCode()) { case OK: if (purchases != null) { for (Purchase p : purchases) { acknowledgePurchase(p); } } message = getString(R.string.ui_donation_success_message); break; case ITEM_UNAVAILABLE: message = getString(R.string.ui_donation_failure_message, getString(R.string.donation_error_unavailable)); break; case ITEM_ALREADY_OWNED: message = getString(R.string.ui_donation_failure_message, getString(R.string.donation_error_already_owned)); break; case USER_CANCELED: message = getString(R.string.ui_donation_failure_message, getString(R.string.donation_error_canceled)); break; case BILLING_UNAVAILABLE: case FEATURE_NOT_SUPPORTED: case ITEM_NOT_OWNED: case SERVICE_DISCONNECTED: case SERVICE_UNAVAILABLE: case DEVELOPER_ERROR: case ERROR: case SERVICE_TIMEOUT: default: message = getString(R.string.ui_donation_failure_message, getString(R.string.donation_unspecified_error, result.getResponseCode())); break; } Toast.makeText(this, message, LENGTH_LONG).show(); finish(); }  void onCreate(Bundle savedInstanceState); @Override void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> details); @Override void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases); @Override void selectedSku(SkuDetails details); static void checkUserDonationStatus(Context context,
                                               final DonationStatusListener listener);  }
@Test public void testResultMessageOK() { activity.onPurchasesUpdated(BillingResult.newBuilder().setResponseCode(OK).build(), Collections.<Purchase>emptyList()); assertToast("Donation successful, thank you!"); }
@Test public void testResultMessageItemUnavailable() { activity.onPurchasesUpdated(BillingResult.newBuilder().setResponseCode(ITEM_UNAVAILABLE).build(), Collections.<Purchase>emptyList()); assertToast("Donation failed: not available"); }
@Test public void testResultMessageItemAlreadyOwned() { activity.onPurchasesUpdated(BillingResult.newBuilder().setResponseCode(ITEM_ALREADY_OWNED).build(), Collections.<Purchase>emptyList()); assertToast("Donation failed: you have already donated"); }
@Test public void testResultMessageUserCanceled() { activity.onPurchasesUpdated(BillingResult.newBuilder().setResponseCode(USER_CANCELED).build(), Collections.<Purchase>emptyList()); assertToast("Donation failed: canceled"); }
@Test public void testResultMessageError() { activity.onPurchasesUpdated(BillingResult.newBuilder().setResponseCode(ERROR).build(), Collections.<Purchase>emptyList()); assertToast("Donation failed: unspecified error: 6"); }