interop-testing: Improve ChannelAndServerBuilderTest readability (#10641)

Add javadoc and code readability refactoring
This commit is contained in:
Sergii Tkachenko 2023-11-02 10:06:40 -07:00 committed by GitHub
parent 84ddcb04e0
commit 302f756449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 7 deletions

View File

@ -19,6 +19,7 @@ package io.grpc;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import com.google.common.reflect.ClassPath.ClassInfo;
import com.google.common.truth.Truth;
@ -46,17 +47,28 @@ public class ChannelAndServerBuilderTest {
public Class<?> builderClass;
/**
* Javadoc.
* Returns the list of classes that have ServerBuilder or ManagedChannelBuilder in their class
* hierarchy and need to be checked for proper overrides of the static constructors.
*/
@Parameters(name = "class={0}")
public static Collection<Object[]> params() throws Exception {
ClassLoader loader = ChannelAndServerBuilderTest.class.getClassLoader();
Collection<ClassInfo> classInfos =
ImmutableSet<ClassInfo> classInfos =
ClassPath.from(loader).getTopLevelClassesRecursive("io.grpc");
// Java 9 doesn't expose the URLClassLoader, which breaks searching through the classpath
if (classInfos.isEmpty()) {
return new ArrayList<>();
}
// Exceptions from the check classes themselves, and ForwardingChannelBuilder.
// ForwardingChannelBuilder is deprecated and was stripped off of unnecessary methods,
// which it inherits from ForwardingChannelBuilder2.
ImmutableSet<Class<?>> ignoreClasses = ImmutableSet.of(
ServerBuilder.class,
ManagedChannelBuilder.class,
ForwardingChannelBuilder.class);
List<Object[]> classes = new ArrayList<>();
for (ClassInfo classInfo : classInfos) {
String className = classInfo.getName();
@ -64,13 +76,11 @@ public class ChannelAndServerBuilderTest {
continue;
}
Class<?> clazz = Class.forName(className, false /*initialize*/, loader);
if (ServerBuilder.class.isAssignableFrom(clazz) && clazz != ServerBuilder.class) {
classes.add(new Object[]{clazz});
if (ignoreClasses.contains(clazz)) {
continue;
}
// ForwardingChannelBuilder extends ForwardingChannelBuilder2, not need for extra checks.
if (ManagedChannelBuilder.class.isAssignableFrom(clazz)
&& clazz != ManagedChannelBuilder.class && clazz != ForwardingChannelBuilder.class) {
if (ServerBuilder.class.isAssignableFrom(clazz)
|| ManagedChannelBuilder.class.isAssignableFrom(clazz)) {
classes.add(new Object[]{clazz});
}
}