Apache9 commented on code in PR #7615: URL: https://github.com/apache/hbase/pull/7615#discussion_r2681175932
########## hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseParameterizedTemplateProvider.java: ########## @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.stream.Stream; +import org.apache.yetus.audience.InterfaceAudience; +import org.junit.jupiter.api.extension.ExtensionConfigurationException; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; +import org.junit.jupiter.params.provider.Arguments; + +/** + * The entry point class for supporting JUnit4 like Parameterized test, where we can use constructor + * to pass parameters. + * <p> + * JUnit5's {@link org.junit.jupiter.params.ParameterizedClass} will create separated test classes, + * which is different with JUnit4 and {@link org.junit.jupiter.params.ParameterizedTest} does not + * support passing parameters through constructors. + * <p> + * When you want to use this provider, annotation the test class with + * {@link HBaseParameterizedTestTemplate}, and provide a static method named "parameters" for + * providing the arguments. All the test method should be marked with + * {@link org.junit.jupiter.api.TestTemplate}, not {@link org.junit.jupiter.api.Test} or + * {@link org.junit.jupiter.params.ParameterizedTest} + * @see HBaseParameterizedTestTemplate + * @see HBaseParameterizedInvocationContext + * @see HBaseParameterizedParameterResolver + */ [email protected] +public class HBaseParameterizedTemplateProvider implements TestTemplateInvocationContextProvider { + + @Override + public boolean supportsTestTemplate(ExtensionContext context) { + return context.getTestClass() + .map(c -> c.isAnnotationPresent(HBaseParameterizedTestTemplate.class)).orElse(false); + } + + @Override + public Stream<TestTemplateInvocationContext> + provideTestTemplateInvocationContexts(ExtensionContext context) { + Class<?> testClass = context.getRequiredTestClass(); + // get parameters + Method method; + try { + method = testClass.getDeclaredMethod("parameters"); Review Comment: For now I think a hard coded method name is enough for our usage in HBase. In JUnit5, we need to use `@MethodSource("<method_name>")` to reference the method, which does not have compile time check either... We can improve this later. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
