Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Jan 2, 2025
1 parent 7ea91b8 commit 0c2faa7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.junit.platform.commons.support.conversion;

import static org.apiguardian.api.API.Status.DEPRECATED;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;

import java.util.ServiceLoader;
Expand Down Expand Up @@ -52,6 +53,7 @@ private ConversionSupport() {
*/
@SuppressWarnings("unchecked")
@Deprecated
@API(status = DEPRECATED, since = "5.12")
public static <T> T convert(String source, Class<T> targetType, ClassLoader classLoader) {
return (T) DefaultConversionService.INSTANCE.convert(source, targetType, getClassLoader(classLoader));
}
Expand Down Expand Up @@ -84,7 +86,7 @@ public static <T> T convert(Object source, Class<T> targetType, ClassLoader clas
.filter(candidate -> candidate.canConvert(source, targetType, classLoader)) //
.findFirst() //
.map(candidate -> candidate.convert(source, targetType, classLoaderToUse)) //
.orElseThrow(() -> new ConversionException("No built-in converter for source type "
.orElseThrow(() -> new ConversionException("No registered or built-in converter for source type "
+ source.getClass().getTypeName() + " and target type " + targetType.getTypeName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
org.junit.platform.suite.engine,
org.junit.platform.testkit,
org.junit.vintage.engine;
uses org.junit.platform.commons.support.conversion.ConversionService;
uses org.junit.platform.commons.support.scanning.ClasspathScanner;
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,27 @@ void throwsExceptionOnInvalidStringForPrimitiveTypes() {
void throwsExceptionWhenImplicitConverstionIsUnsupported() {
assertThatExceptionOfType(ArgumentConversionException.class) //
.isThrownBy(() -> convert("foo", Enigma.class)) //
.withMessage("No built-in converter for source type java.lang.String and target type %s",
.withMessage("No built-in converter for source type java.lang.String and target type %s", // FIXME enhance DefaultConversionService::canConvert
Enigma.class.getName());

assertThatExceptionOfType(ArgumentConversionException.class) //
.isThrownBy(() -> convert(new Enigma(), int[].class)) //
.withMessage("No built-in converter for source type %s and target type int[]", Enigma.class.getName());
.withMessage("No registered or built-in converter for source type %s and target type int[]",
Enigma.class.getName());

assertThatExceptionOfType(ArgumentConversionException.class) //
.isThrownBy(() -> convert(new long[] {}, int[].class)) //
.withMessage("No built-in converter for source type long[] and target type int[]");
.withMessage("No registered or built-in converter for source type long[] and target type int[]");

assertThatExceptionOfType(ArgumentConversionException.class) //
.isThrownBy(() -> convert(new String[] {}, boolean.class)) //
.withMessage("No built-in converter for source type java.lang.String[] and target type boolean");
.withMessage(
"No registered or built-in converter for source type java.lang.String[] and target type boolean");

assertThatExceptionOfType(ArgumentConversionException.class) //
.isThrownBy(() -> convert(Class.class, int[].class)) //
.withMessage("No built-in converter for source type java.lang.Class and target type int[]");
.withMessage(
"No registered or built-in converter for source type java.lang.Class and target type int[]");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ requires java.base mandated
requires java.logging
requires java.management
requires org.apiguardian.api static transitive
uses org.junit.platform.commons.support.conversion.ConversionService
uses org.junit.platform.commons.support.scanning.ClasspathScanner
qualified exports org.junit.platform.commons.logging to org.junit.jupiter.api org.junit.jupiter.engine org.junit.jupiter.migrationsupport org.junit.jupiter.params org.junit.platform.console org.junit.platform.engine org.junit.platform.launcher org.junit.platform.reporting org.junit.platform.runner org.junit.platform.suite.api org.junit.platform.suite.engine org.junit.platform.testkit org.junit.vintage.engine
qualified exports org.junit.platform.commons.util to org.junit.jupiter.api org.junit.jupiter.engine org.junit.jupiter.migrationsupport org.junit.jupiter.params org.junit.platform.console org.junit.platform.engine org.junit.platform.launcher org.junit.platform.reporting org.junit.platform.runner org.junit.platform.suite.api org.junit.platform.suite.commons org.junit.platform.suite.engine org.junit.platform.testkit org.junit.vintage.engine

0 comments on commit 0c2faa7

Please sign in to comment.