30
30
import org .junit .jupiter .api .DisplayNameGenerator .Simple ;
31
31
import org .junit .jupiter .api .DisplayNameGenerator .Standard ;
32
32
import org .junit .jupiter .engine .config .JupiterConfiguration ;
33
- import org .junit .platform .commons .logging .Logger ;
34
- import org .junit .platform .commons .logging .LoggerFactory ;
35
33
import org .junit .platform .commons .support .ReflectionSupport ;
36
34
import org .junit .platform .commons .util .Preconditions ;
37
35
import org .junit .platform .commons .util .StringUtils ;
36
+ import org .junit .platform .engine .DiscoveryIssue ;
37
+ import org .junit .platform .engine .DiscoveryIssue .Severity ;
38
+ import org .junit .platform .engine .TestSource ;
39
+ import org .junit .platform .engine .support .discovery .DiscoveryIssueReporter ;
38
40
39
41
/**
40
42
* Collection of utilities for working with display names.
46
48
*/
47
49
final class DisplayNameUtils {
48
50
49
- private static final Logger logger = LoggerFactory .getLogger (DisplayNameUtils .class );
50
-
51
51
/**
52
52
* Pre-defined standard display name generator instance.
53
53
*/
@@ -74,22 +74,23 @@ final class DisplayNameUtils {
74
74
75
75
static String determineDisplayName (AnnotatedElement element , Supplier <String > displayNameSupplier ) {
76
76
Preconditions .notNull (element , "Annotated element must not be null" );
77
- Optional <DisplayName > displayNameAnnotation = findAnnotation (element , DisplayName .class );
78
- if (displayNameAnnotation .isPresent ()) {
79
- String displayName = displayNameAnnotation .get ().value ().trim ();
80
-
81
- // TODO [#242] Replace logging with precondition check once we have a proper mechanism for
82
- // handling validation exceptions during the TestEngine discovery phase.
83
- if (StringUtils .isBlank (displayName )) {
84
- logger .warn (() -> String .format (
85
- "Configuration error: @DisplayName on [%s] must be declared with a non-blank value." , element ));
86
- }
87
- else {
88
- return displayName ;
89
- }
90
- }
91
- // else let a 'DisplayNameGenerator' generate a display name
92
- return displayNameSupplier .get ();
77
+ return findAnnotation (element , DisplayName .class ) //
78
+ .map (DisplayName ::value ) //
79
+ .filter (StringUtils ::isNotBlank ) //
80
+ .orElseGet (displayNameSupplier );
81
+ }
82
+
83
+ static void validateAnnotation (AnnotatedElement element , Supplier <String > elementDescription ,
84
+ Supplier <TestSource > sourceProvider , DiscoveryIssueReporter reporter ) {
85
+ findAnnotation (element , DisplayName .class ) //
86
+ .map (DisplayName ::value ) //
87
+ .filter (StringUtils ::isBlank ) //
88
+ .ifPresent (__ -> {
89
+ String message = String .format ("@DisplayName on %s must be declared with a non-blank value." ,
90
+ elementDescription .get ());
91
+ reporter .reportIssue (
92
+ DiscoveryIssue .builder (Severity .WARNING , message ).source (sourceProvider .get ()).build ());
93
+ });
93
94
}
94
95
95
96
static String determineDisplayNameForMethod (Supplier <List <Class <?>>> enclosingInstanceTypes , Class <?> testClass ,
0 commit comments