本文整理了Java中org.robolectric.util.ReflectionHelpers.getField
方法的一些代码示例,展示了ReflectionHelpers.getField
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReflectionHelpers.getField
方法的具体详情如下:
包路径:org.robolectric.util.ReflectionHelpers
类名称:ReflectionHelpers
方法名:getField
[英]Reflectively get the value of a field.
[中]反射式获取字段的值。
代码示例来源:origin: robolectric/robolectric
/**
* Returns the Uri set by {@code setNotificationUri()}.
*
* @return Notification URI.
*/
public Uri getNotificationUri_Compatibility() {
return ReflectionHelpers.getField(realAbstractCursor, "mNotifyUri");
}
}
代码示例来源:origin: robolectric/robolectric
/**
* Allows to get the stored netId.
*
* @return The netId.
*/
public int getNetId() {
return ReflectionHelpers.getField(realObject, "netId");
}
}
代码示例来源:origin: robolectric/robolectric
static CppAssetManager2 NdkAssetManagerForJavaObject(/* JNIEnv* env,*/ AssetManager jassetmanager) {
// long assetmanager_handle = env.GetLongField(jassetmanager, gAssetManagerOffsets.mObject);
long assetmanager_handle = ReflectionHelpers.getField(jassetmanager, "mObject");
CppAssetManager2 am = Registries.NATIVE_ASSET_MANAGER_REGISTRY.getNativeObject(assetmanager_handle);
if (am == null) {
throw new IllegalStateException("AssetManager has been finalized!");
}
return am;
}
代码示例来源:origin: robolectric/robolectric
private NativeInput.MotionEvent getNativeMotionEvent() {
long nativePtr;
if (RuntimeEnvironment.getApiLevel() <= KITKAT_WATCH) {
Integer nativePtrInt = ReflectionHelpers.getField(realMotionEvent, "mNativePtr");
nativePtr = nativePtrInt.longValue();
} else {
nativePtr = ReflectionHelpers.getField(realMotionEvent, "mNativePtr");
}
return nativeMotionEventRegistry.getNativeObject(nativePtr);
}
代码示例来源:origin: robolectric/robolectric
/**
* @return the message displayed in the dialog
*/
@Override
public CharSequence getMessage() {
if (mProgressStyle == ProgressDialog.STYLE_HORIZONTAL) {
return super.getMessage();
} else {
TextView message = ReflectionHelpers.getField(realProgressDialog, "mMessageView");
return message.getText();
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected int getFd() {
try {
return ReflectionHelpers.getField(file.getFD(), "fd");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: robolectric/robolectric
long getNativePtr() {
if (RuntimeEnvironment.getApiLevel() >= N) {
ResourcesImpl.ThemeImpl themeImpl = ReflectionHelpers.getField(realTheme, "mThemeImpl");
return ((ShadowLegacyThemeImpl) Shadow.extract(themeImpl)).getNativePtr();
} else {
return ((Number) ReflectionHelpers.getField(realTheme, "mTheme")).longValue();
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void writeByteArray(byte[] b, int offset, int len) {
if (b == null) {
realObject.writeInt(-1);
return;
}
Number nativePtr = ReflectionHelpers.getField(realObject, "mNativePtr");
nativeWriteByteArray(nativePtr.longValue(), b, offset, len);
}
代码示例来源:origin: robolectric/robolectric
@Override
public boolean compare(T actual, F expected) {
return Objects.equals(ReflectionHelpers.getField(actual, fieldName), expected);
}
代码示例来源:origin: robolectric/robolectric
@Implementation
@HiddenApi
public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
Context context = ReflectionHelpers.getField(realObject, "mContext");
List<PhoneAccountHandle> results = new ArrayList<>();
for (PhoneAccountHandle handle : accounts.keySet()) {
if (handle.getComponentName().getPackageName().equals(context.getPackageName())) {
results.add(handle);
}
}
return results;
}
代码示例来源:origin: robolectric/robolectric
@Implementation(minSdk = M)
protected void writeBlob(byte[] b, int offset, int len) {
if (b == null) {
realObject.writeInt(-1);
return;
}
throwsIfOutOfBounds(b.length, offset, len);
long nativePtr = ReflectionHelpers.getField(realObject, "mNativePtr");
nativeWriteBlob(nativePtr, b, offset, len);
}
代码示例来源:origin: robolectric/robolectric
private String fieldByReflectionHelpers(SomeClass o) {
ReflectionHelpers.setField(o, "c", "abc");
return ReflectionHelpers.getField(o, "c");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getFieldReflectively_givesHelpfulExceptions() {
ExampleDescendant example = new ExampleDescendant();
try {
ReflectionHelpers.getField(example, "nonExistent");
fail("Expected exception not thrown");
} catch (RuntimeException e) {
if (!e.getMessage().contains("nonExistent")) {
throw new RuntimeException("Incorrect exception thrown", e);
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(maxSdk = Build.VERSION_CODES.O)
public void shouldSupportLocaleEn_US_perMill() throws Exception {
LocaleData localeData = LocaleData.get(Locale.US);
char perMillValue = ReflectionHelpers.getField(localeData, "perMill");
assertThat(perMillValue).isEqualTo('‰');
}
代码示例来源:origin: robolectric/robolectric
@Implementation
public void cancel() {
directlyOn(realObject, RenderNodeAnimator.class).cancel();
if (getApiLevel() <= LOLLIPOP) {
int state = ReflectionHelpers.getField(realObject, "mState");
if (state != STATE_FINISHED) {
// In 21, RenderNodeAnimator only calls nEnd, it doesn't call the Java end method. Thus, it
// expects the native code will end up calling onFinished, so we do that here.
directlyOn(realObject, RenderNodeAnimator.class, "onFinished");
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getFieldReflectively_getsPrivateFields() {
ExampleDescendant example = new ExampleDescendant();
example.overridden = 5;
assertThat((int) ReflectionHelpers.getField(example, "overridden")).isEqualTo(5);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getFieldReflectively_getsInheritedFields() {
ExampleDescendant example = new ExampleDescendant();
example.setNotOverridden(6);
assertThat((int) ReflectionHelpers.getField(example, "notOverridden")).isEqualTo(6);
}
代码示例来源:origin: robolectric/robolectric
public static WindowId getWindowId(ShadowView shadowView) {
if (shadowView.isAttachedToWindow()) {
Object attachInfo = shadowView.getAttachInfo();
if (getField(attachInfo, "mWindowId") == null) {
IWindowId iWindowId = new MyIWindowIdStub();
reflector(_AttachInfo_.class, attachInfo).setWindowId(new WindowId(iWindowId));
reflector(_AttachInfo_.class, attachInfo).setIWindowId(iWindowId);
}
}
return shadowView.directly().getWindowId();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reset_clearsStatementCache() {
final Map<Long, SQLiteStatement> statementsMap = ReflectionHelpers.getField(CONNECTIONS, "statementsMap");
assertThat(statementsMap).named("statements before").isNotEmpty();
ShadowSQLiteConnection.reset();
assertThat(statementsMap).named("statements after").isEmpty();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reset_clearsConnectionCache() {
final Map<Long, SQLiteConnection> connectionsMap = ReflectionHelpers.getField(CONNECTIONS, "connectionsMap");
assertThat(connectionsMap).named("connections before").isNotEmpty();
ShadowSQLiteConnection.reset();
assertThat(connectionsMap).named("connections after").isEmpty();
}
内容来源于网络,如有侵权,请联系作者删除!