Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-simons/6ba6efd80bfab124ff9f48a465429607 to your computer and use it in GitHub Desktop.
Save michael-simons/6ba6efd80bfab124ff9f48a465429607 to your computer and use it in GitHub Desktop.
import java.lang.reflect.Method;
import java.util.stream.Collectors;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Tag;
import org.junit.platform.commons.util.AnnotationUtils;
final class SimpleDisplayNameGeneratorWithTags extends DisplayNameGenerator.Simple {
@Override
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {
var displayNameForMethod = super.generateDisplayNameForMethod(testClass, testMethod);
var tags = AnnotationUtils.findRepeatableAnnotations(testMethod, Tag.class);
if (tags.isEmpty()) {
return displayNameForMethod;
}
return tags.stream().map(Tag::value).collect(Collectors.joining(", ", "", ": " + displayNameForMethod));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment