Package org.opengis.test
Class TestSuite
- Object
-
- TestSuite
-
public class TestSuite extends Object
The suite of every tests defined in the GeoAPI conformance module. The test cases included in this test suite are:NameTestObjectFactoryTestAffineTransformTestParameterizedTransformTestAuthorityFactoryTestGIGS2001GIGS2002GIGS2003GIGS2004GIGS2005GIGS2006GIGS2007GIGS2008GIGS2009GIGS3002GIGS3003GIGS3004GIGS3005CRSParserTest
TestSuiteclass provides also some static methods for specifying explicitely which factories to use or being notified of test results. Those methods take effect even if theTestCaseare run outside of aTestSuitecontext.How implementations are discovered
All tests useFactoryinstances that are specific to the implementation being tested. By defaultTestSuitefetches the factory implementations withServiceLoader, which will scan everyMETA-INF/services/org.opengis.TheFactoryfiles on the classpath. However implementors can override this default mechanism with explicit calls to thesetFactories(Class, Factory[])method.Implementors can have some control on the tests (factories to use, features to test, tolerance thresholds) by registering their
FactoryFilterorImplementationDetailsin theMETA-INF/services/directory. As an alternative, implementors can also extend directly the variousTestCasesubclasses.Example: The test suite below declares that the tolerance threshold forMyProjectionneeds to be relaxed by a factor 10 during inverse projections.
The abovepackage org.myproject; import org.opengis.test.TestSuite; import org.opengis.test.CalculationType; import org.opengis.test.ToleranceModifier; import org.opengis.test.ToleranceModifiers; import org.opengis.test.ImplementationDetails; import org.opengis.referencing.operation.MathTransform; import org.opengis.util.Factory; import java.util.Properties; public class AllTests extends TestSuite implements ImplementationDetails { @Override public Properties configuration(Factory... factories) { return null; } @Override public ToleranceModifier tolerance(MathTransform transform) { if (transform instanceof MyProjection) { return ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1, 10); } return null; } }
AllTestsclass needs to be registered in theMETA-INF/services/directory if the implementation details shall be honored (otherwise the tests will be run, but the implementation details will be ignored).- Since:
- 3.1
- See Also:
ImplementationDetails,TestCase,Factory
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTestSuite()Constructor provided for allowing subclassing.
-
Method Summary
Modifier and Type Method Description static voidaddTestListener(TestListener listener)Deprecated.To be replaced by JUnit 5 listener mechanism.static voidclear()Clears all factories specified to thesetFactories(Class, Factory[])method, and clears all service loader caches.static <T extends Factory>
T[]getFactories(Class<T> type)Returns the factory implementations explicitely given by the last call tosetFactories(Class, Factory[])for the given interface.static voidremoveTestListener(TestListener listener)Deprecated.To be replaced by JUnit 5 listener mechanism.static voidsetClassLoader(ClassLoader loader)Sets the class loader to use for loading implementations.static <T extends Factory>
voidsetFactories(Class<T> type, T... factory)Specifies the factory implementations to use for the given factory interface.
-
-
-
Constructor Detail
-
TestSuite
protected TestSuite()
Constructor provided for allowing subclassing. Instances of this class usually don't need to be created.
-
-
Method Detail
-
setClassLoader
public static void setClassLoader(ClassLoader loader)
Sets the class loader to use for loading implementations. Anullvalue restores the default context class loader.- Parameters:
loader- the class loader to use, ornullfor the default.
-
setFactories
@SafeVarargs public static <T extends Factory> void setFactories(Class<T> type, T... factory)
Specifies the factory implementations to use for the given factory interface.- Type Parameters:
T- the compile-time type of thetypeclass argument.- Parameters:
type- the factory interface for which an implementation is specified.factory- the implementations to use for the given interface.
-
getFactories
public static <T extends Factory> T[] getFactories(Class<T> type)
Returns the factory implementations explicitely given by the last call tosetFactories(Class, Factory[])for the given interface. This method does not scan theMETA-INF/services/<T>entries.- Type Parameters:
T- the compile-time type of thetypeclass argument.- Parameters:
type- the factory interface for which an implementations is desired.- Returns:
- the implementations for the given interface, or
nullif none.
-
addTestListener
@Deprecated public static void addTestListener(TestListener listener)
Deprecated.To be replaced by JUnit 5 listener mechanism.Adds a listener to be informed every time a test begin or finish, either on success or failure. This method does not check if the given listener was already registered (i.e. the same listener may be added more than once).- Parameters:
listener- The listener to add.nullvalues are silently ignored.
-
removeTestListener
@Deprecated public static void removeTestListener(TestListener listener)
Deprecated.To be replaced by JUnit 5 listener mechanism.Removes a previously added listener. If the given listener has been added more than once, then only the last occurrence is removed. If the given listener is not found, then this method does nothing.- Parameters:
listener- the listener to remove.nullvalues are silently ignored.
-
clear
public static void clear()
Clears all factories specified to thesetFactories(Class, Factory[])method, and clears all service loader caches. After this method call, all factories will be reloaded when first needed. This method is intended for use in situations in which new factories can be installed or removed into a running Java virtual machine.- See Also:
ServiceLoader.reload()
-
-