Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 4d5ca6e

Browse files
committed
Upgrade to Robolectric 3.0
1 parent 314f3e3 commit 4d5ca6e

38 files changed

Lines changed: 114 additions & 167 deletions

File tree

‎AndroidAnnotations/androidannotations-core/androidannotations-test/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
<groupId>org.robolectric</groupId>
6262
<artifactId>robolectric</artifactId>
6363
</dependency>
64+
<dependency>
65+
<groupId>org.robolectric</groupId>
66+
<artifactId>shadows-support-v4</artifactId>
67+
<version>${robolectric.version}</version>
68+
<scope>test</scope>
69+
</dependency>
6470
<dependency>
6571
<groupId>org.easytesting</groupId>
6672
<artifactId>fest-reflect</artifactId>

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/main/java/org/androidannotations/test/preference/PreferencesInjectedActivity.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class PreferencesInjectedActivity extends PreferenceActivity {
4646
@SuppressWarnings("deprecation")
4747
@Override
4848
protected void onCreate(android.os.Bundle savedInstanceState) {
49+
super.onCreate(savedInstanceState);
4950
addPreferencesFromResource(R.xml.settings);
5051
}
5152

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/main/java/org/androidannotations/test/res/ResActivity.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ResActivity extends Activity {
3636
// @AnimationRes
3737
XmlResourceParser fade_in;
3838

39-
// @AnimationRes
39+
@AnimationRes
4040
Animation fadein;
4141

4242
@DrawableRes

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/AwaitingResultFragmentTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
package org.androidannotations.test;
1717

1818
import static org.fest.assertions.api.Assertions.assertThat;
19+
import static org.robolectric.internal.ShadowExtractor.extract;
20+
import static org.robolectric.shadows.support.v4.SupportFragmentTestUtil.startFragment;
1921

2022
import org.junit.Before;
2123
import org.junit.Test;
2224
import org.junit.runner.RunWith;
23-
import org.robolectric.Robolectric;
2425
import org.robolectric.RobolectricTestRunner;
2526
import org.robolectric.shadows.ShadowActivity;
26-
import org.robolectric.util.FragmentTestUtil;
2727

2828
import android.app.Activity;
2929
import android.content.Intent;
@@ -36,7 +36,7 @@ public class AwaitingResultFragmentTest {
3636
@Before
3737
public void setUp() {
3838
fragment = new AwaitingResultFragment_();
39-
FragmentTestUtil.startFragment(fragment);
39+
startFragment(fragment);
4040

4141
assertThat(fragment.onResultCalled).isFalse();
4242
}
@@ -45,7 +45,7 @@ public void setUp() {
4545
public void testOnResultCalledInFragment() {
4646
FragmentStartedActivity_.intent(fragment).startForResult(AwaitingResultFragment.FIRST_REQUEST);
4747

48-
ShadowActivity a = Robolectric.shadowOf_(fragment.getActivity());
48+
ShadowActivity a = (ShadowActivity) extract(fragment.getActivity());
4949
a.receiveResult(FragmentStartedActivity_.intent(fragment).get(), Activity.RESULT_OK, new Intent());
5050

5151
assertThat(fragment.onResultCalled).isTrue();

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/CustomShadowBundle.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package org.androidannotations.test;
1717

18-
import static org.robolectric.Robolectric.directlyOn;
18+
import static org.robolectric.internal.Shadow.directlyOn;
1919

2020
import java.util.Arrays;
2121

2222
import org.robolectric.annotation.Implementation;
2323
import org.robolectric.annotation.Implements;
2424
import org.robolectric.annotation.RealObject;
25-
import org.robolectric.internal.ReflectionHelpers;
2625
import org.robolectric.shadows.ShadowBundle;
26+
import org.robolectric.util.ReflectionHelpers;
2727

2828
import android.os.Bundle;
2929
import android.os.Parcelable;

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/InjectExtraTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class InjectExtraTest {
4242

4343
@Before
4444
public void setUp() {
45-
controller = ActivityController.of(ExtraInjectedActivity_.class);
45+
controller = Robolectric.buildActivity(ExtraInjectedActivity_.class);
4646
activity = controller.get();
4747
}
4848

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/SeekBarChangeListenedActivityTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import static org.fest.assertions.api.Assertions.assertThat;
1919
import static org.robolectric.Robolectric.setupActivity;
20-
import static org.robolectric.Robolectric.shadowOf_;
20+
import static org.robolectric.internal.ShadowExtractor.extract;
2121

2222
import org.junit.Before;
2323
import org.junit.Test;
@@ -38,7 +38,7 @@ public class SeekBarChangeListenedActivityTest {
3838
public void setUp() {
3939
activity = setupActivity(SeekBarChangeListenedActivity_.class);
4040
seekBar = (SeekBar) activity.findViewById(R.id.seekBar1);
41-
shadowSeekBar = shadowOf_(seekBar);
41+
shadowSeekBar = (ShadowSeekBar) extract(seekBar);
4242
}
4343

4444
@Test

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/ServiceInjectionTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void servicesAreInjected() {
6464
// assertThat(activity.fingerprintManager).isNotNull(); // TODO API 23
6565
// assertThat(activity.hardwarePropertiesManager).isNotNull(); // TODO API 24
6666
// assertThat(activity.hdmiControlManager).isNotNull(); // hidden API
67-
// assertThat(activity.inputManager).isNotNull(); // TODO no support yet in Robolectric
67+
// assertThat(activity.inputManager).isNotNull();
6868
assertThat(activity.inputMethodManager).isNotNull();
6969
// assertThat(activity.jobScheduler).isNotNull(); // TODO API 21
7070
assertThat(activity.keyguardManager).isNotNull();
@@ -79,7 +79,7 @@ public void servicesAreInjected() {
7979
// assertThat(activity.networkManagementService).isNotNull(); // hidden API
8080
// assertThat(activity.networkPolicyManager).isNotNull(); // hidden API
8181
// assertThat(activity.networkStatsManager).isNotNull(); // TODO API 23
82-
// assertThat(activity.nfcManager).isNotNull(); // TODO no support yet in Robolectric
82+
assertThat(activity.nfcManager).isNotNull();
8383
assertThat(activity.notificationManager).isNotNull();
8484
// assertThat(activity.nsdManager).isNotNull(); // TODO no support yet in Robolectric
8585
// assertThat(activity.persistentDataBlockManager).isNotNull(); // hidden API
Original file line numberDiff line numberDiff line change
@@ -1,63 +0,0 @@
1-
/**
2-
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed To in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
15-
*/
16-
package org.androidannotations.test;
17-
18-
import static org.fest.reflect.core.Reflection.staticField;
19-
20-
import java.lang.reflect.Method;
21-
22-
import org.androidannotations.api.UiThreadExecutor;
23-
import org.robolectric.Robolectric;
24-
import org.robolectric.TestLifecycleApplication;
25-
import org.robolectric.shadows.ShadowHandler;
26-
27-
import android.app.Application;
28-
import android.os.Handler;
29-
import android.os.Message;
30-
31-
public class TestApplication extends Application implements TestLifecycleApplication {
32-
33-
@Override
34-
public void beforeTest(Method method) {
35-
}
36-
37-
@Override
38-
public void prepareTest(Object test) {
39-
hackHandler();
40-
}
41-
42-
@Override
43-
public void afterTest(Method method) {
44-
}
45-
46-
// TODO remove this after upgrading robolectric to 3+
47-
private void hackHandler() {
48-
final Handler handler = staticField("HANDLER").ofType(Handler.class).in(UiThreadExecutor.class).get();
49-
ShadowHandler shadowHandler = Robolectric.shadowOf_(handler);
50-
shadowHandler.__constructor__(new Handler.Callback() {
51-
@Override
52-
public boolean handleMessage(Message msg) {
53-
// in the robolectric 2.4 there is a strange code - they call
54-
// Handler's handleMessage (it do nothing)
55-
// instead of dispatch, that actually do the job. This is just a
56-
// dirty work-around. It should be removed
57-
// with newer version of robolectric.
58-
handler.dispatchMessage(msg);
59-
return true;
60-
}
61-
});
62-
}
63-
}

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/TextWatchedActivityTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import static org.fest.assertions.api.Assertions.assertThat;
1919
import static org.robolectric.Robolectric.setupActivity;
20-
import static org.robolectric.Robolectric.shadowOf_;
20+
import static org.robolectric.internal.ShadowExtractor.extract;
2121

2222
import org.junit.Before;
2323
import org.junit.Test;
@@ -174,21 +174,21 @@ public void testBeforeTextChangeParametersPassed() {
174174
}
175175

176176
private static void afterTextChanged(TextView textView, Editable s) {
177-
ShadowTextView shadowTextView = shadowOf_(textView);
177+
ShadowTextView shadowTextView = (ShadowTextView) extract(textView);
178178
for (TextWatcher textWatcher : shadowTextView.getWatchers()) {
179179
textWatcher.afterTextChanged(s);
180180
}
181181
}
182182

183183
private static void beforeTextChanged(TextView textView, CharSequence s, int start, int count, int after) {
184-
ShadowTextView shadowTextView = shadowOf_(textView);
184+
ShadowTextView shadowTextView = (ShadowTextView) extract(textView);
185185
for (TextWatcher textWatcher : shadowTextView.getWatchers()) {
186186
textWatcher.beforeTextChanged(s, start, count, after);
187187
}
188188
}
189189

190190
private static void onTextChanged(TextView textView, CharSequence s, int start, int before, int count) {
191-
ShadowTextView shadowTextView = shadowOf_(textView);
191+
ShadowTextView shadowTextView = (ShadowTextView) extract(textView);
192192
for (TextWatcher textWatcher : shadowTextView.getWatchers()) {
193193
textWatcher.onTextChanged(s, start, before, count);
194194
}

0 commit comments

Comments
 (0)