-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
ConversionService
in junit-platform-commons
- Loading branch information
Showing
10 changed files
with
394 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ommons/src/main/java/org/junit/platform/commons/support/conversion/ConversionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.support.conversion; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code ConversionService} is an abstraction that allows an input object to | ||
* be converted to an instance of a different class. | ||
* | ||
* <p>Implementations are loaded via the {@link java.util.ServiceLoader} and must | ||
* follow the service provider requirements. They should not make any assumptions | ||
* regarding when they are instantiated or how often they are called. Since | ||
* instances may potentially be cached and called from different threads, they | ||
* should be thread-safe. | ||
* | ||
* <p>Extend {@link TypedConversionService} if your implementation always converts | ||
* from a given source type into a given target type and does not need access to | ||
* the {@link ClassLoader} to perform the conversion. | ||
* | ||
* @since 1.12 | ||
* @see ConversionSupport | ||
* @see TypedConversionService | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "1.12") | ||
public interface ConversionService { | ||
|
||
/** | ||
* Determine if the supplied source object can be converted into an instance | ||
* of the specified target type. | ||
* | ||
* @param source the source object to convert; may be {@code null} but only | ||
* if the target type is a reference type | ||
* @param targetType the target type the source should be converted into; | ||
* never {@code null} | ||
* @param classLoader the {@code ClassLoader} to use; never {@code null} | ||
* @return {@code true} if the supplied source can be converted | ||
*/ | ||
boolean canConvert(Object source, Class<?> targetType, ClassLoader classLoader); | ||
|
||
/** | ||
* Convert the supplied source object into an instance of the specified | ||
* target type. | ||
* | ||
* @param source the source object to convert; may be {@code null} but only | ||
* if the target type is a reference type | ||
* @param targetType the target type the source should be converted into; | ||
* never {@code null} | ||
* @param classLoader the {@code ClassLoader} to use; never {@code null} | ||
* @return the converted object; may be {@code null} but only if the target | ||
* type is a reference type | ||
* @throws ConversionException if an error occurs during the conversion | ||
*/ | ||
Object convert(Object source, Class<?> targetType, ClassLoader classLoader) throws ConversionException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.