我正在尝试构建一个 RenamingMockContext 来控制 MyAppliction。
它看起来如下:
public class RenamingMockContext extends RenamingDelegatingContext {
private static final String PREFIX = "test.";
public RenamingMockContext(Context context) {
super(new DelegatedMockContext(context), PREFIX);
}
private static class DelegatedMockContext extends MockContext {
private Context mDelegatedContext;
public DelegatedMockContext(Context context) {
mDelegatedContext = context;
}
@Override
public String getPackageName() {
return mDelegatedContext.getPackageName();
}
}
}
MyApplication 如下所示:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
UAirship.takeOff(this, options);
PushManager.enablePush();
PushManager.shared().setIntentReceiver(UrbanAirshipReceiver.class);
}
}
当我运行测试时,它会引发 UnsupportedOperationException。使用以下堆栈跟踪。
java.lang.UnsupportedOperationException
at com.carplink.aCarpLink.test.RenamingMockContext$DelegatedMockContext.getResources(RenamingMockContext.java:29)
at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
at com.urbanairship.Options.loadFromProperties(Unknown Source)
at com.urbanairship.Options.loadFromProperties(Unknown Source)
at com.urbanairship.AirshipConfigOptions.loadDefaultOptions(Unknown Source)
at com.carplink.aCarpLink.CarpLinkApplication.onCreate(CarpLinkApplication.java:15)
at android.test.ApplicationTestCase.createApplication(ApplicationTestCase.java:122)
at com.carplink.aCarpLink.test.CarpLinkApplicationTest.setUp(CarpLinkApplicationTest.java:24)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1606)
显然,城市飞艇的配置需要一些资源。我可以在如何在 RenamingMockContext 中实现 getResources 方面使用一些帮助。