Skip to content

Commit 1c64743

Browse files
feature: convert test app to kotlin (#331)
* convert test app to kotlin * working copy * example after event * make sure to add callback * take out that silly test * update for release * fix logging * let job scheduler do throttle of datafile time instead of us * update gradle * upgrading gradle * update more memory for travis * add gradle properties file for travis * fix data loader test
1 parent 083d445 commit 1c64743

36 files changed

+652
-484
lines changed

android-sdk/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -15,6 +15,8 @@
1515
***************************************************************************/
1616

1717
apply plugin: 'com.android.library'
18+
apply plugin: 'kotlin-android'
19+
apply plugin: 'kotlin-android-extensions'
1820
apply plugin: 'maven'
1921
apply plugin: 'maven-publish'
2022

@@ -86,6 +88,7 @@ dependencies {
8688
androidTestImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
8789
androidTestImplementation "com.google.code.gson:gson:$gson_ver"
8890
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
91+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
8992
}
9093

9194
uploadArchives {
@@ -140,3 +143,4 @@ android.libraryVariants.all { variant ->
140143
}
141144
project.artifacts.add("archives", tasks["${variant.name}SourcesJar"]);
142145
}
146+

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,10 @@ public OptimizelyManager build(Context context) {
888888

889889
if (datafileDownloadInterval > 0) {
890890
// JobScheduler API doesn't allow intervals less than 15 minutes
891-
if (datafileDownloadInterval < 900) {
892-
datafileDownloadInterval = 900;
893-
logger.warn("Minimum datafile polling interval is 15 minutes. Defaulting to 15 minutes.");
894-
}
891+
// if (datafileDownloadInterval < 900) {
892+
// datafileDownloadInterval = 900;
893+
// logger.warn("Minimum datafile polling interval is 15 minutes. Defaulting to 15 minutes.");
894+
// }
895895
}
896896

897897
if (datafileConfig == null) {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public class OptimizelyManagerBuilderTest {
5353
* Verify that building the {@link OptimizelyManager} with a polling interval less than 60
5454
* seconds defaults to 60 seconds.
5555
*/
56-
@Test
57-
public void testBuildWithInvalidPollingInterval() {
58-
Context appContext = mock(Context.class);
59-
when(appContext.getApplicationContext()).thenReturn(appContext);
60-
OptimizelyManager manager = OptimizelyManager.builder("1")
61-
.withDatafileDownloadInterval(5L)
62-
.build(appContext);
63-
64-
assertEquals(900L, manager.getDatafileDownloadInterval().longValue());
65-
}
56+
// @Test
57+
// public void testBuildWithInvalidPollingInterval() {
58+
// Context appContext = mock(Context.class);
59+
// when(appContext.getApplicationContext()).thenReturn(appContext);
60+
// OptimizelyManager manager = OptimizelyManager.builder("1")
61+
// .withDatafileDownloadInterval(5L)
62+
// .build(appContext);
63+
//
64+
// assertEquals(900L, manager.getDatafileDownloadInterval().longValue());
65+
// }
6666

6767
/**
6868
* Verify that building the {@link OptimizelyManager} with a polling interval greater than 60

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,6 @@ public void testBuildWithDatafileDownloadIntervalDeprecated() throws Exception {
117117
any(NotificationCenter.class));
118118
}
119119

120-
@Test
121-
public void testBuildWithInvalidDatafileDownloadInterval() {
122-
Context appContext = mock(Context.class);
123-
Logger logger = mock(Logger.class);
124-
when(appContext.getApplicationContext()).thenReturn(appContext);
125-
126-
long tooSmallNumber = 60;
127-
OptimizelyManager manager = OptimizelyManager.builder("1")
128-
.withLogger(logger)
129-
.withDatafileDownloadInterval(tooSmallNumber, TimeUnit.SECONDS)
130-
.build(appContext);
131-
132-
verify(logger).warn("Minimum datafile polling interval is 15 minutes. Defaulting to 15 minutes.");
133-
}
134-
135-
// EventDispatchInterval
136-
137120
@Test
138121
public void testBuildWithEventDispatchInterval() throws Exception {
139122
whenNew(OptimizelyManager.class).withAnyArguments().thenReturn(mock(OptimizelyManager.class));

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016-2017, Optimizely, Inc. and contributors *
2+
* Copyright 2016-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -17,6 +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.3.72'
2021
def bintray_user = System.getenv('BINTRAY_USER')
2122
def bintray_api_key = System.getenv('BINTRAY_API_KEY')
2223
def version_name = System.getenv('TRAVIS_TAG')
@@ -34,7 +35,8 @@ buildscript {
3435
google()
3536
}
3637
dependencies {
37-
classpath 'com.android.tools.build:gradle:3.4.0'
38+
classpath 'com.android.tools.build:gradle:4.0.0'
39+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
3840

3941
// NOTE: Do not place your application dependencies here; they belong
4042
// in the individual module build.gradle files
@@ -45,6 +47,7 @@ allprojects {
4547
repositories {
4648
jcenter()
4749
google()
50+
mavenCentral()
4851
// Uncomment the next line to use maven locally
4952
//mavenLocal()
5053
}

datafile-handler/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2016-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -15,6 +15,8 @@
1515
***************************************************************************/
1616

1717
apply plugin: 'com.android.library'
18+
apply plugin: 'kotlin-android'
19+
apply plugin: 'kotlin-android-extensions'
1820
apply plugin: 'maven'
1921
apply plugin: 'maven-publish'
2022

@@ -72,6 +74,7 @@ dependencies {
7274
androidTestImplementation "com.crittercism.dexmaker:dexmaker-mockito:$dexmaker_ver"
7375
androidTestImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
7476
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
77+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
7578
}
7679

7780
uploadArchives {
@@ -127,3 +130,4 @@ android.libraryVariants.all { variant ->
127130
project.artifacts.add("archives", tasks["${variant.name}SourcesJar"]);
128131
}
129132

133+

datafile-handler/src/androidTest/java/com/optimizely/ab/android/datafile_handler/DatafileLoaderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,15 @@ public void debugLoggedMultiThreaded() throws IOException {
242242
when(cache.load(datafileCache.getFileName())).thenReturn("{}");
243243
when(cache.save(datafileCache.getFileName(), "{}")).thenReturn(true);
244244

245+
datafileLoader.getDatafile("debugLoggedMultiThreaded", datafileLoadedListener);
246+
245247
Runnable r = () -> datafileLoader.getDatafile("debugLoggedMultiThreaded", datafileLoadedListener);
246248

247249
new Thread(r).start();
248250
new Thread(r).start();
249251
new Thread(r).start();
250252
new Thread(r).start();
251253

252-
datafileLoader.getDatafile("debugLoggedMultiThreaded", datafileLoadedListener);
253-
254254
try {
255255
executor.awaitTermination(5, TimeUnit.SECONDS);
256256
} catch (InterruptedException e) {

event-handler/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
***************************************************************************/
1616

1717
apply plugin: 'com.android.library'
18+
apply plugin: 'kotlin-android'
19+
apply plugin: 'kotlin-android-extensions'
1820
apply plugin: 'maven'
1921
apply plugin: 'maven-publish'
2022

@@ -73,6 +75,7 @@ dependencies {
7375
androidTestImplementation "com.crittercism.dexmaker:dexmaker-mockito:$dexmaker_ver"
7476
androidTestImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
7577
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
78+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
7679
}
7780

7881
uploadArchives {
@@ -128,3 +131,4 @@ android.libraryVariants.all { variant ->
128131
project.artifacts.add("archives", tasks["${variant.name}SourcesJar"]);
129132
}
130133

134+

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1g
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Mon Feb 11 13:52:51 PST 2019
1+
#Tue Jul 07 16:56:21 EDT 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
7+
org.gradle.jvmargs=-Xmx1g

0 commit comments

Comments
 (0)