|
| 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.platform.launcher; |
| 12 | + |
| 13 | +import static org.apiguardian.api.API.Status.EXPERIMENTAL; |
| 14 | + |
| 15 | +import java.lang.reflect.Method; |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import org.apiguardian.api.API; |
| 19 | + |
| 20 | +/** |
| 21 | + * {@link PostDiscoveryFilter} that is applied to the fully qualified |
| 22 | + * {@link Method} name without parameters. |
| 23 | + * |
| 24 | + * @since 1.12 |
| 25 | + * @see #includeMethodNamePatterns(String...) |
| 26 | + * @see #excludeMethodNamePatterns(String...) |
| 27 | + */ |
| 28 | +@API(status = EXPERIMENTAL, since = "1.12") |
| 29 | +public interface MethodFilter extends PostDiscoveryFilter { |
| 30 | + |
| 31 | + /** |
| 32 | + * Create a new <em>include</em> {@link MethodFilter} based on the |
| 33 | + * supplied patterns. |
| 34 | + * |
| 35 | + * <p>The patterns are combined using OR semantics, i.e. if the fully |
| 36 | + * qualified name of a method matches against at least one of the patterns, |
| 37 | + * the method will be included in the result set. |
| 38 | + * |
| 39 | + * @param patterns regular expressions to match against fully qualified |
| 40 | + * method names; never {@code null}, empty, or containing {@code null} |
| 41 | + * @see Class#getName() |
| 42 | + * @see Method#getName() |
| 43 | + * @see #includeMethodNamePatterns(List) |
| 44 | + * @see #excludeMethodNamePatterns(String...) |
| 45 | + */ |
| 46 | + static MethodFilter includeMethodNamePatterns(String... patterns) { |
| 47 | + return new IncludeMethodFilter(patterns); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Create a new <em>include</em> {@link MethodFilter} based on the |
| 52 | + * supplied patterns. |
| 53 | + * |
| 54 | + * <p>The patterns are combined using OR semantics, i.e. if the fully |
| 55 | + * qualified name of a method matches against at least one of the patterns, |
| 56 | + * the method will be included in the result set. |
| 57 | + * |
| 58 | + * @param patterns regular expressions to match against fully qualified |
| 59 | + * method names; never {@code null}, empty, or containing {@code null} |
| 60 | + * @see Class#getName() |
| 61 | + * @see Method#getName() |
| 62 | + * @see #includeMethodNamePatterns(String...) |
| 63 | + * @see #excludeMethodNamePatterns(String...) |
| 64 | + */ |
| 65 | + static MethodFilter includeMethodNamePatterns(List<String> patterns) { |
| 66 | + return includeMethodNamePatterns(patterns.toArray(new String[0])); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Create a new <em>exclude</em> {@link MethodFilter} based on the |
| 71 | + * supplied patterns. |
| 72 | + * |
| 73 | + * <p>The patterns are combined using OR semantics, i.e. if the fully |
| 74 | + * qualified name of a method matches against at least one of the patterns, |
| 75 | + * the method will be excluded from the result set. |
| 76 | + * |
| 77 | + * @param patterns regular expressions to match against fully qualified |
| 78 | + * method names; never {@code null}, empty, or containing {@code null} |
| 79 | + * @see Class#getName() |
| 80 | + * @see Method#getName() |
| 81 | + * @see #excludeMethodNamePatterns(List) |
| 82 | + * @see #includeMethodNamePatterns(String...) |
| 83 | + */ |
| 84 | + static MethodFilter excludeMethodNamePatterns(String... patterns) { |
| 85 | + return new ExcludeMethodFilter(patterns); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Create a new <em>exclude</em> {@link MethodFilter} based on the |
| 90 | + * supplied patterns. |
| 91 | + * |
| 92 | + * <p>The patterns are combined using OR semantics, i.e. if the fully |
| 93 | + * qualified name of a method matches against at least one of the patterns, |
| 94 | + * the method will be excluded from the result set. |
| 95 | + * |
| 96 | + * @param patterns regular expressions to match against fully qualified |
| 97 | + * method names; never {@code null}, empty, or containing {@code null} |
| 98 | + * @see Class#getName() |
| 99 | + * @see Method#getName() |
| 100 | + * @see #excludeMethodNamePatterns(String...) |
| 101 | + * @see #includeMethodNamePatterns(String...) |
| 102 | + */ |
| 103 | + static MethodFilter excludeMethodNamePatterns(List<String> patterns) { |
| 104 | + return excludeMethodNamePatterns(patterns.toArray(new String[0])); |
| 105 | + } |
| 106 | + |
| 107 | +} |
0 commit comments