下面列出了怎么用org.junit.jupiter.api.Nested的API类实例代码及写法,或者点击链接到github查看源代码。
private int getDockerBrowserCount() {
int count = 0;
if (context != null) {
Optional<Class<?>> testClass = context.getTestClass();
if (testClass.isPresent()) {
Class<?> tClass = testClass.get();
count = getCountForClass(count, tClass);
while (tClass.isAnnotationPresent(Nested.class)) {
try {
String tClassName = tClass.getName();
String parentClass = tClassName.substring(0, tClassName.lastIndexOf('$'));
log.trace("{} is Nested, adding count from parent class {}", tClassName, parentClass);
tClass = tClass.getClassLoader().loadClass(parentClass);
count += getCountForClass(count, tClass);
} catch (ClassNotFoundException e) {
log.trace("Error while loading parent class", e);
}
}
}
} else {
// Interactive mode
count = 1;
}
log.trace("Number of required Docker browser(s): {}", count);
return count;
}
private CreateBrowsersUsing getClassLevelAnnotation(Field field) {
Class<?> testClass = field.getDeclaringClass();
CreateBrowsersUsing isPresent = testClass.getAnnotation(CreateBrowsersUsing.class);
if (isPresent == null && testClass.isAnnotationPresent(Nested.class)) {
Class<?> declaringClass = testClass.getDeclaringClass();
while (declaringClass != null && isPresent == null) {
isPresent = declaringClass.getAnnotation(CreateBrowsersUsing.class);
declaringClass = declaringClass.getDeclaringClass();
}
}
return isPresent;
}