use of java.lang.reflect.Field in project storio by pushtorefresh.
the class DefaultStorIOContentResolverTest method getTypeMappingFinder.
@Nullable
private static TypeMappingFinder getTypeMappingFinder(@NonNull DefaultStorIOContentResolver storIOContentResolver) throws NoSuchFieldException, IllegalAccessException {
Field field = DefaultStorIOContentResolver.LowLevelImpl.class.getDeclaredField("typeMappingFinder");
field.setAccessible(true);
return (TypeMappingFinder) field.get(storIOContentResolver.lowLevel());
}
use of java.lang.reflect.Field in project storio by pushtorefresh.
the class EnvironmentTest method shouldThrowExceptionIfRxJavaIsNotInTheClassPath.
@Test
public void shouldThrowExceptionIfRxJavaIsNotInTheClassPath() throws NoSuchFieldException, IllegalAccessException {
Field field = Environment.class.getDeclaredField("RX_JAVA_IS_IN_THE_CLASS_PATH");
field.setAccessible(true);
// Removing FINAL modifier
Field modifiersFieldOfTheField = Field.class.getDeclaredField("modifiers");
modifiersFieldOfTheField.setAccessible(true);
modifiersFieldOfTheField.setInt(field, field.getModifiers() & ~FINAL);
final Object prevValue = field.get(null);
// No Environment will think that RxJava is not in the ClassPath
field.set(null, false);
try {
Environment.throwExceptionIfRxJavaIsNotAvailable("yolo");
failBecauseExceptionWasNotThrown(IllegalStateException.class);
} catch (IllegalStateException expected) {
assertThat(expected).hasMessage("yolo requires RxJava in classpath," + " please add it as compile dependency to the application");
} finally {
// Return previous value of the field
field.set(null, prevValue);
// Restoring FINAL modifier (for better tests performance)
modifiersFieldOfTheField.setInt(field, field.getModifiers() & FINAL);
}
}
use of java.lang.reflect.Field in project storio by pushtorefresh.
the class ToStringChecker method writeSampleValuesToFields.
private void writeSampleValuesToFields(@NonNull T object, @NonNull List<Field> fields) {
for (Field field : fields) {
field.setAccessible(true);
writeSampleValueToField(object, field);
}
}
use of java.lang.reflect.Field in project storio by pushtorefresh.
the class Utils method getMaxSdkVersion.
private static int getMaxSdkVersion() {
final Field[] versionCodesFields = Build.VERSION_CODES.class.getDeclaredFields();
// At least 23
int maxSdkVersion = 23;
for (final Field versionCodeField : versionCodesFields) {
versionCodeField.setAccessible(true);
try {
final Class<?> fieldType = versionCodeField.getType();
if (fieldType.equals(Integer.class)) {
int sdkVersion = (Integer) versionCodeField.get(null);
maxSdkVersion = Math.max(maxSdkVersion, sdkVersion);
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return maxSdkVersion;
}
use of java.lang.reflect.Field in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method setChangesBus.
private static void setChangesBus(@NonNull DefaultStorIOSQLite storIOSQLite, @NonNull ChangesBus<Changes> changesBus) throws NoSuchFieldException, IllegalAccessException {
Field field = DefaultStorIOSQLite.class.getDeclaredField("changesBus");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
//noinspection unchecked
field.set(storIOSQLite, changesBus);
}
Aggregations