Search in sources :

Example 81 with Field

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());
}
Also used : Field(java.lang.reflect.Field) TypeMappingFinder(com.pushtorefresh.storio.TypeMappingFinder) Nullable(android.support.annotation.Nullable)

Example 82 with Field

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);
    }
}
Also used : Field(java.lang.reflect.Field) Test(org.junit.Test)

Example 83 with Field

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);
    }
}
Also used : Field(java.lang.reflect.Field)

Example 84 with 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;
}
Also used : Field(java.lang.reflect.Field) Build(android.os.Build)

Example 85 with Field

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);
}
Also used : Field(java.lang.reflect.Field)

Aggregations

Field (java.lang.reflect.Field)5144 Method (java.lang.reflect.Method)613 Test (org.junit.Test)538 ArrayList (java.util.ArrayList)490 IOException (java.io.IOException)318 HashMap (java.util.HashMap)318 Map (java.util.Map)296 InvocationTargetException (java.lang.reflect.InvocationTargetException)176 List (java.util.List)171 Pattern (java.util.regex.Pattern)122 Matcher (java.util.regex.Matcher)117 HashSet (java.util.HashSet)109 File (java.io.File)107 Annotation (java.lang.annotation.Annotation)98 Support_Field (tests.support.Support_Field)82 Collection (java.util.Collection)81 Test (org.testng.annotations.Test)68 Type (java.lang.reflect.Type)67 SienaException (siena.SienaException)65 Before (org.junit.Before)62