Skip to content

Commit

Permalink
Convert Venmo tests to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lkorth committed Apr 30, 2016
1 parent 54add24 commit 9a3a688
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 599 deletions.

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions Braintree/src/main/java/com/braintreepayments/api/Venmo.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ static void authorizeAccount(BraintreeFragment fragment, Configuration configura
String exceptionMessage = "";
VenmoConfiguration venmoConfiguration = configuration.getPayWithVenmo();
if(!venmoConfiguration.isAccessTokenValid()) {
exceptionMessage = "Venmo is not enabled in the control panel.";
exceptionMessage = "Venmo is not enabled";
} else if (!Venmo.isVenmoInstalled(fragment.getApplicationContext())) {
exceptionMessage = "Venmo is not installed.";
exceptionMessage = "Venmo is not installed";
} else if (!venmoConfiguration.isVenmoWhitelisted(fragment.getApplicationContext().getContentResolver())) {
exceptionMessage = "Venmo is not whitelisted.";
exceptionMessage = "Venmo is not whitelisted";
}

if(!TextUtils.isEmpty(exceptionMessage)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.braintreepayments.api.Venmo;

import org.json.JSONObject;
import org.w3c.dom.Text;

/**
* Contains the remote Pay with Venmo configuration for the Braintree SDK.
Expand Down Expand Up @@ -66,17 +65,14 @@ public boolean isAccessTokenValid() {
}

public boolean isVenmoWhitelisted(ContentResolver contentResolver) {
Cursor cursor = contentResolver
.query(VENMO_AUTHORITY_URI, null, null, null, null);
Cursor cursor = contentResolver.query(VENMO_AUTHORITY_URI, null, null, null, null);

boolean isVenmoWhiteListed =
cursor != null && cursor.moveToFirst() && "true".equals(cursor.getString(0));
boolean isVenmoWhiteListed = cursor != null && cursor.moveToFirst() && "true".equals(cursor.getString(0));

if (cursor != null) {
cursor.close();
}

return isVenmoWhiteListed;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.braintreepayments.api;

import android.content.Context;

import com.braintreepayments.api.interfaces.ConfigurationListener;
import com.braintreepayments.api.interfaces.HttpResponseCallback;
import com.braintreepayments.api.internal.BraintreeHttpClient;
Expand All @@ -18,11 +20,21 @@

public class MockFragmentBuilder {

private Context mContext;
private Authorization mAuthorization;
private Configuration mConfiguration;
private String mSuccessResponse;
private Exception mErrorResponse;

public MockFragmentBuilder() {
mContext = RuntimeEnvironment.application;
}

public MockFragmentBuilder context(Context context) {
mContext = context;
return this;
}

public MockFragmentBuilder authorization(Authorization authorization) {
mAuthorization = authorization;
return this;
Expand All @@ -45,7 +57,7 @@ public MockFragmentBuilder errorResponse(Exception exception) {

public BraintreeFragment build() {
BraintreeFragment fragment = mock(BraintreeFragment.class);
when(fragment.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
when(fragment.getApplicationContext()).thenReturn(mContext);
when(fragment.getAuthorization()).thenReturn(mAuthorization);

doAnswer(new Answer() {
Expand Down
Loading

0 comments on commit 9a3a688

Please sign in to comment.