Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2015-2018 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.jupiter.engine.execution;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static org.apiguardian.api.API.Status.INTERNAL;
import static org.junit.platform.commons.util.ReflectionUtils.isAssignableTo;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.List;
import java.util.Optional;
import org.apiguardian.api.API;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.engine.extension.ExtensionRegistry;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
import org.junit.platform.commons.util.Preconditions;
import org.junit.platform.commons.util.ReflectionUtils;
/**
* {@code ExecutableInvoker} encapsulates the invocation of a
* {@link java.lang.reflect.Executable} (i.e., method or constructor),
* including support for dynamic resolution of method parameters via
* {@link ParameterResolver ParameterResolvers}.
*
* @since 5.0
*/
@API(status = INTERNAL, since = "5.0")
public class ExecutableInvoker {
private static final Logger logger = LoggerFactory.getLogger(ExecutableInvoker.class);
/**
* Invoke the supplied constructor with dynamic parameter resolution.
*
* @param constructor the constructor to invoke and resolve parameters for
* @param extensionContext the current {@code ExtensionContext}
* @param extensionRegistry the {@code ExtensionRegistry} to retrieve
* {@code ParameterResolvers} from
*/
public T invoke(Constructor constructor, ExtensionContext extensionContext,
ExtensionRegistry extensionRegistry) {
return ReflectionUtils.newInstance(constructor,
resolveParameters(constructor, Optional.empty(), extensionContext, extensionRegistry));
}
/**
* Invoke the supplied constructor with the supplied outer instance and
* dynamic parameter resolution.
*
*
This method should only be used to invoke the constructor for
* an inner class.
*
* @param constructor the constructor to invoke and resolve parameters for
* @param outerInstance the outer instance to supply as the first argument
* to the constructor
* @param extensionContext the current {@code ExtensionContext}
* @param extensionRegistry the {@code ExtensionRegistry} to retrieve
* {@code ParameterResolvers} from
*/
public T invoke(Constructor constructor, Object outerInstance, ExtensionContext extensionContext,
ExtensionRegistry extensionRegistry) {
return ReflectionUtils.newInstance(constructor,
resolveParameters(constructor, Optional.empty(), outerInstance, extensionContext, extensionRegistry));
}
/**
* Invoke the supplied {@code static} method with dynamic parameter resolution.
*
* @param method the method to invoke and resolve parameters for
* @param extensionContext the current {@code ExtensionContext}
* @param extensionRegistry the {@code ExtensionRegistry} to retrieve
* {@code ParameterResolvers} from
*/
public Object invoke(Method method, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) {
return ReflectionUtils.invokeMethod(method, null,
resolveParameters(method, Optional.empty(), extensionContext, extensionRegistry));
}
/**
* Invoke the supplied method on the supplied target object with dynamic parameter
* resolution.
*
* @param method the method to invoke and resolve parameters for
* @param target the object on which the method will be invoked; should be
* {@code null} for static methods
* @param extensionContext the current {@code ExtensionContext}
* @param extensionRegistry the {@code ExtensionRegistry} to retrieve
* {@code ParameterResolvers} from
*/
public Object invoke(Method method, Object target, ExtensionContext extensionContext,
ExtensionRegistry extensionRegistry) {
@SuppressWarnings("unchecked")
Optional