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:NameTest
ObjectFactoryTest
AffineTransformTest
ParameterizedTransformTest
AuthorityFactoryTest
GIGS2001
GIGS2002
GIGS2003
GIGS2004
GIGS2005
GIGS2006
GIGS2007
GIGS2008
GIGS2009
GIGS3002
GIGS3003
GIGS3004
GIGS3005
CRSParserTest
TestSuite
class provides also some static methods for specifying explicitely which factories to use or being notified of test results. Those methods take effect even if theTestCase
are run outside of aTestSuite
context.How implementations are discovered
All tests useFactory
instances that are specific to the implementation being tested. By defaultTestSuite
fetches the factory implementations withServiceLoader
, which will scan everyMETA-INF/services/org.opengis.TheFactory
files 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
FactoryFilter
orImplementationDetails
in theMETA-INF/services/
directory. As an alternative, implementors can also extend directly the variousTestCase
subclasses.Example: The test suite below declares that the tolerance threshold forMyProjection
needs 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; } }
AllTests
class 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 protected
TestSuite()
Constructor provided for allowing subclassing.
-
Method Summary
Modifier and Type Method Description static void
addTestListener(TestListener listener)
Deprecated.To be replaced by JUnit 5 listener mechanism.static void
clear()
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 void
removeTestListener(TestListener listener)
Deprecated.To be replaced by JUnit 5 listener mechanism.static void
setClassLoader(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. Anull
value restores the default context class loader.- Parameters:
loader
- the class loader to use, ornull
for 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 thetype
class 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 thetype
class argument.- Parameters:
type
- the factory interface for which an implementations is desired.- Returns:
- the implementations for the given interface, or
null
if 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.null
values 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.null
values 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()
-
-