本文整理了Java中org.robolectric.util.ReflectionHelpers.setStaticField
方法的一些代码示例,展示了ReflectionHelpers.setStaticField
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReflectionHelpers.setStaticField
方法的具体详情如下:
包路径:org.robolectric.util.ReflectionHelpers
类名称:ReflectionHelpers
方法名:setStaticField
[英]Reflectively set the value of a static field.
[中]反射设置静态字段的值。
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#DEVICE} field.
*
* It will be reset for the next test.
*/
public static void setDevice(String device) {
ReflectionHelpers.setStaticField(Build.class, "DEVICE", device);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#TAGS} field.
*
* It will be reset for the next test.
*/
public static void setTags(String tags) {
ReflectionHelpers.setStaticField(Build.class, "TAGS", tags);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#ID} field.
*
* It will be reset for the next test.
*/
public static void setId(String id) {
ReflectionHelpers.setStaticField(Build.class, "ID", id);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build.VERSION#CODENAME} field.
*
* It will be reset for the next test.
*/
public static void setVersionCodename(String versionCodename) {
ReflectionHelpers.setStaticField(Build.VERSION.class, "CODENAME", versionCodename);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#MODEL} field.
*
* It will be reset for the next test.
*/
public static void setModel(String model) {
ReflectionHelpers.setStaticField(Build.class, "MODEL", model);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#MANUFACTURER} field.
*
* It will be reset for the next test.
*/
public static void setManufacturer(String manufacturer) {
ReflectionHelpers.setStaticField(Build.class, "MANUFACTURER", manufacturer);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build.VERSION#RELEASE} field.
*
* It will be reset for the next test.
*/
public static void setVersionRelease(String release) {
ReflectionHelpers.setStaticField(Build.VERSION.class, "RELEASE", release);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#TYPE} field.
*
* It will be reset for the next test.
*/
public static void setType(String type) {
ReflectionHelpers.setStaticField(Build.class, "TYPE", type);
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static void reset() {
// rely on MotionEvent finalizer to clear native object instead of calling
// nativeMotionEventRegistry.clear();
ReflectionHelpers.setStaticField(MotionEvent.class, "gRecyclerTop", null);
ReflectionHelpers.setStaticField(MotionEvent.class, "gSharedTempPointerCoords", null);
ReflectionHelpers.setStaticField(MotionEvent.class, "gSharedTempPointerProperties", null);
ReflectionHelpers.setStaticField(MotionEvent.class, "gRecyclerUsed", 0);
ReflectionHelpers.setStaticField(MotionEvent.class, "gSharedTempPointerIndexMap", null);
}
代码示例来源:origin: robolectric/robolectric
/**
* Sets the value of the {@link Build#SUPPORTED_64_BIT_ABIS} field. Available in Android L+.
*
* <p>It will be reset for the next test.
*/
@TargetApi(LOLLIPOP)
public static void setSupported64BitAbis(String[] supported64BitAbis) {
ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_64_BIT_ABIS", supported64BitAbis);
}
代码示例来源:origin: bumptech/glide
private static void setSdkVersionInt(int version) {
ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", version);
}
}
代码示例来源:origin: bumptech/glide
public static void setSdkVersionInt(int version) {
ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", version);
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static void reset() {
ReflectionHelpers.setStaticField(
WindowManagerGlobal.class, "sDefaultWindowManager", null);
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static void reset() {
ReflectionHelpers.setStaticField(MediaRouter.class, "sStatic", null);
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected static void __staticInitializer__() {
ReflectionHelpers.setStaticField(
VisualVoicemailSms.class, "CREATOR", ShadowVisualVoicemailSms.CREATOR);
}
代码示例来源:origin: robolectric/robolectric
@Override
public void setSdk(Sdk sdk) {
apiLevel = sdk.getApiLevel();
sdkJarPath = sdk.getJarPath();
ReflectionHelpers.setStaticField(RuntimeEnvironment.class, "apiLevel", apiLevel);
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static void reset() {
if (resettableArrays == null) {
resettableArrays = obtainResettableArrays();
}
for (LongSparseArray<?> sparseArray : resettableArrays) {
sparseArray.clear();
}
system = null;
ReflectionHelpers.setStaticField(Resources.class, "mSystem", null);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setStaticValue_shouldIgnoreFinalModifier() {
ReflectionHelpers.setStaticField(Build.class, "MODEL", "expected value");
assertThat(Build.MODEL).isEqualTo("expected value");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setStaticFieldReflectively_withFieldName_setsStaticFields() {
int startingValue = ReflectionHelpers.getStaticField(ExampleDescendant.class, "DESCENDANT");
ReflectionHelpers.setStaticField(ExampleDescendant.class, "DESCENDANT", 7);
assertThat(startingValue).named("startingValue").isEqualTo(6);
assertThat(ExampleDescendant.DESCENDANT).named("DESCENDENT").isEqualTo(7);
// Reset the value to avoid test pollution
ReflectionHelpers.setStaticField(ExampleDescendant.class, "DESCENDANT", startingValue);
}
代码示例来源:origin: ReactiveX/RxAndroid
@Test
public void asyncIgnoredPre16() {
ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 14);
ShadowLooper mainLooper = ShadowLooper.getShadowMainLooper();
mainLooper.pause();
ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
Scheduler main = AndroidSchedulers.from(Looper.getMainLooper(), true);
main.scheduleDirect(new Runnable() {
@Override public void run() {
}
});
Message message = mainMessageQueue.getHead();
assertFalse(message.isAsynchronous());
}
}
内容来源于网络,如有侵权,请联系作者删除!