我试图建立一个重新命名的模拟信息 来控制我的申请
它的外观如下:
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 looks 如下:
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);
}
}
当我进行测试时, 它会扔出一个不支持的操作例外。 与下面的堆叠跟踪 。
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)
显然,城市航空机的配置需要一些资源。我需要一些帮助来实施RenaminingMocktext中的资源配置。