|
| 1 | +package com.leanplum.internal; |
| 2 | + |
| 3 | +import android.app.Application; |
| 4 | + |
| 5 | +import com.leanplum.Leanplum; |
| 6 | +import com.leanplum.__setup.LeanplumTestApp; |
| 7 | +import com.leanplum._whitebox.utilities.SynchronousExecutor; |
| 8 | + |
| 9 | +import junit.framework.TestCase; |
| 10 | + |
| 11 | +import org.junit.Before; |
| 12 | +import org.junit.Test; |
| 13 | +import org.junit.runner.RunWith; |
| 14 | +import org.powermock.core.classloader.annotations.PowerMockIgnore; |
| 15 | +import org.robolectric.RobolectricTestRunner; |
| 16 | +import org.robolectric.RuntimeEnvironment; |
| 17 | +import org.robolectric.annotation.Config; |
| 18 | +import org.robolectric.util.ReflectionHelpers; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +@RunWith(RobolectricTestRunner.class) |
| 24 | +@Config( |
| 25 | + sdk = 16, |
| 26 | + application = LeanplumTestApp.class |
| 27 | +) |
| 28 | +@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "org.json.*", "org.powermock.*"}) |
| 29 | +public class RequestOldUtilTest extends TestCase { |
| 30 | + private final String POST = "POST"; |
| 31 | + /** |
| 32 | + * Runs before every test case. |
| 33 | + */ |
| 34 | + @Before |
| 35 | + public void setUp() { |
| 36 | + Application context = RuntimeEnvironment.application; |
| 37 | + assertNotNull(context); |
| 38 | + Leanplum.setApplicationContext(context); |
| 39 | + |
| 40 | + // Mock this so async things run synchronously |
| 41 | + ReflectionHelpers.setStaticField(Util.class, "singleThreadExecutor", new SynchronousExecutor()); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testSetNewBatchUUID() { |
| 46 | + LeanplumEventDataManager.init(Leanplum.getContext()); |
| 47 | + |
| 48 | + RequestOld request1 = new RequestOld(this.POST, Constants.Methods.START, null); |
| 49 | + request1.sendEventually(); |
| 50 | + RequestOld request2 = new RequestOld(this.POST, Constants.Methods.TRACK, null); |
| 51 | + request2.sendEventually(); |
| 52 | + List<Map<String, Object>> unsentRequests1 = request1.getUnsentRequests(1.0); |
| 53 | + String oldUUID1 = (String) unsentRequests1.get(0).get(request1.UUID_KEY); |
| 54 | + |
| 55 | + List<Map<String, Object>> unsentRequests2 = request1.getUnsentRequests(1.0); |
| 56 | + String oldUUID2 = (String) unsentRequests2.get(0).get(request1.UUID_KEY); |
| 57 | + |
| 58 | + List<Map<String, Object>> unsentRequests3 = request1.getUnsentRequests(0.5); |
| 59 | + String newUUID = (String) unsentRequests3.get(0).get(request1.UUID_KEY); |
| 60 | + |
| 61 | + assertTrue(oldUUID1.equals(oldUUID2)); |
| 62 | + assertFalse(oldUUID1.equals(newUUID)); |
| 63 | + } |
| 64 | +} |
0 commit comments