@ 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 ) ; }
Creates a mock object and populates its fields .