junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ExecutableInvoker.java
raw symbols SCIP| 1 | /* |
| 2 | * Copyright 2015-2024 the original author or authors. |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | * accompanies this distribution and is available at |
| 7 | * |
| 8 | * https://www.eclipse.org/legal/epl-v20.html |
| 9 | */ |
| 10 | |
| 11 | package org.junit.jupiter.api.extension; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.EXPERIMENTAL; |
| 14 | |
| 15 | import java.lang.reflect.Constructor; |
| 16 | import java.lang.reflect.Method; |
| 17 | |
| 18 | import org.apiguardian.api.API; |
| 19 | |
| 20 | /** |
| 21 | * {@code ExecutableInvoker} allows invoking methods and constructors |
| 22 | * with support for dynamic resolution of parameters via |
| 23 | * {@link ParameterResolver ParameterResolvers}. |
| 24 | * |
| 25 | * @since 5.9 |
| 26 | */ |
| 27 | @API(status = EXPERIMENTAL, since = "5.9") |
| 28 | public interface ExecutableInvoker { |
| 29 | |
| 30 | /** |
| 31 | * Invoke the supplied {@code static} method with dynamic parameter resolution. |
| 32 | * |
| 33 | * @param method the method to invoke and resolve parameters for |
| 34 | * @see #invoke(Method, Object) |
| 35 | */ |
| 36 | default Object invoke(Method method) { |
| 37 | return invoke(method, null); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Invoke the supplied method with dynamic parameter resolution. |
| 42 | * |
| 43 | * @param method the method to invoke and resolve parameters for |
| 44 | * @param target the target on which the executable will be invoked; |
| 45 | * can be {@code null} for {@code static} methods |
| 46 | */ |
| 47 | Object invoke(Method method, Object target); |
| 48 | |
| 49 | /** |
| 50 | * Invoke the supplied top-level constructor with dynamic parameter resolution. |
| 51 | * |
| 52 | * @param constructor the constructor to invoke and resolve parameters for |
| 53 | * @see #invoke(Constructor, Object) |
| 54 | */ |
| 55 | default <T> T invoke(Constructor<T> constructor) { |
| 56 | return invoke(constructor, null); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Invoke the supplied constructor with the supplied outer instance and |
| 61 | * dynamic parameter resolution. |
| 62 | * |
| 63 | * <p>Use this method when invoking the constructor for an <em>inner</em> class. |
| 64 | * |
| 65 | * @param constructor the constructor to invoke and resolve parameters for |
| 66 | * @param outerInstance the outer instance to supply as the first argument |
| 67 | * to the constructor; must be {@code null} for top-level classes |
| 68 | * or {@code static} nested classes |
| 69 | */ |
| 70 | <T> T invoke(Constructor<T> constructor, Object outerInstance); |
| 71 | |
| 72 | } |