public static T getInternalState()

in hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Whitebox.java [61:84]


    public static <T> T getInternalState(Object target, String fieldName) {
        assert fieldName != null;
        int sep = fieldName.indexOf(SEPARATOR);
        if (sep > 0) {
            String field = fieldName.substring(0, sep);
            Object value = getInternalState(target, field);
            field = fieldName.substring(sep + 1);
            return getInternalState(value, field);
        }

        Class<?> c = target instanceof Class<?> ?
                     (Class<?>) target : target.getClass();
        try {
            Field f = getFieldFromHierarchy(c, fieldName);
            f.setAccessible(true);
            @SuppressWarnings("unchecked")
            T result = (T) f.get(target);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(String.format(
                      "Unable to get internal state on field '%s' of %s",
                      fieldName, target), e);
        }
    }