MethodBasedTestDescriptor(UniqueId uniqueId, String displayName, Class<?> testClass, Method testMethod, JupiterConfiguration configuration) { super(uniqueId, displayName, MethodSource.from(testClass, testMethod), configuration); this.testClass = Preconditions.notNull(testClass, "Class must not be null"); this.testMethod = testMethod; this.tags = getTags(testMethod); }
private boolean shouldRun( MethodSource source ) { String testClass = TestListResolver.toClassFileName( source.getClassName() ); String testMethod = source.getMethodName(); return this.testListResolver.shouldRun( testClass, testMethod ); } }
private String getTechnicalName(TestIdentifier testIdentifier) { Optional<TestSource> optionalSource = testIdentifier.getSource(); if (optionalSource.isPresent()) { TestSource source = optionalSource.get(); if (source instanceof ClassSource) { return ((ClassSource) source).getJavaClass().getName(); } else if (source instanceof MethodSource) { MethodSource methodSource = (MethodSource) source; String methodParameterTypes = methodSource.getMethodParameterTypes(); if (StringUtils.isBlank(methodParameterTypes)) { return methodSource.getMethodName(); } return String.format("%s(%s)", methodSource.getMethodName(), methodParameterTypes); } } // Else fall back to display name return testIdentifier.getDisplayName(); }
private static String getTestCaseName(TestIdentifier description) { try { TestSource testSource = description.getSource().get(); if (testSource instanceof MethodSource) { return ((MethodSource) testSource).getClassName(); } return description.getDisplayName().split("\\(|\\)")[1]; } catch (Exception e) { return description.getDisplayName(); } }
private String getMethodName(TestIdentifier description) { try { TestSource testSource = description.getSource().get(); if (testSource instanceof MethodSource) { return ((MethodSource) testSource).getMethodName(); } return description.getDisplayName().split("\\(|\\)")[0]; } catch (Exception e) { return description.getDisplayName(); } }
/** * Create a new {@code MethodSource} using the supplied class name and * method name. * * @param className the class name; must not be {@code null} or blank * @param methodName the method name; must not be {@code null} or blank */ public static MethodSource from(String className, String methodName) { return new MethodSource(className, methodName); }
String realClassName = methodSource.getClassName(); .orElse( new String[] { realClassName, realClassName } ); String methodName = methodSource.getMethodName(); boolean useMethod = display.equals( methodName ) || display.equals( methodName + "()" ); String resolvedMethodName = useMethod ? methodName : display;
/** * Creates a new {@link AbstractBenchmarkDescriptor} given {@link UniqueId}, {@code displayName} and a {@link TestSource}. * * @param uniqueId the {@link UniqueId} for this descriptor. * @param displayName * @param source source this descriptor. */ public AbstractBenchmarkDescriptor(UniqueId uniqueId, String displayName, TestSource source) { super(uniqueId, displayName, source); Set<TestTag> tags = Collections.emptySet(); if (source instanceof ClassSource) { tags = DescriptorUtils.getTags(((ClassSource) source).getJavaClass()); } if (source instanceof MethodSource) { try { tags = DescriptorUtils.getTags(Class.forName(((MethodSource) source).getClassName())); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } } this.tags = tags; }
/** * Create a new {@code MethodSource} using the supplied class name, method * name, and method parameter types. * * @param className the class name; must not be {@code null} or blank * @param methodName the method name; must not be {@code null} or blank * @param methodParameterTypes the method parameter types as a string */ public static MethodSource from(String className, String methodName, String methodParameterTypes) { return new MethodSource(className, methodName, methodParameterTypes); }
private static MethodSource toMethodSource(Class<?> testClass, String methodName) { if (methodName.contains("[") && methodName.endsWith("]")) { // special case for parameterized tests return toMethodSource(testClass, methodName.substring(0, methodName.indexOf("["))); } else { List<Method> methods = findMethods(testClass, where(Method::getName, isEqual(methodName))); return (methods.size() == 1) ? MethodSource.from(testClass, getOnlyElement(methods)) : null; } }
/** * Create a new {@code MethodSource} using the supplied {@link Method method}. * * @param testMethod the Java method; must not be {@code null} * @see #from(Class, Method) */ public static MethodSource from(Method testMethod) { return new MethodSource(testMethod); }
public BenchmarkMethodDescriptor(UniqueId uniqueId, BenchmarkMethod method) { super(uniqueId, generateDefaultDisplayName(method), MethodSource.from(method.getDeclaringClass(), method.getMethod())); this.method = method; }
/** * Create a new {@code MethodSource} using the supplied * {@link Class class} and {@link Method method}. * * <p>This method should be used in favor of {@link #from(Method)} if the * test method is inherited from a superclass or present as an interface * {@code default} method. * * @param testClass the Java class; must not be {@code null} * @param testMethod the Java method; must not be {@code null} * @since 1.3 */ @API(status = STABLE, since = "1.3") public static MethodSource from(Class<?> testClass, Method testMethod) { return new MethodSource(testClass, testMethod); }
private ParametrizedBenchmarkMethodDescriptor(UniqueId uniqueId, BenchmarkMethod benchmarkMethod, ParametrizedBenchmarkMethod parametrizedMethod) { super(uniqueId, generateDefaultDisplayName(benchmarkMethod.getMethod()), MethodSource.from(benchmarkMethod.getDeclaringClass(), benchmarkMethod.getMethod())); this.method = benchmarkMethod; this.parametrizedMethod = parametrizedMethod; }
public BenchmarkFixtureDescriptor(UniqueId uniqueId, BenchmarkMethod method, BenchmarkFixture fixture) { super(uniqueId, fixture.getDisplayName(), MethodSource.from(method.getMethod())); this.fixture = fixture; this.tags = DescriptorUtils.getTags(method.getDeclaringClass()); }