Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support AppComponentFactory in Robolectric
Signed-off-by: utzcoz <utzcoz@outlook.com>
- Loading branch information
Showing
8 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
robolectric/src/test/java/org/robolectric/CustomAppComponentFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.robolectric; | ||
|
||
import android.app.AppComponentFactory; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Intent; | ||
|
||
public class CustomAppComponentFactory extends AppComponentFactory { | ||
@Override | ||
public BroadcastReceiver instantiateReceiver(ClassLoader cl, String className, Intent intent) | ||
throws InstantiationException, IllegalAccessException, ClassNotFoundException { | ||
if (className != null && className.contains(CustomConstructorReceiver.class.getName())) { | ||
return new CustomConstructorReceiver(100); | ||
} | ||
return super.instantiateReceiver(cl, className, intent); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
robolectric/src/test/java/org/robolectric/CustomConstructorReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.robolectric; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
public class CustomConstructorReceiver extends BroadcastReceiver { | ||
private final int intValue; | ||
|
||
public CustomConstructorReceiver(int intValue) { | ||
// We don't use intValue actually, and we only want to use this class to test the initialization | ||
// of BroadcastReceiver with a custom constructor. | ||
this.intValue = intValue; | ||
} | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
robolectric/src/test/resources/TestAndroidManifestWithAppComponentFactory.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.robolectric"> | ||
<uses-sdk android:targetSdkVersion="18"/> | ||
|
||
<application | ||
android:appComponentFactory=".CustomAppComponentFactory"> | ||
<receiver android:name=".CustomConstructorReceiver"> | ||
<intent-filter> | ||
<action android:name="org.robolectric.ACTION_CUSTOM_CONSTRUCTOR"/> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters