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

Commit f0feb19

Browse files
committed
Add real behavior for ShadowBundle#getParcelableArray
1 parent 8c12b25 commit f0feb19

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (C) 2010-2014 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.test15;
17+
18+
import static org.robolectric.Robolectric.directlyOn;
19+
20+
import java.util.Arrays;
21+
22+
import org.robolectric.annotation.Implementation;
23+
import org.robolectric.annotation.Implements;
24+
import org.robolectric.annotation.RealObject;
25+
import org.robolectric.internal.ReflectionHelpers;
26+
import org.robolectric.shadows.ShadowBundle;
27+
28+
import android.os.Bundle;
29+
import android.os.Parcelable;
30+
31+
/***
32+
* Workaround for https://github.com/robolectric/robolectric/issues/1440
33+
*/
34+
@Implements(Bundle.class)
35+
public class CustomShadowBundle extends ShadowBundle {
36+
37+
@RealObject
38+
private Bundle realObject;
39+
40+
@Implementation
41+
public Parcelable[] getParcelableArray(String key) {
42+
Parcelable[] array = directlyOn(realObject, Bundle.class, "getParcelableArray", new ReflectionHelpers.ClassParameter<String>(String.class, key));
43+
44+
if (array == null) {
45+
return null;
46+
}
47+
48+
return Arrays.copyOf(array, array.length, Parcelable[].class);
49+
}
50+
}

‎AndroidAnnotations/functional-test-1-5/src/test/java/org/androidannotations/test15/FragmentArgsTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import org.junit.Test;
2121
import org.junit.runner.RunWith;
2222
import org.robolectric.RobolectricTestRunner;
23+
import org.robolectric.annotation.Config;
2324

2425
import android.os.Bundle;
2526

27+
@Config(shadows = CustomShadowBundle.class)
2628
@RunWith(RobolectricTestRunner.class)
2729
public class FragmentArgsTest {
2830

‎AndroidAnnotations/functional-test-1-5/src/test/java/org/androidannotations/test15/InjectExtraTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
import org.junit.runner.RunWith;
2525
import org.robolectric.Robolectric;
2626
import org.robolectric.RobolectricTestRunner;
27+
import org.robolectric.annotation.Config;
2728
import org.robolectric.util.ActivityController;
2829

2930
import android.app.Activity;
3031
import android.content.Context;
3132

33+
@Config(shadows = CustomShadowBundle.class)
3234
@RunWith(RobolectricTestRunner.class)
3335
public class InjectExtraTest {
3436

‎AndroidAnnotations/functional-test-1-5/src/test/java/org/androidannotations/test15/instancestate/SaveInstanceStateActivityParameterizedTest.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222
import java.util.Arrays;
2323
import java.util.Collection;
2424

25+
import org.androidannotations.test15.CustomShadowBundle;
2526
import org.fest.util.Lists;
2627
import org.junit.Test;
2728
import org.junit.runner.RunWith;
2829
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters;
2930
import org.robolectric.ParameterizedRobolectricTestRunnerWorkaround;
3031
import org.robolectric.Robolectric;
32+
import org.robolectric.annotation.Config;
3133

3234
import android.os.Bundle;
3335

36+
@Config(shadows = CustomShadowBundle.class)
3437
@RunWith(ParameterizedRobolectricTestRunnerWorkaround.class)
3538
public class SaveInstanceStateActivityParameterizedTest {
3639

0 commit comments

Comments
 (0)