Skip to content

Commit

Permalink
Fix AnalyticsManager test pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
lkorth committed Nov 10, 2015
1 parent e10d226 commit fb85062
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.provider.Settings.Secure;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.FlakyTest;
import android.test.suitebuilder.annotation.SmallTest;

import com.braintreepayments.api.exceptions.InvalidArgumentException;
Expand Down Expand Up @@ -48,6 +47,8 @@
@SmallTest
public class AnalyticsManagerTest {

private static final String TEST_UUID = "testuuid";

@Rule
public final ActivityTestRule<TestActivity> mActivityTestRule =
new ActivityTestRule<>(TestActivity.class);
Expand Down Expand Up @@ -230,15 +231,10 @@ public void post(String path, String data, HttpResponseCallback callback) {
}

@Test(timeout = 1000)
@FlakyTest(tolerance = 3)
public void newRequest_sendsCorrectMetaData() throws JSONException {
setup();

String uuid = "testuuid";
AnalyticsManager.sendRequest(mFragment, "custom", "some-interesting-event");
getTargetContext().getSharedPreferences("BraintreeApi", Context.MODE_PRIVATE).edit()
.putString("braintreeUUID", uuid)
.commit();
AnalyticsManager.flushEvents(mFragment);

ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
Expand All @@ -253,7 +249,7 @@ public void newRequest_sendsCorrectMetaData() throws JSONException {
assertEquals(Build.MODEL, json.getString("deviceModel"));
assertEquals(Secure.getString(getTargetContext().getContentResolver(), Secure.ANDROID_ID),
json.getString("androidId"));
assertEquals(uuid, json.getString("deviceAppGeneratedPersistentUuid"));
assertEquals(TEST_UUID, json.getString("deviceAppGeneratedPersistentUuid"));
assertEquals("true", json.getString("isSimulator"));
assertEquals("Portrait", json.getString("userInterfaceOrientation"));
assertEquals("custom", json.getString("integrationType"));
Expand All @@ -262,9 +258,11 @@ public void newRequest_sendsCorrectMetaData() throws JSONException {
}

public void setup() throws JSONException {
mFragment = generateFragment();
getTargetContext().getSharedPreferences("BraintreeApi", Context.MODE_PRIVATE).edit().clear()
getTargetContext().getSharedPreferences("BraintreeApi", Context.MODE_PRIVATE)
.edit()
.putString("braintreeUUID", TEST_UUID)
.commit();
mFragment = generateFragment();
}

private BraintreeFragment generateFragment() {
Expand Down

0 comments on commit fb85062

Please sign in to comment.