use of com.google.copybara.doc.annotations.Example in project copybara by google.
the class ExamplesTest method testExamples.
@Test
public void testExamples() {
SkylarkTestExecutor executor = getExecutor();
ImmutableList.Builder<Result> resBuilder = ImmutableList.builder();
for (Class<?> module : executor.getModules()) {
for (Method method : module.getMethods()) {
Examples examples = method.getAnnotation(Examples.class);
ImmutableList<Example> samples;
if (examples == null) {
Example singleSample = method.getAnnotation(Example.class);
if (singleSample != null) {
samples = ImmutableList.of(singleSample);
} else {
continue;
}
} else {
samples = ImmutableList.copyOf(examples.value());
}
resBuilder.addAll(checkExamples(executor, module, samples, method.getName()));
}
}
ImmutableList<Result> result = resBuilder.build();
// Normally we won't remove examples or modules. This checks that we don't go down. This
// is the number of modules in Apr 2019. We can update this from time to time. It is not
// critical to have an accurate number, but that we don't lose at least these.
assertWithMessage("Less examples than expected").that(result.size()).isAtLeast(48);
Set<? extends Class<?>> modules = result.stream().map(e -> e.cls).collect(Collectors.toSet());
assertWithMessage("Less classes than expected: " + modules).that(modules.size()).isAtLeast(5);
List<Result> errors = result.stream().filter(Result::isError).collect(Collectors.toList());
assertWithMessage("Errors in examples(" + errors.size() + "):\n\n" + Joiner.on("\n-----------------------------\n").join(errors)).that(errors).isEmpty();
}
Aggregations