sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1547939 [2/2] - in /sis/branches/JDK7: core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/ c...
Date Wed, 04 Dec 2013 22:34:19 GMT
Copied: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java
(from r1546824, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java?p2=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java&p1=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java&r1=1546824&r2=1547939&rev=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -19,259 +19,77 @@ package org.apache.sis.measure;
 import javax.measure.unit.Unit;
 import javax.measure.quantity.Quantity;
 import javax.measure.converter.UnitConverter;
-import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
-import org.junit.*;
+import org.junit.Test;
 
-import static javax.measure.unit.Unit.ONE;
-import static javax.measure.unit.SI.CELSIUS;
-import static javax.measure.unit.SI.METRE;
-import static javax.measure.unit.SI.KILOMETRE;
-import static javax.measure.unit.SI.RADIAN;
-import static javax.measure.unit.NonSI.CENTIRADIAN;
 import static javax.measure.unit.NonSI.DEGREE_ANGLE;
-import static javax.measure.unit.NonSI.MINUTE_ANGLE;
-import static javax.measure.unit.NonSI.SECOND_ANGLE;
-import static javax.measure.unit.NonSI.GRADE;
-import static javax.measure.unit.NonSI.DAY;
-import static javax.measure.unit.NonSI.SPHERE;
-import static javax.measure.unit.NonSI.ATMOSPHERE;
-import static javax.measure.unit.NonSI.NAUTICAL_MILE;
-import static org.apache.sis.measure.Units.*;
+import static org.apache.sis.measure.SexagesimalConverter.*;
 import static org.apache.sis.test.Assert.*;
 
 
 /**
- * Test conversions using the units declared in {@link Units}.
+ * Test {@link SexagesimalConverter}
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
  * @version 0.4
  * @module
  */
-@DependsOn(org.apache.sis.internal.util.URIParserTest.class)
-public final strictfp class UnitsTest extends TestCase {
+public final strictfp class SexagesimalConverterTest extends TestCase {
     /**
-     * Compares two values for equality.
+     * Tolerance value for the comparisons of floating point numbers.
+     */
+    private static final double TOLERANCE = 1E-12;
+
+    /**
+     * Converts the given value to an other unit, compares with the expected value, and verify
+     * the inverse conversion. Then tries again with the negative of the given values.
      */
     private static <Q extends Quantity> void checkConversion(
             final double expected, final Unit<Q> unitExpected,
             final double actual,   final Unit<Q> unitActual)
     {
-        UnitConverter converter = unitActual.getConverterTo(unitExpected);
-        assertEquals(expected, converter.convert(actual), 1E-6);
-        converter = converter.inverse();
-        assertEquals(actual, converter.convert(expected), 1E-6);
-    }
-
-    /**
-     * Checks the conversions using {@link Units#SEXAGESIMAL_DMS}.
-     */
-    @Test
-    public void testSexagesimal() {
-        checkConversion(10.00, DEGREE_ANGLE, 10.0000, SEXAGESIMAL_DMS);
-        checkConversion(10.01, DEGREE_ANGLE, 10.0036, SEXAGESIMAL_DMS);
-        checkConversion(10.50, DEGREE_ANGLE, 10.3000, SEXAGESIMAL_DMS);
-        checkConversion(10.99, DEGREE_ANGLE, 10.5924, SEXAGESIMAL_DMS);
-    }
-
-    /**
-     * Tests serialization of units.
-     *
-     * @todo The {@code assertEquals} in this method should actually be {@code assertSame},
-     *       but JSR-275 0.9.3 does not resolve units on deserialization.
-     */
-    @Test
-    public void testSerialization() {
-        assertEquals(DEGREE_ANGLE,         assertSerializedEquals(DEGREE_ANGLE));
-        assertEquals(SEXAGESIMAL_DMS,      assertSerializedEquals(SEXAGESIMAL_DMS));
-        assertEquals(DEGREE_MINUTE_SECOND, assertSerializedEquals(DEGREE_MINUTE_SECOND));
-        assertEquals(PPM,                  assertSerializedEquals(PPM));
-    }
-
-    /**
-     * Tests {@link Units#isTemporal(Unit)}.
-     */
-    @Test
-    public void testIsTemporal() {
-        // Standard units
-        assertFalse(isTemporal(null));
-        assertFalse(isTemporal(ONE));
-        assertFalse(isTemporal(METRE));
-        assertFalse(isTemporal(RADIAN));
-        assertFalse(isTemporal(CENTIRADIAN));
-        assertFalse(isTemporal(DEGREE_ANGLE));
-        assertFalse(isTemporal(MINUTE_ANGLE));
-        assertFalse(isTemporal(SECOND_ANGLE));
-        assertFalse(isTemporal(GRADE));
-        assertTrue (isTemporal(DAY));
-        assertFalse(isTemporal(SPHERE));
-        assertFalse(isTemporal(ATMOSPHERE));
-        assertFalse(isTemporal(NAUTICAL_MILE));
-
-        // Additional units
-        assertFalse(isTemporal(PPM));
-        assertTrue (isTemporal(MILLISECOND));
-        assertFalse(isTemporal(SEXAGESIMAL_DMS));
-        assertFalse(isTemporal(DEGREE_MINUTE_SECOND));
-    }
-
-    /**
-     * Tests {@link Units#isLinear(Unit)}.
-     */
-    @Test
-    public void testIsLinear() {
-        // Standard units
-        assertFalse(isLinear(null));
-        assertFalse(isLinear(ONE));
-        assertTrue (isLinear(METRE));
-        assertFalse(isLinear(RADIAN));
-        assertFalse(isLinear(CENTIRADIAN));
-        assertFalse(isLinear(DEGREE_ANGLE));
-        assertFalse(isLinear(MINUTE_ANGLE));
-        assertFalse(isLinear(SECOND_ANGLE));
-        assertFalse(isLinear(GRADE));
-        assertFalse(isLinear(DAY));
-        assertFalse(isLinear(SPHERE));
-        assertFalse(isLinear(ATMOSPHERE));
-        assertTrue (isLinear(NAUTICAL_MILE));
-
-        // Additional units
-        assertFalse(isLinear(PPM));
-        assertFalse(isLinear(MILLISECOND));
-        assertFalse(isLinear(SEXAGESIMAL_DMS));
-        assertFalse(isLinear(DEGREE_MINUTE_SECOND));
-    }
-
-    /**
-     * Tests {@link Units#isAngular(Unit)}.
-     */
-    @Test
-    public void testIsAngular() {
-        // Standard units
-        assertFalse(isAngular(null));
-        assertFalse(isAngular(ONE));
-        assertFalse(isAngular(METRE));
-        assertTrue (isAngular(RADIAN));
-        assertTrue (isAngular(CENTIRADIAN));
-        assertTrue (isAngular(DEGREE_ANGLE));
-        assertTrue (isAngular(MINUTE_ANGLE));
-        assertTrue (isAngular(SECOND_ANGLE));
-        assertTrue (isAngular(GRADE));
-        assertFalse(isAngular(DAY));
-        assertFalse(isAngular(SPHERE));
-        assertFalse(isAngular(ATMOSPHERE));
-        assertFalse(isAngular(NAUTICAL_MILE));
-
-        // Additional units
-        assertFalse(isAngular(PPM));
-        assertFalse(isAngular(MILLISECOND));
-        assertTrue (isAngular(SEXAGESIMAL_DMS));
-        assertTrue (isAngular(DEGREE_MINUTE_SECOND));
-    }
-
-    /**
-     * Tests {@link Units#isScale(Unit)}.
-     */
-    @Test
-    public void testIsScale() {
-        // Standard units
-        assertFalse(isScale(null));
-        assertTrue (isScale(ONE));
-        assertFalse(isScale(METRE));
-        assertFalse(isScale(RADIAN));
-        assertFalse(isScale(CENTIRADIAN));
-        assertFalse(isScale(DEGREE_ANGLE));
-        assertFalse(isScale(MINUTE_ANGLE));
-        assertFalse(isScale(SECOND_ANGLE));
-        assertFalse(isScale(GRADE));
-        assertFalse(isScale(DAY));
-        assertFalse(isScale(SPHERE));
-        assertFalse(isScale(ATMOSPHERE));
-        assertFalse(isScale(NAUTICAL_MILE));
-
-        // Additional units
-        assertTrue (isScale(PPM));
-        assertFalse(isScale(MILLISECOND));
-        assertFalse(isScale(SEXAGESIMAL_DMS));
-        assertFalse(isScale(DEGREE_MINUTE_SECOND));
-    }
-
-    /**
-     * Tests {@link Units#isPressure(Unit)}.
-     */
-    @Test
-    public void testIsPressure() {
-        assertFalse(isPressure(null));
-        assertFalse(isPressure(METRE));
-        assertTrue (isPressure(ATMOSPHERE));
-    }
-
-    /**
-     * Tests {@link Units#toStandardUnit(Unit)}.
-     */
-    @Test
-    public void testToStandardUnit() {
-        assertEquals(1000.0,               toStandardUnit(KILOMETRE),    1E-15);
-        assertEquals(0.017453292519943295, toStandardUnit(DEGREE_ANGLE), 1E-15);
+        final UnitConverter converter = unitActual.getConverterTo(unitExpected);
+        final UnitConverter inverse   = converter.inverse();
+        assertEquals( expected, converter.convert( actual), TOLERANCE);
+        assertEquals( actual,   inverse.convert( expected), TOLERANCE);
+        assertEquals(-expected, converter.convert(-actual), TOLERANCE);
+        assertEquals(-actual,   inverse.convert(-expected), TOLERANCE);
     }
 
     /**
-     * Tests {@link Units#multiply(Unit, double)}.
+     * Checks the conversions using {@link SexagesimalConverter#DM}.
      */
     @Test
-    public void testMultiply() {
-        assertSame(KILOMETRE,    multiply(METRE,  1000));
-        assertSame(DEGREE_ANGLE, multiply(RADIAN, 0.017453292519943295));
+    public void testDM() {
+        checkConversion(10.00,              DEGREE_ANGLE, 10.0000,    DM);
+        checkConversion(10.006,             DEGREE_ANGLE, 10.0036,    DM);
+        checkConversion(10.50,              DEGREE_ANGLE, 10.3000,    DM);
+        checkConversion(10.987333333333333, DEGREE_ANGLE, 10.5924,    DM);
+        checkConversion(44.503354166666666, DEGREE_ANGLE, 44.3020125, DM);
     }
 
     /**
-     * Tests {@link Units#valueOf(String)}.
+     * Checks the conversions using {@link SexagesimalConverter#DMS}.
      */
     @Test
-    public void testValueOf() {
-        assertSame(DEGREE_ANGLE, valueOf("°"));
-        assertSame(DEGREE_ANGLE, valueOf("deg"));
-        assertSame(DEGREE_ANGLE, valueOf("degree"));
-        assertSame(DEGREE_ANGLE, valueOf("degrees"));
-        assertSame(DEGREE_ANGLE, valueOf("degrées"));
-        assertSame(DEGREE_ANGLE, valueOf("DEGREES"));
-        assertSame(DEGREE_ANGLE, valueOf("DEGRÉES"));
-        assertSame(DEGREE_ANGLE, valueOf("degrees_east"));
-        assertSame(DEGREE_ANGLE, valueOf("degrées_north"));
-        assertSame(DEGREE_ANGLE, valueOf("decimal_degree"));
-        assertSame(SECOND_ANGLE, valueOf("arcsec"));
-        assertSame(RADIAN,       valueOf("rad"));
-        assertSame(RADIAN,       valueOf("radian"));
-        assertSame(RADIAN,       valueOf("radians"));
-        assertSame(METRE,        valueOf("m"));
-        assertSame(METRE,        valueOf("metre"));
-        assertSame(METRE,        valueOf("meter"));
-        assertSame(METRE,        valueOf("metres"));
-        assertSame(METRE,        valueOf("mètres"));
-        assertSame(METRE,        valueOf("meters"));
-        assertSame(KILOMETRE,    valueOf("km"));
-        assertSame(KILOMETRE,    valueOf("kilometre"));
-        assertSame(KILOMETRE,    valueOf("kilometer"));
-        assertSame(KILOMETRE,    valueOf("kilometres"));
-        assertSame(KILOMETRE,    valueOf("kilomètres"));
-        assertSame(KILOMETRE,    valueOf("kilometers"));
-        assertSame(CELSIUS,      valueOf("Celsius"));
-        assertSame(CELSIUS,      valueOf("degree Celsius"));
-        assertSame(CELSIUS,      valueOf("degree_Celcius"));
+    public void testDMS() {
+        checkConversion(10.00,              DEGREE_ANGLE, 10.0000,    DMS);
+        checkConversion(10.01,              DEGREE_ANGLE, 10.0036,    DMS);
+        checkConversion(10.50,              DEGREE_ANGLE, 10.3000,    DMS);
+        checkConversion(10.99,              DEGREE_ANGLE, 10.5924,    DMS);
+        checkConversion(44.505590277777777, DEGREE_ANGLE, 44.3020125, DMS);
     }
 
     /**
-     * Tests {@link Units#valueOfEPSG(int)} and {@link Units#valueOf(String)} with a {@code
"EPSG:####"} syntax.
+     * Checks the conversions using {@link SexagesimalConverter#DMS_SCALED}.
      */
     @Test
-    public void testValueOfEPSG() {
-        assertSame(METRE,        valueOfEPSG(9001));
-        assertSame(DEGREE_ANGLE, valueOfEPSG(9102));
-        assertSame(METRE,        valueOf("EPSG:9001"));
-        assertSame(DEGREE_ANGLE, valueOf(" epsg : 9102"));
-        assertSame(DEGREE_ANGLE, valueOf("urn:ogc:def:uom:EPSG::9102"));
-        assertSame(METRE,        valueOf("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
-        assertSame(METRE,        valueOf("gmxUom.xml#m"));
+    public void testDMS_Scaled() {
+        checkConversion(10.00,              DEGREE_ANGLE, 100000,     DMS_SCALED);
+        checkConversion(10.01,              DEGREE_ANGLE, 100036,     DMS_SCALED);
+        checkConversion(10.50,              DEGREE_ANGLE, 103000,     DMS_SCALED);
+        checkConversion(10.99,              DEGREE_ANGLE, 105924,     DMS_SCALED);
+        checkConversion(44.505590277777777, DEGREE_ANGLE, 443020.125, DMS_SCALED);
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -17,11 +17,9 @@
 package org.apache.sis.measure;
 
 import javax.measure.unit.Unit;
-import javax.measure.quantity.Quantity;
-import javax.measure.converter.UnitConverter;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
-import org.junit.*;
+import org.junit.Test;
 
 import static javax.measure.unit.Unit.ONE;
 import static javax.measure.unit.SI.CELSIUS;
@@ -37,6 +35,7 @@ import static javax.measure.unit.NonSI.D
 import static javax.measure.unit.NonSI.SPHERE;
 import static javax.measure.unit.NonSI.ATMOSPHERE;
 import static javax.measure.unit.NonSI.NAUTICAL_MILE;
+import static org.apache.sis.measure.SexagesimalConverter.*;
 import static org.apache.sis.measure.Units.*;
 import static org.apache.sis.test.Assert.*;
 
@@ -49,30 +48,18 @@ import static org.apache.sis.test.Assert
  * @version 0.4
  * @module
  */
-@DependsOn(org.apache.sis.internal.util.URIParserTest.class)
+@DependsOn({
+    SexagesimalConverterTest.class,
+    org.apache.sis.internal.util.URIParserTest.class
+})
 public final strictfp class UnitsTest extends TestCase {
     /**
-     * Compares two values for equality.
-     */
-    private static <Q extends Quantity> void checkConversion(
-            final double expected, final Unit<Q> unitExpected,
-            final double actual,   final Unit<Q> unitActual)
-    {
-        UnitConverter converter = unitActual.getConverterTo(unitExpected);
-        assertEquals(expected, converter.convert(actual), 1E-6);
-        converter = converter.inverse();
-        assertEquals(actual, converter.convert(expected), 1E-6);
-    }
-
-    /**
-     * Checks the conversions using {@link Units#SEXAGESIMAL_DMS}.
+     * Sanity check of {@link UnitsMap}. This test fail if at least one code in the
+     * {@link UnitsMap#EPSG_CODES} static initializer is invalid.
      */
     @Test
-    public void testSexagesimal() {
-        checkConversion(10.00, DEGREE_ANGLE, 10.0000, SEXAGESIMAL_DMS);
-        checkConversion(10.01, DEGREE_ANGLE, 10.0036, SEXAGESIMAL_DMS);
-        checkConversion(10.50, DEGREE_ANGLE, 10.3000, SEXAGESIMAL_DMS);
-        checkConversion(10.99, DEGREE_ANGLE, 10.5924, SEXAGESIMAL_DMS);
+    public void testUnitsMap() {
+        assertFalse(UnitsMap.EPSG_CODES.containsKey(null));
     }
 
     /**
@@ -84,8 +71,8 @@ public final strictfp class UnitsTest ex
     @Test
     public void testSerialization() {
         assertEquals(DEGREE_ANGLE,         assertSerializedEquals(DEGREE_ANGLE));
-        assertEquals(SEXAGESIMAL_DMS,      assertSerializedEquals(SEXAGESIMAL_DMS));
-        assertEquals(DEGREE_MINUTE_SECOND, assertSerializedEquals(DEGREE_MINUTE_SECOND));
+        assertEquals(DMS,      assertSerializedEquals(DMS));
+        assertEquals(DMS_SCALED, assertSerializedEquals(DMS_SCALED));
         assertEquals(PPM,                  assertSerializedEquals(PPM));
     }
 
@@ -112,8 +99,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertFalse(isTemporal(PPM));
         assertTrue (isTemporal(MILLISECOND));
-        assertFalse(isTemporal(SEXAGESIMAL_DMS));
-        assertFalse(isTemporal(DEGREE_MINUTE_SECOND));
+        assertFalse(isTemporal(DMS));
+        assertFalse(isTemporal(DMS_SCALED));
     }
 
     /**
@@ -139,8 +126,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertFalse(isLinear(PPM));
         assertFalse(isLinear(MILLISECOND));
-        assertFalse(isLinear(SEXAGESIMAL_DMS));
-        assertFalse(isLinear(DEGREE_MINUTE_SECOND));
+        assertFalse(isLinear(DMS));
+        assertFalse(isLinear(DMS_SCALED));
     }
 
     /**
@@ -166,8 +153,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertFalse(isAngular(PPM));
         assertFalse(isAngular(MILLISECOND));
-        assertTrue (isAngular(SEXAGESIMAL_DMS));
-        assertTrue (isAngular(DEGREE_MINUTE_SECOND));
+        assertTrue (isAngular(DMS));
+        assertTrue (isAngular(DMS_SCALED));
     }
 
     /**
@@ -193,8 +180,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertTrue (isScale(PPM));
         assertFalse(isScale(MILLISECOND));
-        assertFalse(isScale(SEXAGESIMAL_DMS));
-        assertFalse(isScale(DEGREE_MINUTE_SECOND));
+        assertFalse(isScale(DMS));
+        assertFalse(isScale(DMS_SCALED));
     }
 
     /**
@@ -274,4 +261,14 @@ public final strictfp class UnitsTest ex
         assertSame(METRE,        valueOf("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
         assertSame(METRE,        valueOf("gmxUom.xml#m"));
     }
+
+    /**
+     * Tests {@link Units#getEpsgCode(Unit)}.
+     */
+    @Test
+    public void testGetEpsgCode() {
+        assertEquals(Integer.valueOf(9001), getEpsgCode(METRE));
+        assertEquals(Integer.valueOf(9102), getEpsgCode(DEGREE_ANGLE));
+        assertEquals(Integer.valueOf(9110), getEpsgCode(DMS));
+    }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -31,7 +31,7 @@ import org.apache.sis.xml.MarshallerPool
 import org.apache.sis.xml.XML;
 import org.junit.After;
 
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
 
 
 /**
@@ -132,15 +132,31 @@ public abstract strictfp class XMLTestCa
     }
 
     /**
+     * Marshals the given object using the {@linkplain #getMarshallerPool() test marshaller
pool}.
+     *
+     * @param  object The object to marshal.
+     * @return The marshalled object.
+     * @throws JAXBException If an error occurred while marshalling the object.
+     */
+    protected final String marshal(final Object object) throws JAXBException {
+        final MarshallerPool pool = getMarshallerPool();
+        final Marshaller marshaller = pool.acquireMarshaller();
+        final String xml = marshal(marshaller, object);
+        pool.recycle(marshaller);
+        return xml;
+    }
+
+    /**
      * Marshals the given object using the given marshaler.
      *
      * @param  marshaller The marshaller to use.
-     * @param  object     The object to marshal, or {@code null}.
-     * @return The marshalled object, or {@code null} if and only if the given {@code object}
was null.
+     * @param  object The object to marshal.
+     * @return The marshalled object.
      * @throws JAXBException If an error occurred while marshalling the object.
      */
     protected final String marshal(final Marshaller marshaller, final Object object) throws
JAXBException {
         ArgumentChecks.ensureNonNull("marshaller", marshaller);
+        ArgumentChecks.ensureNonNull("object", object);
         if (buffer == null) {
             buffer = new StringWriter();
         }
@@ -150,15 +166,34 @@ public abstract strictfp class XMLTestCa
     }
 
     /**
+     * Unmarshals the given object using the {@linkplain #getMarshallerPool() test marshaller
pool}.
+     *
+     * @param  <T>  Compile-time type of {@code type} argument.
+     * @param  type The expected type of the unmarshalled object.
+     * @param  xml  The XML representation of the object to unmarshal.
+     * @return The unmarshalled object.
+     * @throws JAXBException If an error occurred while unmarshalling the XML.
+     */
+    protected final <T> T unmarshal(final Class<T> type, final String xml) throws
JAXBException {
+        final MarshallerPool pool = getMarshallerPool();
+        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        final Object object = unmarshal(unmarshaller, xml);
+        pool.recycle(unmarshaller);
+        assertInstanceOf("unmarshal", type, object);
+        return type.cast(object);
+    }
+
+    /**
      * Unmarshals the given XML using the given unmarshaler.
      *
      * @param  unmarshaller The unmarshaller to use.
-     * @param  xml The XML representation of the object to unmarshal, or {@code null}.
-     * @return The unmarshalled object, or {@code null} if and only if the given {@code xml}
was null.
+     * @param  xml The XML representation of the object to unmarshal.
+     * @return The unmarshalled object.
      * @throws JAXBException If an error occurred while unmarshalling the XML.
      */
     protected final Object unmarshal(final Unmarshaller unmarshaller, final String xml) throws
JAXBException {
         ArgumentChecks.ensureNonNull("unmarshaller", unmarshaller);
+        ArgumentChecks.ensureNonNull("xml", xml);
         return unmarshaller.unmarshal(new StringReader(xml));
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -87,6 +87,7 @@ import org.junit.BeforeClass;
     org.apache.sis.util.iso.DefaultNameFactoryTest.class,
 
     // Measurements and formatting.
+    org.apache.sis.measure.SexagesimalConverterTest.class,
     org.apache.sis.measure.UnitsTest.class,
     org.apache.sis.measure.RangeTest.class,
     org.apache.sis.measure.DateRangeTest.class,

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -464,6 +464,17 @@ public final strictfp class CharSequence
     }
 
     /**
+     * Tests the {@link CharSequences#replace(CharSequence, CharSequence, CharSequence)}
method.
+     */
+    @Test
+    public void testReplace() {
+        final String text = "One apple, two orange oranges";
+        assertSame(text, replace(text, "pineapple", "orange"));
+        assertEquals("One orange, two orange oranges", replace(text, "apple", "orange").toString());
+        assertEquals("One apple, two apple apples",    replace(text, "orange", "apple").toString());
+    }
+
+    /**
      * Tests the {@link CharSequences#copyChars(CharSequence, int, char[], int, int)} method.
      */
     @Test

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -59,8 +59,9 @@ public final strictfp class MonolineForm
      */
     private static String localize(final Level level, final String expected) {
         final String label = level.getLocalizedName();
-        return expected.replace(level.getName(), label)
-                .replace("\t", CharSequences.spaces(MonolineFormatter.levelWidth(null) -
label.length()));
+        CharSequence text = CharSequences.replace(expected, level.getName(), label);
+        text = CharSequences.replace(text, "\t", CharSequences.spaces(MonolineFormatter.levelWidth(null)
- label.length()));
+        return text.toString();
     }
 
     /**

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java
[UTF-8] Wed Dec  4 22:34:18 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -180,7 +181,7 @@ public final strictfp class IOUtilitiesT
         assertEquals("Path with space.", new File("/Users/name/Map with spaces.png"),
                 IOUtilities.toFile(new URL("file:/Users/name/Map with spaces.png"), encoding));
         assertEquals("Path with + sign.", new File("/Users/name/++t--++est.shp"),
-                IOUtilities.toFile(new URL("file:/Users/name/++t--++est.shp".replace("+",
plus)), encoding));
+                IOUtilities.toFile(new URL(CharSequences.replace("file:/Users/name/++t--++est.shp",
"+", plus).toString()), encoding));
     }
 
     /**



Mime
View raw message