Skip to content

Commit 7e595ed

Browse files
authored
Release version 1.3.0 (#104)
2 parents 0f998e1 + 796fdfa commit 7e595ed

File tree

7 files changed

+98
-25
lines changed

7 files changed

+98
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ android:
33
components:
44
- tools
55
- platform-tools
6-
- build-tools-24.0.3
6+
- build-tools-25.0.2
77
- android-24
88
- doc-24
99
- extra-android-m2repository

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Optimizely Android X SDK Changelog
2+
### 1.3.0
3+
April 12, 2017
4+
5+
- Add getter for `ProjectConfig`
6+
27
### 1.2.0
38
March 20, 2017
49

android-sdk/src/androidTest/java/com/optimizely/ab/android/sdk/OptimizelyManagerTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.optimizely.ab.android.shared.ServiceScheduler;
2828
import com.optimizely.ab.android.user_profile.AndroidUserProfile;
29+
import com.optimizely.ab.config.parser.ConfigParseException;
2930

3031
import org.junit.Before;
3132
import org.junit.Test;
@@ -98,6 +99,45 @@ public void initialize() {
9899
assertTrue(intent.getComponent().getShortClassName().contains("DataFileService"));
99100
}
100101

102+
@Test
103+
public void initializeWithEmptyDatafile() {
104+
Context context = mock(Context.class);
105+
Context appContext = mock(Context.class);
106+
when(context.getApplicationContext()).thenReturn(appContext);
107+
when(appContext.getPackageName()).thenReturn("com.optly");
108+
109+
String emptyString = "";
110+
111+
optimizelyManager.initialize(context, emptyString);
112+
verify(logger).error(eq("Unable to parse compiled data file"), any(ConfigParseException.class));
113+
}
114+
115+
@Test
116+
public void initializeWithMalformedDatafile() {
117+
Context context = mock(Context.class);
118+
Context appContext = mock(Context.class);
119+
when(context.getApplicationContext()).thenReturn(appContext);
120+
when(appContext.getPackageName()).thenReturn("com.optly");
121+
122+
String emptyString = "malformed data";
123+
124+
optimizelyManager.initialize(context, emptyString);
125+
verify(logger).error(eq("Unable to parse compiled data file"), any(ConfigParseException.class));
126+
}
127+
128+
@Test
129+
public void initializeWithNullDatafile() {
130+
Context context = mock(Context.class);
131+
Context appContext = mock(Context.class);
132+
when(context.getApplicationContext()).thenReturn(appContext);
133+
when(appContext.getPackageName()).thenReturn("com.optly");
134+
135+
String emptyString = null;
136+
137+
optimizelyManager.initialize(context, emptyString);
138+
verify(logger).error(eq("Unable to parse compiled data file"), any(ConfigParseException.class));
139+
}
140+
101141
@Test
102142
public void stop() {
103143
Context context = mock(Context.class);

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.optimizely.ab.Optimizely;
2424
import com.optimizely.ab.UnknownEventTypeException;
2525
import com.optimizely.ab.config.Experiment;
26+
import com.optimizely.ab.config.ProjectConfig;
2627
import com.optimizely.ab.config.Variation;
2728
import com.optimizely.ab.notification.NotificationListener;
2829

@@ -60,10 +61,10 @@ public class OptimizelyClient {
6061
*/
6162
public @Nullable Variation activate(@NonNull String experimentKey,
6263
@NonNull String userId) {
63-
if (optimizely != null) {
64+
if (isValid()) {
6465
return optimizely.activate(experimentKey, userId);
6566
} else {
66-
logger.warn("Optimizely is not initialized, can't activate experiment {} for user {}",
67+
logger.warn("Optimizely is not initialized, could not activate experiment {} for user {}",
6768
experimentKey, userId);
6869
return null;
6970
}
@@ -81,15 +82,28 @@ public class OptimizelyClient {
8182
public @Nullable Variation activate(@NonNull String experimentKey,
8283
@NonNull String userId,
8384
@NonNull Map<String, String> attributes) {
84-
if (optimizely != null) {
85+
if (isValid()) {
8586
return optimizely.activate(experimentKey, userId, attributes);
8687
} else {
87-
logger.warn("Optimizely is not initialized, can't activate experiment {} for user {} " +
88+
logger.warn("Optimizely is not initialized, could not activate experiment {} for user {} " +
8889
"with attributes", experimentKey, userId);
8990
return null;
9091
}
9192
}
9293

94+
/**
95+
* Get the {@link ProjectConfig} instance
96+
* @return the current {@link ProjectConfig} instance
97+
*/
98+
public @Nullable ProjectConfig getProjectConfig() {
99+
if (isValid()) {
100+
return optimizely.getProjectConfig();
101+
} else {
102+
logger.warn("Optimizely is not initialized, could not get project config");
103+
return null;
104+
}
105+
}
106+
93107
/**
94108
* Check that this is a valid instance
95109
* @return True if the OptimizelyClient instance was instantiated correctly
@@ -105,7 +119,7 @@ public boolean isValid() {
105119
*/
106120
public void track(@NonNull String eventName,
107121
@NonNull String userId) {
108-
if (optimizely != null) {
122+
if (isValid()) {
109123
optimizely.track(eventName, userId);
110124
} else {
111125
logger.warn("Optimizely is not initialized, could not track event {} for user {}", eventName, userId);
@@ -121,7 +135,7 @@ public void track(@NonNull String eventName,
121135
public void track(@NonNull String eventName,
122136
@NonNull String userId,
123137
@NonNull Map<String, String> attributes) throws UnknownEventTypeException {
124-
if (optimizely != null) {
138+
if (isValid()) {
125139
optimizely.track(eventName, userId, attributes);
126140

127141
} else {
@@ -141,7 +155,7 @@ public void track(@NonNull String eventName,
141155
@NonNull String userId,
142156
@NonNull Map<String, String> attributes,
143157
@NonNull Map<String, ?> eventTags) throws UnknownEventTypeException {
144-
if (optimizely != null) {
158+
if (isValid()) {
145159
optimizely.track(eventName, userId, attributes, eventTags);
146160

147161
} else {
@@ -160,7 +174,7 @@ public void track(@NonNull String eventName,
160174
public void track(@NonNull String eventName,
161175
@NonNull String userId,
162176
long eventValue) throws UnknownEventTypeException {
163-
if (optimizely != null) {
177+
if (isValid()) {
164178
optimizely.track(eventName, userId, eventValue);
165179
} else {
166180
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
@@ -181,7 +195,7 @@ public void track(@NonNull String eventName,
181195
@NonNull String userId,
182196
@NonNull Map<String, String> attributes,
183197
long eventValue) {
184-
if (optimizely != null) {
198+
if (isValid()) {
185199
optimizely.track(eventName, userId, attributes, eventValue);
186200
} else {
187201
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
@@ -215,7 +229,7 @@ public void track(@NonNull String eventName,
215229
@NonNull String userId,
216230
@NonNull Map<String, String> attributes,
217231
boolean activateExperiment) {
218-
if (optimizely != null) {
232+
if (isValid()) {
219233
return optimizely.getVariableString(variableKey, userId, attributes,
220234
activateExperiment);
221235
} else {
@@ -251,7 +265,7 @@ public void track(@NonNull String eventName,
251265
@NonNull String userId,
252266
@NonNull Map<String, String> attributes,
253267
boolean activateExperiment) {
254-
if (optimizely != null) {
268+
if (isValid()) {
255269
return optimizely.getVariableBoolean(variableKey, userId, attributes,
256270
activateExperiment);
257271
} else {
@@ -287,7 +301,7 @@ public void track(@NonNull String eventName,
287301
@NonNull String userId,
288302
@NonNull Map<String, String> attributes,
289303
boolean activateExperiment) {
290-
if (optimizely != null) {
304+
if (isValid()) {
291305
return optimizely.getVariableInteger(variableKey, userId, attributes,
292306
activateExperiment);
293307
} else {
@@ -323,7 +337,7 @@ public void track(@NonNull String eventName,
323337
@NonNull String userId,
324338
@NonNull Map<String, String> attributes,
325339
boolean activateExperiment) {
326-
if (optimizely != null) {
340+
if (isValid()) {
327341
return optimizely.getVariableDouble(variableKey, userId, attributes,
328342
activateExperiment);
329343
} else {
@@ -343,7 +357,7 @@ public void track(@NonNull String eventName,
343357
@SuppressWarnings("WeakerAccess")
344358
public @Nullable Variation getVariation(@NonNull String experimentKey,
345359
@NonNull String userId) {
346-
if (optimizely != null) {
360+
if (isValid()) {
347361
return optimizely.getVariation(experimentKey, userId);
348362
} else {
349363
logger.warn("Optimizely is not initialized, could not get variation for experiment {} " +
@@ -364,7 +378,7 @@ public void track(@NonNull String eventName,
364378
public @Nullable Variation getVariation(@NonNull String experimentKey,
365379
@NonNull String userId,
366380
@NonNull Map<String, String> attributes) {
367-
if (optimizely != null) {
381+
if (isValid()) {
368382
return optimizely.getVariation(experimentKey, userId, attributes);
369383
} else {
370384
logger.warn("Optimizely is not initialized, could not get variation for experiment {} " +
@@ -385,7 +399,7 @@ public void track(@NonNull String eventName,
385399
* @param listener listener to add
386400
*/
387401
public void addNotificationListener(@NonNull NotificationListener listener) {
388-
if (optimizely != null) {
402+
if (isValid()) {
389403
optimizely.addNotificationListener(listener);
390404
} else {
391405
logger.warn("Optimizely is not initialized, could not add notification listener");
@@ -398,7 +412,7 @@ public void addNotificationListener(@NonNull NotificationListener listener) {
398412
* @param listener listener to remove
399413
*/
400414
public void removeNotificationListener(@NonNull NotificationListener listener) {
401-
if (optimizely != null) {
415+
if (isValid()) {
402416
optimizely.removeNotificationListener(listener);
403417
} else {
404418
logger.warn("Optimizely is not initialized, could not remove notification listener");
@@ -409,7 +423,7 @@ public void removeNotificationListener(@NonNull NotificationListener listener) {
409423
* Remove all {@link NotificationListener} instances.
410424
*/
411425
public void clearNotificationListeners() {
412-
if (optimizely != null) {
426+
if (isValid()) {
413427
optimizely.clearNotificationListeners();
414428
} else {
415429
logger.warn("Optimizely is not initialized, could not clear notification listeners");

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testGoodActivation1() {
5555
public void testBadActivation1() {
5656
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
5757
optimizelyClient.activate("1", "1");
58-
verify(logger).warn("Optimizely is not initialized, can't activate experiment {} " +
58+
verify(logger).warn("Optimizely is not initialized, could not activate experiment {} " +
5959
"for user {}", "1", "1");
6060
}
6161

@@ -71,7 +71,7 @@ public void testGoodActivation2() {
7171
public void testBadActivation2() {
7272
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
7373
optimizelyClient.activate("1", "1", new HashMap<String, String>());
74-
verify(logger).warn("Optimizely is not initialized, can't activate experiment {} " +
74+
verify(logger).warn("Optimizely is not initialized, could not activate experiment {} " +
7575
"for user {} with attributes", "1", "1");
7676
}
7777

@@ -182,6 +182,20 @@ public void testBadGetVariation3() {
182182
"for user {} with attributes", "1", "1");
183183
}
184184

185+
@Test
186+
public void testGoodGetProjectConfig() {
187+
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
188+
optimizelyClient.getProjectConfig();
189+
verify(optimizely).getProjectConfig();
190+
}
191+
192+
@Test
193+
public void testBadGetProjectConfig() {
194+
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
195+
optimizelyClient.getProjectConfig();
196+
verify(logger).warn("Optimizely is not initialized, could not get project config");
197+
}
198+
185199
@Test
186200
public void testIsValid() {
187201
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ buildscript {
3333
jcenter()
3434
}
3535
dependencies {
36-
classpath 'com.android.tools.build:gradle:2.2.3'
36+
classpath 'com.android.tools.build:gradle:2.3.1'
3737

3838
// NOTE: Do not place your application dependencies here; they belong
3939
// in the individual module build.gradle files
@@ -48,7 +48,7 @@ allprojects {
4848

4949
ext {
5050
compile_sdk_version = 24
51-
build_tools_version = "24.0.3"
51+
build_tools_version = "25.0.2"
5252
min_sdk_version = 10
5353
target_sdk_version = 24
5454

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Aug 17 09:30:38 PDT 2016
1+
#Tue Apr 04 22:41:06 CEST 2017
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-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 commit comments

Comments
 (0)