Skip to content

Commit a35150a

Browse files
Merge pull request #668 from BranchMetrics/RELEASE/3_0_4
Release version 3.0.4
2 parents c2cf679 + 54638b4 commit a35150a

File tree

12 files changed

+153
-102
lines changed

12 files changed

+153
-102
lines changed

Branch-SDK-TestBed/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
android:versionName="1.0" >
66

77
<uses-sdk
8-
android:minSdkVersion="14"
9-
android:targetSdkVersion="20" />
8+
android:minSdkVersion="16"
9+
android:targetSdkVersion="28" />
1010

1111
<uses-permission android:name="android.permission.INTERNET" />
1212

Branch-SDK-TestBed/src/io/branch/branchandroiddemo/test/BUOTestRoutines.java renamed to Branch-SDK-TestBed/androidTest/io/branch/branchandroiddemo/BUOTestRoutines.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.branch.branchandroiddemo.test;
1+
package io.branch.branchandroiddemo;
22

33
import android.content.Context;
44
import android.os.Parcel;

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

Lines changed: 86 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
package io.branch.branchandroiddemo.test;
1+
package io.branch.branchandroiddemo;
22

3-
import android.test.InstrumentationTestCase;
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
46

57
import org.json.JSONException;
68
import org.json.JSONObject;
9+
import org.junit.After;
10+
import org.junit.Assert;
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
714

8-
import java.io.IOException;
915
import java.util.concurrent.CountDownLatch;
1016
import java.util.concurrent.TimeUnit;
1117

@@ -17,117 +23,136 @@
1723
import io.branch.referral.BranchShortLinkBuilder;
1824
import io.branch.referral.PrefHelper;
1925

20-
public class BranchSDKTests extends InstrumentationTestCase {
26+
@RunWith(AndroidJUnit4.class)
27+
public class BranchSDKTests {
2128

29+
private Context mContext;
2230
private Branch branch;
2331
private PrefHelper prefHelper;
24-
private static String urlFB;
25-
private static String referralCode;
26-
private static int referralCodeAmount;
27-
private static int referralCodeCalculationType;
28-
private static int referralCodeLocation;
2932

30-
public void setUp() throws Exception {
31-
super.setUp();
32-
33-
branch = Branch.getInstance(getInstrumentation().getContext());
34-
prefHelper = PrefHelper.getInstance(getInstrumentation().getContext());
33+
@Before
34+
public void setUp() {
35+
mContext = InstrumentationRegistry.getTargetContext();
36+
branch = Branch.getInstance(mContext);
37+
prefHelper = PrefHelper.getInstance(mContext);
3538
}
3639

37-
public void tearDown() throws Exception {
40+
@After
41+
public void tearDown() {
3842
branch.resetUserSession();
39-
super.tearDown();
43+
}
44+
45+
private Context getTestContext() {
46+
return mContext;
4047
}
4148

4249
private void initSession() throws InterruptedException {
4350
final CountDownLatch signal = new CountDownLatch(1);
4451
branch.initSession(new BranchReferralInitListener() {
4552
@Override
4653
public void onInitFinished(JSONObject referringParams, BranchError error) {
47-
assertNull(error);
54+
Assert.assertNull(error);
4855
signal.countDown();
4956
}
5057
});
5158
signal.await(1, TimeUnit.SECONDS);
5259
}
5360

54-
public void test00GetShortUrlSyncFailure() {
55-
String url = new BranchShortLinkBuilder(getInstrumentation().getContext()).getShortUrl();
56-
assertNull(url);
57-
}
58-
59-
public void test02GetShortURLAsync() throws InterruptedException, IOException {
60-
initSession();
61-
61+
private String _fburl;
62+
private String getUrlFB() throws InterruptedException {
6263
final CountDownLatch signal = new CountDownLatch(1);
63-
new BranchShortLinkBuilder(getInstrumentation().getContext())
64+
_fburl = null;
65+
66+
new BranchShortLinkBuilder(getTestContext())
6467
.setChannel("facebook")
6568
.generateShortUrl(new BranchLinkCreateListener() {
6669
@Override
6770
public void onLinkCreate(String url, BranchError error) {
68-
assertNull(error);
69-
assertNotNull(url);
70-
assertTrue(url.startsWith("https://bnc.lt/l/"));
71-
urlFB = url;
71+
Assert.assertNull(error);
72+
Assert.assertNotNull(url);
73+
Assert.assertTrue(url.startsWith("https://bnc.lt/l/"));
74+
_fburl = url;
7275

7376
signal.countDown();
7477
}
7578
});
76-
signal.await(1, TimeUnit.SECONDS);
79+
signal.await(5, TimeUnit.SECONDS);
80+
return _fburl;
81+
}
82+
83+
@Test
84+
public void test00GetShortUrlSyncFailure() {
85+
String url = new BranchShortLinkBuilder(getTestContext()).getShortUrl();
86+
Assert.assertNull(url);
7787
}
7888

89+
@Test
90+
public void test02GetShortURLAsync() throws InterruptedException {
91+
initSession();
92+
final String urlFB = getUrlFB();
93+
Assert.assertNotNull(urlFB);
94+
}
95+
96+
@Test
7997
public void test04GetShortURLAsync1Cached() throws InterruptedException {
8098
initSession();
99+
final String urlFB = getUrlFB();
81100

82101
final CountDownLatch signal = new CountDownLatch(1);
83-
new BranchShortLinkBuilder(getInstrumentation().getContext())
102+
new BranchShortLinkBuilder(getTestContext())
84103
.setChannel("facebook")
85104
.generateShortUrl(new BranchLinkCreateListener() {
86105
@Override
87106
public void onLinkCreate(String url, BranchError error) {
88-
assertNull(error);
89-
assertNotNull(url);
90-
assertSame(url, urlFB);
107+
Assert.assertNull(error);
108+
Assert.assertNotNull(url);
109+
Assert.assertSame(url, urlFB);
91110

92111
signal.countDown();
93112
}
94113
});
95114
signal.await(1, TimeUnit.SECONDS);
96115
}
97116

117+
@Test
98118
public void test04GetShortURLAsync2Uncached() throws InterruptedException {
99119
initSession();
120+
final String urlFB = getUrlFB();
100121

101122
final CountDownLatch signal = new CountDownLatch(1);
102-
new BranchShortLinkBuilder(getInstrumentation().getContext())
123+
new BranchShortLinkBuilder(getTestContext())
103124
.setChannel("twitter")
104125
.generateShortUrl(new BranchLinkCreateListener() {
105126
@Override
106127
public void onLinkCreate(String url, BranchError error) {
107-
assertNull(error);
108-
assertNotNull(url);
109-
assertSame(url, urlFB);
128+
Assert.assertNull(error);
129+
Assert.assertNotNull(url);
130+
Assert.assertSame(url, urlFB);
110131

111132
signal.countDown();
112133
}
113134
});
114135
signal.await(1, TimeUnit.SECONDS);
115136
}
116137

138+
@Test
117139
public void test04GetShortURLSync() throws InterruptedException {
118140
initSession();
119-
String url = new BranchShortLinkBuilder(getInstrumentation().getContext())
141+
final String urlFB = getUrlFB();
142+
143+
String url = new BranchShortLinkBuilder(getTestContext())
120144
.setChannel("facebook")
121145
.getShortUrl();
122146

123-
assertSame(url, urlFB);
147+
Assert.assertSame(url, urlFB);
124148

125-
url = new BranchShortLinkBuilder(getInstrumentation().getContext())
149+
url = new BranchShortLinkBuilder(getTestContext())
126150
.setChannel("linkedin")
127151
.getShortUrl();
128-
assertFalse(url.equals(urlFB));
152+
Assert.assertNotEquals(url, urlFB);
129153
}
130154

155+
@Test
131156
public void test01SetIdentity() throws InterruptedException {
132157
initSession();
133158

@@ -136,14 +161,14 @@ public void test01SetIdentity() throws InterruptedException {
136161
branch.setIdentity("test_user_1", new BranchReferralInitListener() {
137162
@Override
138163
public void onInitFinished(JSONObject referringParams, BranchError error) {
139-
assertNull(error);
140-
assertNotNull(referringParams);
141-
assertTrue(prefHelper.getIdentityID().equals("85338557421453831"));
164+
Assert.assertNull(error);
165+
Assert.assertNotNull(referringParams);
166+
Assert.assertEquals(prefHelper.getIdentityID(), "85338557421453831");
142167

143168
JSONObject installParams = branch.getFirstReferringParams();
144169
try {
145-
assertTrue(installParams.getString("name").equals("test name"));
146-
assertTrue(installParams.getString("message").equals("hello there with short url"));
170+
Assert.assertEquals(installParams.getString("name"), "test name");
171+
Assert.assertEquals(installParams.getString("message"), "hello there with short url");
147172
} catch (JSONException ignore) {
148173
}
149174

@@ -153,6 +178,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
153178
signal.await(1, TimeUnit.SECONDS);
154179
}
155180

181+
@Test
156182
public void test03GetRewardsChanged() throws InterruptedException {
157183
initSession();
158184

@@ -162,15 +188,16 @@ public void test03GetRewardsChanged() throws InterruptedException {
162188
branch.loadRewards(new BranchReferralStateChangedListener() {
163189
@Override
164190
public void onStateChanged(boolean changed, BranchError error) {
165-
assertNull(error);
166-
assertTrue(changed);
191+
Assert.assertNull(error);
192+
Assert.assertTrue(changed);
167193

168194
signal.countDown();
169195
}
170196
});
171197
signal.await(1, TimeUnit.SECONDS);
172198
}
173199

200+
@Test
174201
public void testGetRewardsUnchanged() throws InterruptedException {
175202
initSession();
176203

@@ -180,29 +207,30 @@ public void testGetRewardsUnchanged() throws InterruptedException {
180207
branch.loadRewards(new BranchReferralStateChangedListener() {
181208
@Override
182209
public void onStateChanged(boolean changed, BranchError error) {
183-
assertNull(error);
184-
assertFalse(changed);
210+
Assert.assertNull(error);
211+
Assert.assertFalse(changed);
185212

186213
signal.countDown();
187214
}
188215
});
189216
signal.await(1, TimeUnit.SECONDS);
190217
}
191218

219+
@Test
192220
public void testZLoad() throws InterruptedException {
193221
initSession();
194222

195223
final CountDownLatch signalFinal = new CountDownLatch(1);
196224
final CountDownLatch signal = new CountDownLatch(1);
197225
for (int i = 0; i < 100; i++) {
198226
final int idx = i;
199-
new BranchShortLinkBuilder(getInstrumentation().getContext())
227+
new BranchShortLinkBuilder(getTestContext())
200228
.setChannel(i + "")
201229
.generateShortUrl(new BranchLinkCreateListener() {
202230
@Override
203231
public void onLinkCreate(String url, BranchError error) {
204-
assertNull(error);
205-
assertNotNull(url);
232+
Assert.assertNull(error);
233+
Assert.assertNotNull(url);
206234
if (idx == 99) {
207235
signal.countDown();
208236
}
@@ -212,13 +240,13 @@ public void onLinkCreate(String url, BranchError error) {
212240
}
213241
signal.await(10, TimeUnit.SECONDS);
214242

215-
new BranchShortLinkBuilder(getInstrumentation().getContext())
243+
new BranchShortLinkBuilder(getTestContext())
216244
.setFeature("loadTest")
217245
.generateShortUrl(new BranchLinkCreateListener() {
218246
@Override
219247
public void onLinkCreate(String url, BranchError error) {
220-
assertNull(error);
221-
assertNotNull(url);
248+
Assert.assertNull(error);
249+
Assert.assertNotNull(url);
222250
signalFinal.countDown();
223251
}
224252
});

Branch-SDK-TestBed/src/io/branch/branchandroiddemo/test/TrackingControlTestRoutines.java renamed to Branch-SDK-TestBed/androidTest/io/branch/branchandroiddemo/TrackingControlTestRoutines.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.branch.branchandroiddemo.test;
1+
package io.branch.branchandroiddemo;
22

33
import android.content.Context;
44
import android.text.TextUtils;

Branch-SDK-TestBed/build.gradle

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ apply plugin: 'com.android.application'
22

33
dependencies {
44
implementation project(':Branch-SDK')
5-
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.+'
6-
implementation ('com.google.android.gms:play-services-ads:10.0.1')
5+
implementation ('com.google.android.gms:play-services-ads:16.0.0')
76

87
/* Add chrome custom tabs for guaranteed matching */
98
implementation ('com.android.support:customtabs:23.3.0') {
109
exclude module: 'support-v4'
1110
}
11+
12+
testImplementation 'junit:junit:4.12'
13+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
14+
androidTestImplementation 'com.android.support.test:rules:1.0.2'
15+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
1216
}
1317

1418
android {
15-
compileSdkVersion 23
19+
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
1620
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
1721

1822
defaultConfig {
1923
applicationId "io.branch.branchandroiddemo"
20-
minSdkVersion 16
24+
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_MINIMUM)
2125
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
2226
versionName project.VERSION_NAME
2327
versionCode Integer.parseInt(project.VERSION_CODE)
28+
29+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2430
}
2531

2632
signingConfigs { release }
@@ -40,10 +46,11 @@ android {
4046
renderscript.srcDirs = ['src']
4147
res.srcDirs = ['res']
4248
assets.srcDirs = ['assets']
43-
}
4449

45-
// Move the tests to tests/java, tests/res, etc...
46-
androidTest.setRoot('tests')
50+
androidTest {
51+
java.srcDirs = ['androidTest']
52+
}
53+
}
4754

4855
// Move the build types to build-types/<type>
4956
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...

Branch-SDK-TestBed/src/io/branch/branchandroiddemo/MainActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.util.Date;
1919

20-
import io.branch.branchandroiddemo.test.BUOTestRoutines;
2120
import io.branch.indexing.BranchUniversalObject;
2221
import io.branch.referral.Branch;
2322
import io.branch.referral.Branch.BranchReferralInitListener;

Branch-SDK/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
package="io.branch.referral"
44
android:versionCode="1"
55
android:versionName="1.0" >
6-
<uses-sdk
7-
android:minSdkVersion="8"
8-
android:targetSdkVersion="20" />
96
</manifest>

0 commit comments

Comments
 (0)