下面列出了怎么用org.junit.platform.commons.support.HierarchyTraversalMode的API类实例代码及写法,或者点击链接到github查看源代码。
private MicroProfileApplication<?> autoDiscoverMPApp(Class<?> clazz, boolean errorIfNone) {
// First check for any MicroProfileApplicaiton directly present on the test class
List<Field> mpApps = AnnotationSupport.findAnnotatedFields(clazz, Container.class,
f -> Modifier.isStatic(f.getModifiers()) &&
Modifier.isPublic(f.getModifiers()) &&
MicroProfileApplication.class.isAssignableFrom(f.getType()),
HierarchyTraversalMode.TOP_DOWN);
if (mpApps.size() == 1)
try {
return (MicroProfileApplication<?>) mpApps.get(0).get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
// This should never happen because we only look for fields that are public+static
e.printStackTrace();
}
if (mpApps.size() > 1)
throw new ExtensionConfigurationException("Should be no more than 1 public static MicroProfileApplication field on " + clazz);
// If none found, check any SharedContainerConfig
String sharedConfigMsg = "";
if (sharedConfigClass != null) {
MicroProfileApplication<?> mpApp = autoDiscoverMPApp(sharedConfigClass, false);
if (mpApp != null)
return mpApp;
sharedConfigMsg = " or " + sharedConfigClass;
}
if (errorIfNone)
throw new ExtensionConfigurationException("No public static MicroProfileApplication fields annotated with @Container were located " +
"on " + clazz + sharedConfigMsg + " to auto-connect with REST-client fields.");
return null;
}