Skip to content

Commit 5eb49ae

Browse files
Merge pull request #781 from BranchMetrics/Staging
Release 4.2.1
2 parents d033c3b + a3a7f74 commit 5eb49ae

File tree

20 files changed

+1324
-1134
lines changed

20 files changed

+1324
-1134
lines changed

Branch-SDK-TestBed/src/androidTest/java/io/branch/branchandroiddemo/BranchSDKTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import io.branch.referral.BranchError;
2323
import io.branch.referral.BranchShortLinkBuilder;
2424
import io.branch.referral.PrefHelper;
25+
import io.branch.referral.ServerRequestGetCPID;
26+
import io.branch.referral.util.BranchCPID;
2527

2628
@RunWith(AndroidJUnit4.class)
2729
public class BranchSDKTests {
@@ -30,6 +32,25 @@ public class BranchSDKTests {
3032
private Branch branch;
3133
private PrefHelper prefHelper;
3234

35+
CountDownLatch lock = new CountDownLatch(1);
36+
37+
@Test
38+
public void testGetCPID() throws Throwable {
39+
branch.initSession();
40+
branch.getCrossPlatformIds(new ServerRequestGetCPID.BranchCrossPlatformIdListener() {
41+
@Override public void onDataFetched(BranchCPID cpidResponse, BranchError error) {
42+
if (error == null) {
43+
Assert.assertNotNull(cpidResponse);
44+
} else {
45+
Assert.fail("getCrossPlatformIds returned error, " + error.getMessage());
46+
}
47+
lock.countDown();
48+
}
49+
});
50+
51+
Assert.assertTrue(lock.await(5000, TimeUnit.MILLISECONDS));
52+
}
53+
3354
@Before
3455
public void setUp() {
3556
mContext = InstrumentationRegistry.getContext();

Branch-SDK-TestBed/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,4 @@
9191
<!--</receiver>-->
9292

9393
</application>
94-
95-
<instrumentation
96-
android:name="android.test.InstrumentationTestRunner"
97-
android:targetPackage="io.branch.branchandroiddemo" />
9894
</manifest>

Branch-SDK/src/androidTest/java/io/branch/referral/BranchCPIDTest.java

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4;
44
import io.branch.referral.Defines.RequestPath;
5-
import io.branch.referral.util.BranchCrossPlatformId;
6-
import io.branch.referral.util.BranchLastAttributedTouchData;
5+
6+
import org.json.JSONObject;
77
import org.junit.Assert;
88
import org.junit.Test;
99
import org.junit.runner.RunWith;
@@ -17,9 +17,7 @@ public class BranchCPIDTest extends BranchEventTest {
1717

1818
@Test
1919
public void testGetCPID() throws Throwable{
20-
Branch branch = Branch.getInstance(getTestContext());
21-
22-
new BranchCrossPlatformId(null, getTestContext());
20+
Branch.getInstance(getTestContext()).getCrossPlatformIds(null);
2321

2422
ServerRequestQueue queue = ServerRequestQueue.getInstance(getTestContext());
2523
Assert.assertEquals(1, queue.getSize());
@@ -31,9 +29,7 @@ public void testGetCPID() throws Throwable{
3129

3230
@Test
3331
public void testGetLATD() throws Throwable{
34-
Branch branch = Branch.getInstance(getTestContext());
35-
36-
new BranchLastAttributedTouchData(null, getTestContext());
32+
Branch.getInstance(getTestContext()).getLastAttributedTouchData(null);
3733

3834
ServerRequestQueue queue = ServerRequestQueue.getInstance(getTestContext());
3935
Assert.assertEquals(1, queue.getSize());
@@ -43,4 +39,50 @@ public void testGetLATD() throws Throwable{
4339
Assert.assertEquals(cpidRequest.getRequestPath(), RequestPath.GetLATD.getPath());
4440
}
4541

42+
@Test
43+
public void testGetLATDAttributionWindowDefault() throws Throwable {
44+
Branch branch = Branch.getInstance(getTestContext());
45+
PrefHelper prefHelper = PrefHelper.getInstance(getTestContext());
46+
47+
// Defaults to ServerRequestGetLATD.defaultAttributionWindow
48+
int defValue = prefHelper.getLATDAttributionWindow();
49+
Assert.assertEquals(ServerRequestGetLATD.defaultAttributionWindow, defValue);
50+
51+
// After request with custom attribution window, still defaults to ServerRequestGetLATD.defaultAttributionWindow
52+
branch.getLastAttributedTouchData(null, 80);
53+
int prefValueA = prefHelper.getLATDAttributionWindow();
54+
Assert.assertEquals(ServerRequestGetLATD.defaultAttributionWindow, prefValueA);
55+
}
56+
57+
@Test
58+
public void testGetLATDAttributionWindowSetting() throws Throwable {
59+
//setup
60+
Branch branch = Branch.getInstance(getTestContext());
61+
PrefHelper prefHelper = PrefHelper.getInstance(getTestContext());
62+
63+
// Defaults to ServerRequestGetLATD.defaultAttributionWindow
64+
int defValue = prefHelper.getLATDAttributionWindow();
65+
Assert.assertEquals(ServerRequestGetLATD.defaultAttributionWindow, defValue);
66+
67+
// Setting new attribution window to 10
68+
prefHelper.setLATDAttributionWindow(10);
69+
int newValue = prefHelper.getLATDAttributionWindow();
70+
Assert.assertEquals(10, newValue);
71+
72+
// make request, get its post body, check that the attribution window equals 10
73+
branch.getLastAttributedTouchData(null);
74+
ServerRequestQueue queue = ServerRequestQueue.getInstance(getTestContext());
75+
Assert.assertEquals(1, queue.getSize());
76+
77+
ServerRequest latdRequest = queue.peekAt(0);
78+
Assert.assertTrue(latdRequest instanceof ServerRequestGetLATD);
79+
80+
JSONObject postBody = latdRequest.getPost();
81+
Assert.assertNotNull(postBody);
82+
JSONObject userData = postBody.optJSONObject(Defines.Jsonkey.UserData.getKey());
83+
Assert.assertNotNull(userData);
84+
85+
int atrWind = userData.optInt(Defines.Jsonkey.LATDAttributionWindow.getKey());
86+
Assert.assertEquals(10, atrWind);
87+
}
4688
}

Branch-SDK/src/androidTest/java/io/branch/referral/BranchTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5-
import androidx.test.InstrumentationRegistry;
5+
6+
import androidx.test.core.app.ApplicationProvider;
67
import androidx.test.ext.junit.runners.AndroidJUnit4;
78

89
import org.junit.Assert;
@@ -22,7 +23,7 @@ public class BranchTest {
2223

2324
@Before
2425
public void setUp() {
25-
mContext = InstrumentationRegistry.getContext();
26+
mContext = ApplicationProvider.getApplicationContext();
2627
}
2728

2829
@After

Branch-SDK/src/main/java/io/branch/indexing/BranchUniversalObject.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import io.branch.referral.Branch;
2121
import io.branch.referral.BranchError;
22+
import io.branch.referral.BranchShareSheetBuilder;
2223
import io.branch.referral.BranchShortLinkBuilder;
2324
import io.branch.referral.BranchUtil;
2425
import io.branch.referral.Defines;
@@ -650,7 +651,7 @@ public void showShareSheet(@NonNull Activity activity, @NonNull LinkProperties l
650651
PrefHelper.Debug("Sharing error. Branch instance is not created yet. Make sure you have initialised Branch.");
651652
}
652653
} else {
653-
Branch.ShareLinkBuilder shareLinkBuilder = new Branch.ShareLinkBuilder(activity, getLinkBuilder(activity, linkProperties));
654+
BranchShareSheetBuilder shareLinkBuilder = new BranchShareSheetBuilder(activity, getLinkBuilder(activity, linkProperties));
654655
shareLinkBuilder.setCallback(new LinkShareListenerWrapper(callback, shareLinkBuilder, linkProperties))
655656
.setChannelProperties(channelProperties)
656657
.setSubject(style.getMessageTitle())
@@ -943,12 +944,12 @@ private BranchUniversalObject(Parcel in) {
943944
*/
944945
private class LinkShareListenerWrapper implements Branch.BranchLinkShareListener {
945946
private final Branch.BranchLinkShareListener originalCallback_;
946-
private final Branch.ShareLinkBuilder shareLinkBuilder_;
947+
private final BranchShareSheetBuilder shareSheetBuilder_;
947948
private final LinkProperties linkProperties_;
948949

949-
LinkShareListenerWrapper(Branch.BranchLinkShareListener originalCallback, Branch.ShareLinkBuilder shareLinkBuilder, LinkProperties linkProperties) {
950+
LinkShareListenerWrapper(Branch.BranchLinkShareListener originalCallback, BranchShareSheetBuilder shareLinkBuilder, LinkProperties linkProperties) {
950951
originalCallback_ = originalCallback;
951-
shareLinkBuilder_ = shareLinkBuilder;
952+
shareSheetBuilder_ = shareLinkBuilder;
952953
linkProperties_ = linkProperties;
953954
}
954955

@@ -988,7 +989,7 @@ public void onChannelSelected(String channelName) {
988989
}
989990
if (originalCallback_ instanceof Branch.ExtendedBranchLinkShareListener) {
990991
if (((Branch.ExtendedBranchLinkShareListener) originalCallback_).onChannelSelected(channelName, BranchUniversalObject.this, linkProperties_)) {
991-
shareLinkBuilder_.setShortLinkBuilderInternal(getLinkBuilder(shareLinkBuilder_.getShortLinkBuilder(), linkProperties_));
992+
shareSheetBuilder_.setShortLinkBuilderInternal(getLinkBuilder(shareSheetBuilder_.getShortLinkBuilder(), linkProperties_));
992993
}
993994
}
994995
}

0 commit comments

Comments
 (0)