|
17 | 17 | import org.junit.platform.commons.util.Preconditions;
|
18 | 18 |
|
19 | 19 | /**
|
20 |
| - * {@code TypedConversionService} is an abstract base class for |
21 |
| - * {@link Converter} implementations that always convert objects of a |
22 |
| - * given source type into a given target type. |
| 20 | + * {@code SimpleConverter} is an abstract base class for {@link Converter} |
| 21 | + * implementations that always convert objects of a given source type into a |
| 22 | + * given target type. |
23 | 23 | *
|
24 | 24 | * @param <S> the type of the source argument to convert
|
25 | 25 | * @param <T> the type of the target object to create from the source
|
26 | 26 | * @since 6.0
|
27 | 27 | */
|
28 | 28 | @API(status = EXPERIMENTAL, since = "6.0")
|
29 |
| -public abstract class TypedConverter<S, T extends @Nullable Object> implements Converter<S, T> { |
| 29 | +public abstract class SimpleConverter<S, T extends @Nullable Object> implements Converter<S, T> { |
30 | 30 |
|
31 | 31 | private final Class<S> sourceType;
|
32 | 32 | private final Class<T> targetType;
|
33 | 33 |
|
34 | 34 | /**
|
35 |
| - * Create a new {@code TypedConversionService}. |
| 35 | + * Create a new {@code SimpleConverter}. |
36 | 36 | *
|
37 | 37 | * @param sourceType the type of the argument to convert; never {@code null}
|
38 | 38 | * @param targetType the type of the target object to create from the source;
|
39 | 39 | * never {@code null}
|
40 | 40 | */
|
41 |
| - protected TypedConverter(Class<S> sourceType, Class<T> targetType) { |
| 41 | + protected SimpleConverter(Class<S> sourceType, Class<T> targetType) { |
42 | 42 | this.sourceType = Preconditions.notNull(sourceType, "sourceType must not be null");
|
43 | 43 | this.targetType = Preconditions.notNull(targetType, "targetType must not be null");
|
44 | 44 | }
|
45 | 45 |
|
46 | 46 | @Override
|
47 | 47 | public final boolean canConvert(ConversionContext context) {
|
48 |
| - // FIXME TypeDescriptor.NONE handling? |
49 |
| - // FIXME add test cases with subtypes |
50 |
| - return this.sourceType == context.sourceType().getType() && this.targetType == context.targetType().getType(); |
| 48 | + // FIXME adjust for subtypes |
| 49 | + return !context.sourceType().equals(TypeDescriptor.NONE) // |
| 50 | + && this.sourceType == context.sourceType().getType() // |
| 51 | + && this.targetType == context.targetType().getType(); |
51 | 52 | }
|
52 | 53 |
|
53 | 54 | @Override
|
54 | 55 | public final T convert(@Nullable S source, ConversionContext context) {
|
| 56 | + Preconditions.notNull(source, "source cannot be null"); |
55 | 57 | return convert(source);
|
56 | 58 | }
|
57 | 59 |
|
58 | 60 | /**
|
59 | 61 | * Convert the supplied {@code source} object of type {@code S} into an object
|
60 | 62 | * of type {@code T}.
|
61 | 63 | *
|
62 |
| - * @param source the source object to convert; may be {@code null} |
| 64 | + * @param source the source object to convert; never {@code null} |
63 | 65 | * @return the converted object; may be {@code null} but only if the target
|
64 | 66 | * type is a reference type
|
65 | 67 | * @throws ConversionException if an error occurs during the conversion
|
66 | 68 | */
|
67 |
| - protected abstract T convert(@Nullable S source) throws ConversionException; |
| 69 | + protected abstract T convert(S source) throws ConversionException; |
68 | 70 |
|
69 | 71 | }
|
0 commit comments