From fb85062f362ccbaaf9c6876d3354d2aca02b4b8c Mon Sep 17 00:00:00 2001
From: lkorth <luke@lukekorth.com>
Date: Tue, 10 Nov 2015 17:47:01 -0500
Subject: [PATCH] Fix AnalyticsManager test pollution

---
 .../api/AnalyticsManagerTest.java                | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/BraintreeApi/src/androidTest/java/com/braintreepayments/api/AnalyticsManagerTest.java b/BraintreeApi/src/androidTest/java/com/braintreepayments/api/AnalyticsManagerTest.java
index 83414c9fe7..e688492468 100644
--- a/BraintreeApi/src/androidTest/java/com/braintreepayments/api/AnalyticsManagerTest.java
+++ b/BraintreeApi/src/androidTest/java/com/braintreepayments/api/AnalyticsManagerTest.java
@@ -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;
@@ -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);
@@ -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);
@@ -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"));
@@ -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() {