Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: upgrade the androidx and get all tests passing #356

Merged
merged 11 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
targetSdkVersion target_sdk_version
versionCode 1
versionName version_name
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
buildConfigField "String", "CLIENT_VERSION", "\"$version_name\""
consumerProguardFiles '../proguard-rules.txt'
}
Expand Down Expand Up @@ -69,18 +69,18 @@ dependencies {
}

compileOnly "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
implementation "com.android.support:support-annotations:$support_annotations_ver"
implementation "androidx.annotation:annotation:$annotations_ver"

testImplementation "junit:junit:$junit_ver"
testImplementation "org.mockito:mockito-core:$mockito_ver"
testImplementation "org.powermock:powermock-mockito-release-full:$powermock_ver"
testImplementation "com.noveogroup.android:android-logger:$android_logger_ver"

androidTestImplementation "com.android.support.test:runner:$support_test_runner_ver"
androidTestImplementation "androidx.test.ext:junit:$androidx_test"
// Set this dependency to use JUnit 4 rules
androidTestImplementation "com.android.support.test:rules:$support_test_runner_ver"
androidTestImplementation "androidx.test:rules:$androidx_test"
// Set this dependency to build and run Espresso tests
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espresso_ver"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver"
androidTestImplementation "org.mockito:mockito-core:$mockito_ver"
androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver"
androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.test.runner.AndroidJUnit4;
import androidx.annotation.RequiresApi;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.optimizely.ab.event.internal.payload.Event;
import com.optimizely.ab.event.internal.payload.EventBatch;

import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.optimizely.ab.android.sdk;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import androidx.test.platform.app.InstrumentationRegistry;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -87,11 +87,11 @@ public static Collection<Object[]> data() throws IOException {
return Arrays.asList(new Object[][] {
{
3,
loadRawResource(InstrumentationRegistry.getTargetContext(),R.raw.validprojectconfigv3)
loadRawResource(InstrumentationRegistry.getInstrumentation().getTargetContext(),R.raw.validprojectconfigv3)
},
{
4,
loadRawResource(InstrumentationRegistry.getTargetContext(),R.raw.validprojectconfigv4)
loadRawResource(InstrumentationRegistry.getInstrumentation().getTargetContext(),R.raw.validprojectconfigv4)
}
});
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public static Collection<Object[]> data() throws IOException {
public OptimizelyClientTest(int datafileVersion,String datafile){
try {
this.datafileVersion = datafileVersion;
eventHandler = spy(DefaultEventHandler.getInstance(InstrumentationRegistry.getTargetContext()));
eventHandler = spy(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext()));
optimizely = Optimizely.builder(datafile, eventHandler).build();
if(datafileVersion==3) {
when(bucketer.bucket(optimizely.getProjectConfig().getExperiments().get(0), GENERIC_USER_ID, optimizely.getProjectConfig())).thenReturn(optimizely.getProjectConfig().getExperiments().get(0).getVariations().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
***************************************************************************/
package com.optimizely.ab.android.sdk;

import java.util.HashMap;
import java.util.Map;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.support.test.runner.AndroidJUnit4;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.optimizely.ab.android.sdk;

import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.optimizely.ab.OptimizelyRuntimeException;
import com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler;
import com.optimizely.ab.android.event_handler.DefaultEventHandler;
Expand Down Expand Up @@ -51,29 +51,29 @@ public <T extends OptimizelyRuntimeException> void handleError(T exception) thro
}
};

OptimizelyManager manager = OptimizelyManager.builder(testProjectId).withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getTargetContext()))
OptimizelyManager manager = OptimizelyManager.builder(testProjectId).withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext()))
.withDatafileDownloadInterval(30L)
.withEventDispatchInterval(30L)
.withDatafileHandler(new DefaultDatafileHandler())
.withErrorHandler(errorHandler)
.withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getTargetContext()))
.withLogger(logger).build(InstrumentationRegistry.getTargetContext());
.withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext()))
.withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext());

assertNotNull(manager);
assertNotNull(manager.getDatafileHandler());
assertNotNull(manager.getUserProfileService());
assertNotNull(manager.getErrorHandler(InstrumentationRegistry.getTargetContext()));
assertNotNull(manager.getEventHandler(InstrumentationRegistry.getTargetContext()));
assertNotNull(manager.getErrorHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
}

@Test
public void testBuilderWithOut() {
OptimizelyManager manager = OptimizelyManager.builder(testProjectId).build(InstrumentationRegistry.getTargetContext());
OptimizelyManager manager = OptimizelyManager.builder(testProjectId).build(InstrumentationRegistry.getInstrumentation().getTargetContext());

assertNotNull(manager);
assertNotNull(manager.getDatafileHandler());
assertNotNull(manager.getUserProfileService());
assertNotNull(manager.getEventHandler(InstrumentationRegistry.getTargetContext()));
assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
}

}
Loading