Author: desruisseaux
Date: Fri Mar  6 23:17:44 2015
New Revision: 1664759

URL: http://svn.apache.org/r1664759
Log:
Referencing: moved a test closer to where the tested objects are defined.

Added:
    
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java
      - copied, changed from r1663765, 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
Modified:
    
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
    
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Copied: 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java
 (from r1663765, 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java?p2=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java&p1=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java&r1=1663765&r2=1664759&rev=1664759&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java
 [UTF-8] Fri Mar  6 23:17:44 2015
@@ -14,35 +14,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.referencing.operation.transform;
+package org.apache.sis.internal.referencing.provider;
 
-import java.util.Set;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.IdentityHashMap;
+import java.util.ServiceLoader;
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
-import org.opengis.util.NoSuchIdentifierException;
-import org.opengis.referencing.operation.Conversion;
-import org.opengis.referencing.operation.Projection;
-import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.OperationMethod;
-import org.apache.sis.internal.referencing.provider.Affine;
-import org.apache.sis.internal.util.Constants;
-import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.opengis.test.Assert.*;
+import static org.junit.Assert.*;
 
 
 /**
- * Tests the registration of operation methods in {@link 
DefaultMathTransformFactory}. This test uses the
- * providers registered in all {@code 
META-INF/services/org.opengis.referencing.operation.OperationMethod}
- * files found on the classpath.
+ * Tests all providers defined in this package.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
@@ -51,83 +40,14 @@ import static org.opengis.test.Assert.*;
  */
 @DependsOn({
     org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,
-    OperationMethodSetTest.class
+    AffineTest.class
 })
-public final strictfp class DefaultMathTransformFactoryTest extends TestCase {
+public final strictfp class AllProvidersTest extends TestCase {
     /**
-     * The factory being tested.
+     * Returns all registered operation methods.
      */
-    private static DefaultMathTransformFactory factory;
-
-    /**
-     * Creates the factory to be tested.
-     */
-    @BeforeClass
-    public static void createFactory() {
-        factory = new DefaultMathTransformFactory();
-    }
-
-    /**
-     * Releases the factory used for the tests.
-     */
-    @AfterClass
-    public static void releaseFactory() {
-        factory = null;
-    }
-
-    /**
-     * Tests the {@link 
DefaultMathTransformFactory#getOperationMethod(String)} method.
-     *
-     * @throws NoSuchIdentifierException Should never happen.
-     */
-    @Test
-    public void testGetOperationMethod() throws NoSuchIdentifierException {
-        // A conversion which is not a projection.
-        OperationMethod method = factory.getOperationMethod(Constants.AFFINE);
-        assertInstanceOf("Affine", Affine.class, method);
-
-        // Same than above, using EPSG code.
-        assertSame("EPSG:9624", method, 
factory.getOperationMethod("EPSG:9624"));
-    }
-
-    /**
-     * Tests non-existent operation method.
-     */
-    @Test
-    @DependsOnMethod("testGetOperationMethod")
-    public void testNonExistentCode() {
-        try {
-            factory.getOperationMethod("EPXX:9624");
-            fail("Expected NoSuchIdentifierException");
-        } catch (NoSuchIdentifierException e) {
-            final String message = e.getLocalizedMessage();
-            assertTrue(message, message.contains("EPXX:9624"));
-        }
-    }
-
-    /**
-     * Tests the {@link 
DefaultMathTransformFactory#getAvailableMethods(Class)} method.
-     *
-     * @throws NoSuchIdentifierException Should never happen.
-     */
-    @Test
-    @DependsOnMethod("testGetOperationMethod")
-    public void testGetAvailableMethods() throws NoSuchIdentifierException {
-        final Set<OperationMethod> transforms  = 
factory.getAvailableMethods(SingleOperation.class);
-        final Set<OperationMethod> conversions = 
factory.getAvailableMethods(Conversion.class);
-        final Set<OperationMethod> projections = 
factory.getAvailableMethods(Projection.class);
-        /*
-         * Following tests should not cause loading of more classes than 
needed.
-         */
-        assertFalse(transforms .isEmpty());
-        assertFalse(conversions.isEmpty());
-        assertTrue (projections.isEmpty());
-        assertTrue 
(conversions.contains(factory.getOperationMethod(Constants.AFFINE)));
-        /*
-         * Following tests will force instantiation of all remaining 
OperationMethod.
-         */
-        assertTrue("Conversions should be a subset of transforms.",  
transforms .containsAll(conversions));
-        assertTrue("Projections should be a subset of conversions.", 
conversions.containsAll(projections));
+    private static Iterable<OperationMethod> methods() {
+        return ServiceLoader.load(OperationMethod.class, 
AbstractProvider.class.getClassLoader());
     }
 
     /**
@@ -135,11 +55,10 @@ public final strictfp class DefaultMathT
      * This is only for sharing existing resources by avoiding unnecessary 
objects duplication.
      */
     @Test
-    @DependsOnMethod("testGetAvailableMethods")
     public void ensureParameterUniqueness() {
         final Map<GeneralParameterDescriptor, String> groupNames = new 
IdentityHashMap<>();
         final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> 
existings = new HashMap<>();
-        for (final OperationMethod method : 
factory.getAvailableMethods(SingleOperation.class)) {
+        for (final OperationMethod method : methods()) {
             final ParameterDescriptorGroup group = method.getParameters();
             final String name = group.getName().getCode();
             for (final GeneralParameterDescriptor param : group.descriptors()) 
{
@@ -147,8 +66,8 @@ public final strictfp class DefaultMathT
                 final GeneralParameterDescriptor existing = 
existings.put(param, param);
                 if (existing != null && existing != param) {
                     fail("Parameter “" + param.getName().getCode() + "” 
defined in “" + name + '”'
-                       + " was already defined in “" + 
groupNames.get(existing) + "”."
-                       + " The same instance could be shared.");
+                            + " was already defined in “" + 
groupNames.get(existing) + "”."
+                            + " The same instance could be shared.");
                 }
             }
         }

Modified: 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java?rev=1664759&r1=1664758&r2=1664759&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
 [UTF-8] Fri Mar  6 23:17:44 2015
@@ -17,11 +17,6 @@
 package org.apache.sis.referencing.operation.transform;
 
 import java.util.Set;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import org.opengis.parameter.GeneralParameterDescriptor;
-import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.util.NoSuchIdentifierException;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.Projection;
@@ -50,7 +45,7 @@ import static org.opengis.test.Assert.*;
  * @module
  */
 @DependsOn({
-    org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,
+    org.apache.sis.internal.referencing.provider.AllProvidersTest.class,
     OperationMethodSetTest.class
 })
 public final strictfp class DefaultMathTransformFactoryTest extends TestCase {
@@ -129,28 +124,4 @@ public final strictfp class DefaultMathT
         assertTrue("Conversions should be a subset of transforms.",  
transforms .containsAll(conversions));
         assertTrue("Projections should be a subset of conversions.", 
conversions.containsAll(projections));
     }
-
-    /**
-     * Ensures that every parameter instance is unique. Actually this test is 
not strong requirement.
-     * This is only for sharing existing resources by avoiding unnecessary 
objects duplication.
-     */
-    @Test
-    @DependsOnMethod("testGetAvailableMethods")
-    public void ensureParameterUniqueness() {
-        final Map<GeneralParameterDescriptor, String> groupNames = new 
IdentityHashMap<>();
-        final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> 
existings = new HashMap<>();
-        for (final OperationMethod method : 
factory.getAvailableMethods(SingleOperation.class)) {
-            final ParameterDescriptorGroup group = method.getParameters();
-            final String name = group.getName().getCode();
-            for (final GeneralParameterDescriptor param : group.descriptors()) 
{
-                assertFalse("Parameter declared twice in the same group.", 
name.equals(groupNames.put(param, name)));
-                final GeneralParameterDescriptor existing = 
existings.put(param, param);
-                if (existing != null && existing != param) {
-                    fail("Parameter “" + param.getName().getCode() + "” 
defined in “" + name + '”'
-                       + " was already defined in “" + 
groupNames.get(existing) + "”."
-                       + " The same instance could be shared.");
-                }
-            }
-        }
-    }
 }

Modified: 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1664759&r1=1664758&r2=1664759&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
 [UTF-8] Fri Mar  6 23:17:44 2015
@@ -82,10 +82,11 @@ import org.junit.BeforeClass;
 
     org.apache.sis.referencing.operation.DefaultFormulaTest.class,
     org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,
+    org.apache.sis.internal.referencing.provider.AffineTest.class,
+    org.apache.sis.internal.referencing.provider.AllProvidersTest.class,
     
org.apache.sis.referencing.operation.transform.OperationMethodSetTest.class,
     
org.apache.sis.referencing.operation.transform.DefaultMathTransformFactoryTest.class,
     org.apache.sis.internal.referencing.OperationMethodsTest.class,
-    org.apache.sis.internal.referencing.provider.AffineTest.class,
 
     org.apache.sis.referencing.datum.BursaWolfParametersTest.class,
     org.apache.sis.referencing.datum.TimeDependentBWPTest.class,


Reply via email to