code: @SuppressWarnings("unchecked") // types must agree
    public static <T> T createMockObject(Type type) {
      Class<T> rawType;
  
      if (type instanceof ParameterizedType) {
        rawType = (Class<T>) ((ParameterizedType) type).getRawType();
      } else if (type instanceof Class) {
        rawType = (Class<T>) type;
      } else {
        throw new UnsupportedOperationException("Unsupported type: "
            + type.getClass().getSimpleName());
      }
      T instance = instantiateObject(rawType);
  
      return populateObject(instance);
    }
docs: Creates a mock object and populates its fields.
  
  @param type Type of mock object
  @param <T>  Type of mock object
  @return Mock Object of type T