private Object createInstanceUsingNeedleTestCase(final Class<?> type) throws IllegalStateException {
        try {
            Object instance = ReflectionUtil.invokeMethod(this, "getInstanceByConstructorInjection", type);
            if (instance == null) {
                instance = CreateInstanceByDefaultConstructor.INSTANCE.apply(type);
            }
            if (instance == null) {
                throw new IllegalStateException("failed to create instance of type " + type.getCanonicalName());
            }
            return instance;
        } catch (final Exception e) {
            throw new IllegalStateException(e);
        }

    }
private Object createInstanceUsingNeedleTestCase ( final Class < ? > type ) throws IllegalStateException { try { Object instance = ReflectionUtil . invokeMethod ( this , "getInstanceByConstructorInjection" , type ) ; if ( instance == null ) { instance = CreateInstanceByDefaultConstructor . INSTANCE . apply ( type ) ; } if ( instance == null ) { throw new IllegalStateException ( "failed to create instance of type " + type . getCanonicalName ( ) ) ; } return instance ; } catch ( final Exception e ) { throw new IllegalStateException ( e ) ; } }
Uses private instantiation methods of NeedleTestCase via {@link ReflectionUtil#invokeMethod(Object, String, Object...)}. First tries to create new
instance with constructor injection, then falls back to default constructor. If creation fails, an IllegalStateException is thrown.
@param type type of instance to create
@return new instance of type. Never <code>null</code>
@throws IllegalStateException when creation fails.