Skip to content

Commit

Permalink
Upgrade Robolectric to pass tests with Rx
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanenicolas committed Apr 28, 2016
1 parent 5c36fd2 commit 8432d84
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ ext.deps = [// Common
compiletesting: 'com.google.testing.compile:compile-testing:0.7',
easymock : 'org.easymock:easymock:3.4',
powermock : 'org.powermock:powermock-easymock-release-full:1.6.4',
robolectric : 'org.robolectric:robolectric:2.2',]
robolectric : 'org.robolectric:robolectric:3.0',]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ActivityController;
import toothpick.Scope;
Expand All @@ -18,8 +18,8 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;

@RunWith(RobolectricTestRunner.class) //
@Config(manifest = "src/main/AndroidManifest.xml")
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class SimpleActivityTest {

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ActivityController;
import toothpick.testing.ToothPickRule;
Expand All @@ -19,8 +19,8 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;

@RunWith(RobolectricTestRunner.class) //
@Config(manifest = "src/main/AndroidManifest.xml")
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class SimpleActivityTestWithRules {

//do not use @Rule here, we use a chain below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import toothpick.Scope;
import toothpick.ToothPick;

Expand All @@ -23,7 +24,7 @@ public class ActivityModuleTest {
public void testGet() throws Exception {
//GIVEN
Activity activity = Robolectric.buildActivity(Activity.class).create().get();
Application application = Robolectric.application;
Application application = RuntimeEnvironment.application;
Scope appScope = ToothPick.openScope(application);
appScope.installModules(new ApplicationModule(application));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import toothpick.Scope;
import toothpick.ToothPick;

Expand All @@ -40,7 +41,7 @@ public class ApplicationModuleTest {
public void testModule_shouldReturnApplicationBindings() throws Exception {
//GIVEN
Activity activity = Robolectric.buildActivity(Activity.class).create().get();
Application application = Robolectric.application;
Application application = RuntimeEnvironment.application;
Scope appScope = ToothPick.openScope(application);
appScope.installModules(new ApplicationModule(application));

Expand All @@ -54,7 +55,7 @@ public void testModule_shouldReturnApplicationBindings() throws Exception {
SharedPreferences sharedPreferences = appScope.getInstance(SharedPreferences.class);

//THEN
assertThat(injectedApp, is(Robolectric.application));
assertThat(injectedApp, is(RuntimeEnvironment.application));
assertThat(accountManager, notNullValue());
assertThat(assetManager, notNullValue());
assertThat(contentResolver, notNullValue());
Expand All @@ -67,7 +68,7 @@ public void testModule_shouldReturnApplicationBindings() throws Exception {
public void testModule_shouldReturnSystemServices() throws Exception {
//GIVEN
Activity activity = Robolectric.buildActivity(Activity.class).create().get();
Application application = Robolectric.application;
Application application = RuntimeEnvironment.application;
Scope appScope = ToothPick.openScope(application);
appScope.installModules(new ApplicationModule(application));

Expand All @@ -90,7 +91,7 @@ public void testModule_shouldReturnSystemServices() throws Exception {
DownloadManager downloadManager = appScope.getInstance(DownloadManager.class);

//THEN
assertThat(injectedApp, is(Robolectric.application));
assertThat(injectedApp, is(RuntimeEnvironment.application));
assertThat(locationManager, notNullValue());
assertThat(windowManager, notNullValue());
assertThat(activityManager, notNullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import toothpick.Scope;
import toothpick.ToothPick;

Expand All @@ -25,7 +26,7 @@ public class SupportActivityModuleTest {
public void testGet() throws Exception {
//GIVEN
FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).create().get();
Application application = Robolectric.application;
Application application = RuntimeEnvironment.application;
Scope appScope = ToothPick.openScope(application);
appScope.installModules(new ApplicationModule(application));

Expand Down

0 comments on commit 8432d84

Please sign in to comment.