Skip to content

Commit 6db5a0d

Browse files
committed
Extract methods to improve readability
1 parent f5137fb commit 6db5a0d

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

junit-platform-suite-commons/src/main/java/org/junit/platform/suite/commons/SuiteLauncherDiscoveryRequestBuilder.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,7 @@ private MethodSelector selectMethod(Class<?> suiteClass, SelectMethod annotation
457457

458458
private MethodSelector toMethodSelector(Class<?> suiteClass, SelectMethod annotation) {
459459
if (!annotation.value().isEmpty()) {
460-
Preconditions.condition(annotation.type() == Class.class,
461-
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
462-
"type must not be set in conjunction with fully qualified method name"));
463-
Preconditions.condition(annotation.typeName().isEmpty(),
464-
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
465-
"type name must not be set in conjunction with fully qualified method name"));
466-
Preconditions.condition(annotation.name().isEmpty(),
467-
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
468-
"method name must not be set in conjunction with fully qualified method name"));
469-
Preconditions.condition(annotation.parameterTypes().length == 0,
470-
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
471-
"parameter types must not be set in conjunction with fully qualified method name"));
472-
Preconditions.condition(annotation.parameterTypeNames().isEmpty(),
473-
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
474-
"parameter type names must not be set in conjunction with fully qualified method name"));
475-
476-
return DiscoverySelectors.selectMethod(annotation.value());
460+
return toMethodSelectorFromFQMN(suiteClass, annotation);
477461
}
478462

479463
Class<?> type = annotation.type() == Class.class ? null : annotation.type();
@@ -487,25 +471,44 @@ private MethodSelector toMethodSelector(Class<?> suiteClass, SelectMethod annota
487471
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
488472
"either parameter type names or parameter types must be set but not both"));
489473
}
474+
return toMethodSelector(suiteClass, type, typeName, parameterTypes, methodName, parameterTypeNames);
475+
}
476+
477+
private static MethodSelector toMethodSelectorFromFQMN(Class<?> suiteClass, SelectMethod annotation) {
478+
Preconditions.condition(annotation.type() == Class.class,
479+
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
480+
"type must not be set in conjunction with fully qualified method name"));
481+
Preconditions.condition(annotation.typeName().isEmpty(),
482+
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
483+
"type name must not be set in conjunction with fully qualified method name"));
484+
Preconditions.condition(annotation.name().isEmpty(),
485+
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
486+
"method name must not be set in conjunction with fully qualified method name"));
487+
Preconditions.condition(annotation.parameterTypes().length == 0,
488+
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
489+
"parameter types must not be set in conjunction with fully qualified method name"));
490+
Preconditions.condition(annotation.parameterTypeNames().isEmpty(),
491+
() -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
492+
"parameter type names must not be set in conjunction with fully qualified method name"));
493+
494+
return DiscoverySelectors.selectMethod(annotation.value());
495+
}
496+
497+
private static MethodSelector toMethodSelector(Class<?> suiteClass, Class<?> type, String typeName,
498+
Class<?>[] parameterTypes, String methodName, String parameterTypeNames) {
490499
if (type == null) {
491500
Preconditions.notBlank(typeName, () -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
492501
"type must be set or type name must not be blank"));
493-
if (parameterTypes == null) {
494-
return DiscoverySelectors.selectMethod(typeName, methodName, parameterTypeNames);
495-
}
496-
else {
497-
return DiscoverySelectors.selectMethod(typeName, methodName, parameterTypes);
498-
}
502+
return parameterTypes == null //
503+
? DiscoverySelectors.selectMethod(typeName, methodName, parameterTypeNames) //
504+
: DiscoverySelectors.selectMethod(typeName, methodName, parameterTypes);
499505
}
500506
else {
501507
Preconditions.condition(typeName == null, () -> prefixErrorMessageForInvalidSelectMethodUsage(suiteClass,
502508
"either type name or type must be set but not both"));
503-
if (parameterTypes == null) {
504-
return DiscoverySelectors.selectMethod(type, methodName, parameterTypeNames);
505-
}
506-
else {
507-
return DiscoverySelectors.selectMethod(type, methodName, parameterTypes);
508-
}
509+
return parameterTypes == null //
510+
? DiscoverySelectors.selectMethod(type, methodName, parameterTypeNames) //
511+
: DiscoverySelectors.selectMethod(type, methodName, parameterTypes);
509512
}
510513
}
511514

0 commit comments

Comments
 (0)