Skip to content

Commit 6425bbd

Browse files
authored
fix: upgrade android tools and libraries (#437)
- Upgrade android tools and libraries (gradle 7.5, AGP 7.2, kotlin 1.7, powermock 2.0.9) - Clean up old tests
1 parent 9faa8ba commit 6425bbd

File tree

18 files changed

+86
-126
lines changed

18 files changed

+86
-126
lines changed

android-sdk/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ android {
2525
defaultConfig {
2626
minSdkVersion min_sdk_version
2727
targetSdkVersion target_sdk_version
28-
versionCode 1
29-
versionName version_name
28+
multiDexEnabled true
3029
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3130
buildConfigField "String", "CLIENT_VERSION", "\"$version_name\""
3231

@@ -69,7 +68,8 @@ dependencies {
6968

7069
testImplementation "junit:junit:$junit_ver"
7170
testImplementation "org.mockito:mockito-core:$mockito_ver"
72-
testImplementation "org.powermock:powermock-mockito-release-full:$powermock_ver"
71+
testImplementation "org.powermock:powermock-module-junit4:$powermock_ver"
72+
testImplementation "org.powermock:powermock-api-mockito2:$powermock_ver"
7373
testImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
7474

7575
androidTestImplementation "androidx.work:work-testing:$work_runtime"

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class OptimizelyManager {
8585

8686
@Nullable private OptimizelyStartListener optimizelyStartListener;
8787

88-
@NonNull private final List<OptimizelyDecideOption> defaultDecideOptions;
88+
@Nullable private final List<OptimizelyDecideOption> defaultDecideOptions;
8989
private String sdkVersion = null;
9090

9191
OptimizelyManager(@Nullable String projectId,
@@ -100,7 +100,7 @@ public class OptimizelyManager {
100100
@Nullable EventProcessor eventProcessor,
101101
@NonNull UserProfileService userProfileService,
102102
@NonNull NotificationCenter notificationCenter,
103-
@NonNull List<OptimizelyDecideOption> defaultDecideOptions) {
103+
@Nullable List<OptimizelyDecideOption> defaultDecideOptions) {
104104

105105
if (projectId == null && sdkKey == null) {
106106
logger.error("projectId and sdkKey are both null!");

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public class OptimizelyManagerBuilderTest {
6868
@Before
6969
public void setup() throws Exception {
7070
mockContext = mock(Context.class);
71-
when(mockContext.getApplicationContext()).thenReturn(mockContext);
7271
mockDatafileHandler = mock(DefaultDatafileHandler.class);
7372
}
7473

@@ -133,7 +132,6 @@ public void testBuildWithDatafileHandler() {
133132
@Test
134133
public void testBuildWithUserProfileService() {
135134
Context appContext = mock(Context.class);
136-
when(appContext.getApplicationContext()).thenReturn(appContext);
137135
DefaultUserProfileService ups = mock(DefaultUserProfileService.class);
138136
OptimizelyManager manager = OptimizelyManager.builder()
139137
.withSDKKey(testSdkKey)

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerIntervalTest.java

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@
1616

1717
package com.optimizely.ab.android.sdk;
1818

19+
import static org.mockito.Matchers.any;
20+
import static org.mockito.Matchers.anyInt;
21+
import static org.mockito.Matchers.anyList;
22+
import static org.mockito.Matchers.anyLong;
23+
import static org.mockito.Matchers.anyString;
24+
import static org.mockito.Matchers.eq;
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.verify;
27+
import static org.mockito.Mockito.when;
28+
import static org.powermock.api.mockito.PowerMockito.mockStatic;
29+
import static org.powermock.api.mockito.PowerMockito.verifyNew;
30+
import static org.powermock.api.mockito.PowerMockito.whenNew;
31+
1932
import android.content.Context;
2033

2134
import com.optimizely.ab.android.datafile_handler.DatafileHandler;
2235
import com.optimizely.ab.android.event_handler.DefaultEventHandler;
2336
import com.optimizely.ab.android.shared.DatafileConfig;
24-
import com.optimizely.ab.android.user_profile.DefaultUserProfileService;
2537
import com.optimizely.ab.bucketing.UserProfileService;
2638
import com.optimizely.ab.error.ErrorHandler;
2739
import com.optimizely.ab.event.BatchEventProcessor;
@@ -32,36 +44,17 @@
3244
import org.junit.Before;
3345
import org.junit.Test;
3446
import org.junit.runner.RunWith;
35-
import org.mockito.runners.MockitoJUnitRunner;
36-
import org.powermock.api.mockito.PowerMockito;
47+
import org.powermock.core.PowerMockUtils;
3748
import org.powermock.core.classloader.annotations.PowerMockIgnore;
3849
import org.powermock.core.classloader.annotations.PrepareForTest;
3950
import org.powermock.modules.junit4.PowerMockRunner;
51+
4052
import org.slf4j.Logger;
4153

42-
import java.util.List;
4354
import java.util.concurrent.BlockingQueue;
4455
import java.util.concurrent.ExecutorService;
4556
import java.util.concurrent.TimeUnit;
4657

47-
import static junit.framework.Assert.assertEquals;
48-
import static junit.framework.Assert.assertFalse;
49-
import static org.mockito.Matchers.any;
50-
import static org.mockito.Matchers.anyBoolean;
51-
import static org.mockito.Matchers.anyList;
52-
import static org.mockito.Matchers.anyLong;
53-
import static org.mockito.Matchers.anyInt;
54-
import static org.mockito.Matchers.anyObject;
55-
import static org.mockito.Matchers.anyString;
56-
import static org.mockito.Matchers.eq;
57-
import static org.mockito.Mockito.mock;
58-
import static org.mockito.Mockito.never;
59-
import static org.mockito.Mockito.verify;
60-
import static org.mockito.Mockito.when;
61-
import static org.powermock.api.mockito.PowerMockito.mockStatic;
62-
import static org.powermock.api.mockito.PowerMockito.verifyNew;
63-
import static org.powermock.api.mockito.PowerMockito.whenNew;
64-
6558

6659
@RunWith(PowerMockRunner.class)
6760
@PowerMockIgnore("jdk.internal.reflect.*")
@@ -75,7 +68,6 @@ public class OptimizelyManagerIntervalTest {
7568
@Before
7669
public void setup() throws Exception {
7770
mockContext = mock(Context.class);
78-
when(mockContext.getApplicationContext()).thenReturn(mockContext);
7971

8072
whenNew(OptimizelyManager.class).withAnyArguments().thenReturn(mock(OptimizelyManager.class));
8173
whenNew(BatchEventProcessor.class).withAnyArguments().thenReturn(mock(BatchEventProcessor.class));
@@ -95,19 +87,20 @@ public void testBuildWithDatafileDownloadInterval() throws Exception {
9587
.withDatafileDownloadInterval(goodNumber, TimeUnit.MINUTES)
9688
.build(mockContext);
9789

98-
verifyNew(OptimizelyManager.class).withArguments(anyString(),
90+
verifyNew(OptimizelyManager.class).withArguments(
9991
anyString(),
92+
any(), // nullable (String)
10093
any(DatafileConfig.class),
10194
any(Logger.class),
10295
eq(goodNumber * 60L), // seconds
10396
any(DatafileHandler.class),
104-
any(ErrorHandler.class),
97+
any(), // nullable (ErrorHandler)
10598
anyLong(),
10699
any(EventHandler.class),
107100
any(EventProcessor.class),
108101
any(UserProfileService.class),
109102
any(NotificationCenter.class),
110-
anyList());
103+
any()); // nullable (DefaultDecideOptions)
111104
}
112105

113106
@Test
@@ -118,19 +111,20 @@ public void testBuildWithDatafileDownloadIntervalDeprecated() throws Exception {
118111
.withDatafileDownloadInterval(goodNumber) // deprecated
119112
.build(mockContext);
120113

121-
verifyNew(OptimizelyManager.class).withArguments(anyString(),
114+
verifyNew(OptimizelyManager.class).withArguments(
122115
anyString(),
116+
any(), // nullable (String)
123117
any(DatafileConfig.class),
124118
any(Logger.class),
125-
eq(goodNumber), // seconds
119+
eq(goodNumber), // seconds
126120
any(DatafileHandler.class),
127-
any(ErrorHandler.class),
121+
any(), // nullable (ErrorHandler)
128122
anyLong(),
129123
any(EventHandler.class),
130124
any(EventProcessor.class),
131125
any(UserProfileService.class),
132126
any(NotificationCenter.class),
133-
anyList());
127+
any()); // nullable (DefaultDecideOptions)
134128
}
135129

136130
@Test
@@ -141,30 +135,32 @@ public void testBuildWithEventDispatchInterval() throws Exception {
141135
.withEventDispatchInterval(goodNumber, TimeUnit.SECONDS)
142136
.build(mockContext);
143137

144-
verifyNew(BatchEventProcessor.class).withArguments(any(BlockingQueue.class),
138+
verifyNew(BatchEventProcessor.class).withArguments(
139+
any(BlockingQueue.class),
145140
any(EventHandler.class),
146141
anyInt(),
147142
eq(goodNumber * 1000L), // milliseconds
148143
anyLong(),
149144
any(ExecutorService.class),
150145
any(NotificationCenter.class),
151-
any(Object.class));
146+
any()); // PowerMock bug? requires an extra null at the end
152147

153148
verify(mockEventHandler).setDispatchInterval(-1L); // default
154149

155-
verifyNew(OptimizelyManager.class).withArguments(anyString(),
150+
verifyNew(OptimizelyManager.class).withArguments(
156151
anyString(),
152+
any(), // nullable (String)
157153
any(DatafileConfig.class),
158154
any(Logger.class),
159155
anyLong(),
160156
any(DatafileHandler.class),
161-
any(ErrorHandler.class),
157+
any(), // nullable (ErrorHandler)
162158
eq(-1L), // default
163159
any(EventHandler.class),
164160
any(EventProcessor.class),
165161
any(UserProfileService.class),
166162
any(NotificationCenter.class),
167-
anyList());
163+
any()); // nullable (DefaultDecideOptions)
168164
}
169165

170166
@Test
@@ -178,30 +174,32 @@ public void testBuildWithEventDispatchRetryInterval() throws Exception {
178174
.withEventDispatchRetryInterval(goodNumber, timeUnit)
179175
.build(mockContext);
180176

181-
verifyNew(BatchEventProcessor.class).withArguments(any(BlockingQueue.class),
177+
verifyNew(BatchEventProcessor.class).withArguments(
178+
any(BlockingQueue.class),
182179
any(EventHandler.class),
183180
anyInt(),
184181
eq(defaultEventFlushInterval * 1000L), // milliseconds
185182
anyLong(),
186183
any(ExecutorService.class),
187184
any(NotificationCenter.class),
188-
any(Object.class));
185+
any()); // PowerMock bug? requires an extra null at the end
189186

190187
verify(mockEventHandler).setDispatchInterval(timeUnit.toMillis(goodNumber)); // milli-seconds
191188

192-
verifyNew(OptimizelyManager.class).withArguments(anyString(),
189+
verifyNew(OptimizelyManager.class).withArguments(
193190
anyString(),
191+
any(), // nullable (String)
194192
any(DatafileConfig.class),
195193
any(Logger.class),
196194
anyLong(),
197195
any(DatafileHandler.class),
198-
any(ErrorHandler.class),
196+
any(), // nullable (ErrorHandler)
199197
eq(goodNumber * 1000L * 60L), // milliseconds
200198
any(EventHandler.class),
201199
any(EventProcessor.class),
202200
any(UserProfileService.class),
203201
any(NotificationCenter.class),
204-
anyList());
202+
any()); // nullable (DefaultDecideOptions)
205203
}
206204

207205
@Test
@@ -219,23 +217,24 @@ public void testBuildWithEventDispatchIntervalDeprecated() throws Exception {
219217
anyLong(),
220218
any(ExecutorService.class),
221219
any(NotificationCenter.class),
222-
any(Object.class));
220+
any()); // PowerMock bug? requires an extra null at the end
223221

224222
verify(mockEventHandler).setDispatchInterval(-1L); // deprecated api not change default retryInterval
225223

226-
verifyNew(OptimizelyManager.class).withArguments(anyString(),
224+
verifyNew(OptimizelyManager.class).withArguments(
227225
anyString(),
226+
any(), // nullable (String)
228227
any(DatafileConfig.class),
229228
any(Logger.class),
230229
anyLong(),
231230
any(DatafileHandler.class),
232-
any(ErrorHandler.class),
231+
any(), // nullable (ErrorHandler)
233232
eq(-1L), // deprecated api not change default retryInterval
234233
any(EventHandler.class),
235234
any(EventProcessor.class),
236235
any(UserProfileService.class),
237236
any(NotificationCenter.class),
238-
anyList());
237+
any()); // nullable (DefaultDecideOptions)
239238
}
240239

241240
}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1818

1919
buildscript {
20-
ext.kotlin_version = '1.4.0'
20+
ext.kotlin_version = '1.7.0'
2121

2222
ext.version_name = System.getenv('TRAVIS_TAG')
2323
if (version_name == null || version_name.isEmpty()) {
@@ -30,7 +30,7 @@ buildscript {
3030
google()
3131
}
3232
dependencies {
33-
classpath 'com.android.tools.build:gradle:4.1.2'
33+
classpath 'com.android.tools.build:gradle:7.2.1'
3434
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
3535

3636
// NOTE: Do not place your application dependencies here; they belong
@@ -67,7 +67,7 @@ ext {
6767
annotations_ver = "1.2.0"
6868
junit_ver = "4.12"
6969
mockito_ver = "1.10.19"
70-
powermock_ver = "1.6.4"
70+
powermock_ver = "2.0.9"
7171
support_test_runner_ver = "0.5"
7272
dexmaker_ver = "1.4"
7373
gson_ver = "2.8.9"

datafile-handler/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ android {
2525
defaultConfig {
2626
minSdkVersion min_sdk_version
2727
targetSdkVersion target_sdk_version
28-
versionCode 1
29-
versionName version_name
28+
multiDexEnabled true
3029
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3130
}
3231
testOptions {

event-handler/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ android {
2525
defaultConfig {
2626
minSdkVersion min_sdk_version
2727
targetSdkVersion target_sdk_version
28-
versionCode 1
29-
versionName "1.0"
28+
multiDexEnabled true
3029
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3130
}
3231
testOptions {
@@ -58,7 +57,8 @@ dependencies {
5857

5958
testImplementation "junit:junit:$junit_ver"
6059
testImplementation "org.mockito:mockito-core:$mockito_ver"
61-
testImplementation "org.powermock:powermock-mockito-release-full:$powermock_ver"
60+
testImplementation "org.powermock:powermock-module-junit4:$powermock_ver"
61+
testImplementation "org.powermock:powermock-api-mockito2:$powermock_ver"
6262
testImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
6363

6464
androidTestImplementation "androidx.work:work-testing:$work_runtime"

event-handler/src/androidTest/java/com/optimizely/ab/android/event_handler/EventDAOTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class EventDAOTest {
5353
public void setupEventDAO() {
5454
logger = mock(Logger.class);
5555
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
56+
context.deleteDatabase(String.format(EventSQLiteOpenHelper.DB_NAME , "1"));
5657
eventDAO = EventDAO.getInstance(context, "1", logger);
5758
}
5859

event-handler/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
<uses-permission android:name="android.permission.INTERNET"/>
2424

2525
<application>
26-
<!--
27-
Add these lines to your manifest if you want the services to schedule themselves again after a boot
28-
or package replace.
29-
-->
3026
<receiver
3127
android:name=".EventRescheduler"
3228
android:enabled="true"

event-handler/src/test/java/com/optimizely/ab/android/event_handler/EventClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.runner.RunWith;
2424
import org.mockito.ArgumentCaptor;
2525
import org.mockito.Mock;
26+
import org.mockito.exceptions.base.MockitoException;
2627
import org.mockito.runners.MockitoJUnitRunner;
2728
import org.slf4j.Logger;
2829

@@ -107,7 +108,6 @@ public void sendEvents300() throws IOException {
107108
when(client.openConnection(event.getURL())).thenReturn(urlConnection);
108109
when(urlConnection.getResponseCode()).thenReturn(300);
109110
InputStream inputStream = mock(InputStream.class);
110-
when(urlConnection.getInputStream()).thenReturn(inputStream);
111111

112112
eventClient.sendEvent(event);
113113
ArgumentCaptor<Client.Request> captor1 = ArgumentCaptor.forClass(Client.Request.class);
@@ -146,7 +146,7 @@ public void sendEventsIoExceptionGetInputStream() throws IOException {
146146
@SuppressWarnings("unchecked")
147147
@Test()
148148
public void sendEventsIoExceptionOpenConnection() throws IOException {
149-
when(client.openConnection(event.getURL())).thenThrow(IOException.class);
149+
when(client.openConnection(event.getURL())).thenThrow(MockitoException.class);
150150

151151
eventClient.sendEvent(event);
152152
ArgumentCaptor<Client.Request> captor1 = ArgumentCaptor.forClass(Client.Request.class);

0 commit comments

Comments
 (0)