Skip to content

Commit 940d018

Browse files
committed
Enhance canConvert with inner converters evaluation
1 parent 0284786 commit 940d018

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/DefaultConversionService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,20 @@ private DefaultConversionService() {
7878
*/
7979
@Override
8080
public boolean canConvert(Object source, Class<?> targetType, ClassLoader classLoader) {
81-
return source instanceof String;
81+
if (source == null && targetType.isPrimitive()) {
82+
return false;
83+
}
84+
85+
if (!(source instanceof String)) {
86+
return false;
87+
}
88+
89+
if (String.class.equals(targetType)) {
90+
return true;
91+
}
92+
93+
return stringToObjectConverters.stream().anyMatch(
94+
candidate -> candidate.canConvertTo(toWrapperType(targetType)));
8295
}
8396

8497
/**
@@ -145,7 +158,6 @@ public Object convert(Object source, Class<?> targetType, ClassLoader classLoade
145158
return source;
146159
}
147160

148-
// FIXME move/copy next three lines to canConvert?
149161
Class<?> targetTypeToUse = toWrapperType(targetType);
150162
Optional<StringToObjectConverter> converter = stringToObjectConverters.stream().filter(
151163
candidate -> candidate.canConvertTo(targetTypeToUse)).findFirst();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy