Skip to content

Commit 8f2f7b4

Browse files
committed
Remove ClassLoader parameter from canConvert
1 parent 017866b commit 8f2f7b4

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static <T> T convert(Object source, TypeDescriptor targetType, ClassLoade
8282
Converter converter = Stream.concat( //
8383
StreamSupport.stream(serviceLoader.spliterator(), false), //
8484
Stream.of(DefaultConverter.INSTANCE)) //
85-
.filter(candidate -> candidate.canConvert(source, targetType, classLoader)) //
85+
.filter(candidate -> candidate.canConvert(source, targetType)) //
8686
.findFirst() //
8787
.orElseThrow(() -> new ConversionException("No registered or built-in converter for source '" + source
8888
+ "' and target type " + targetType.getType().getTypeName()));

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ public interface Converter {
4343
* if the target type is a reference type
4444
* @param targetType the descriptor of the type the source should be converted into;
4545
* never {@code null}
46-
* @param classLoader the {@code ClassLoader} to use; never {@code null}
4746
* @return {@code true} if the supplied source can be converted
4847
*/
49-
boolean canConvert(Object source, TypeDescriptor targetType, ClassLoader classLoader);
48+
boolean canConvert(Object source, TypeDescriptor targetType);
5049

5150
/**
5251
* Convert the supplied source object into an instance of the specified
5352
* target type.
5453
*
54+
* <p>This method will only be invoked if {@link #canConvert(Object, TypeDescriptor)}
55+
* returned {@code true} for the same target type.
56+
*
5557
* @param source the source object to convert; may be {@code null} but only
5658
* if the target type is a reference type
5759
* @param targetType the descriptor of the type the source should be converted into;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ private DefaultConverter() {
7373
* if the target type is a reference type
7474
* @param targetType the target type the source should be converted into;
7575
* never {@code null}
76-
* @param classLoader the {@code ClassLoader} to use; never {@code null}
7776
* @return {@code true} if the supplied source can be converted
7877
*/
7978
@Override
80-
public boolean canConvert(Object source, TypeDescriptor targetType, ClassLoader classLoader) {
79+
public boolean canConvert(Object source, TypeDescriptor targetType) {
8180
if (source == null) {
8281
return !targetType.isPrimitive();
8382
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected TypedConverter(Class<S> sourceType, Class<T> targetType) {
4444
}
4545

4646
@Override
47-
public final boolean canConvert(Object source, TypeDescriptor targetType, ClassLoader classLoader) {
47+
public final boolean canConvert(Object source, TypeDescriptor targetType) {
4848
return this.sourceType.isInstance(source)
4949
&& ReflectionUtils.isAssignableTo(this.targetType, targetType.getType());
5050
}

platform-tests/src/test/java/org/junit/platform/commons/support/conversion/DefaultConverterTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,9 @@ void convertsStringToClassWithCustomTypeFromDifferentClassLoader() throws Except
252252
assertThat(declaringExecutable.getDeclaringClass().getClassLoader()).isSameAs(testClassLoader);
253253

254254
var typeDescriptor = TypeDescriptor.forType(Class.class);
255-
var classLoader = classLoader(declaringExecutable);
256-
assertThat(canConvert(customTypeName, typeDescriptor, classLoader)).isTrue();
255+
assertThat(canConvert(customTypeName, typeDescriptor)).isTrue();
257256

258-
var clazz = (Class<?>) convert(customTypeName, typeDescriptor, classLoader);
257+
var clazz = (Class<?>) convert(customTypeName, typeDescriptor, classLoader(declaringExecutable));
259258
assertThat(clazz).isNotEqualTo(Enigma.class);
260259
assertThat(clazz).isEqualTo(customType);
261260
assertThat(clazz.getClassLoader()).isSameAs(testClassLoader);
@@ -345,17 +344,13 @@ private void assertConverts(Object input, Class<?> targetClass, Object expectedO
345344
}
346345

347346
private boolean canConvert(Object input, TypeDescriptor targetClass) {
348-
return canConvert(input, targetClass, classLoader());
347+
return DefaultConverter.INSTANCE.canConvert(input, targetClass);
349348
}
350349

351350
private Object convert(Object input, TypeDescriptor targetClass) {
352351
return convert(input, targetClass, classLoader());
353352
}
354353

355-
private boolean canConvert(Object input, TypeDescriptor targetClass, ClassLoader classLoader) {
356-
return DefaultConverter.INSTANCE.canConvert(input, targetClass, classLoader);
357-
}
358-
359354
private Object convert(Object input, TypeDescriptor targetClass, ClassLoader classLoader) {
360355
return DefaultConverter.INSTANCE.convert(input, targetClass, classLoader);
361356
}

0 commit comments

Comments
 (0)