sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1401236 [2/2] - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/math/ main/java/org/apache/sis/measure/ main/java/org/apache/sis/util/ main/java/org/apache/sis/util/logging/ main/java/org/apache/sis/util/resources/ test/jav...
Date Tue, 23 Oct 2012 10:11:35 GMT
Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Localized.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Localized.java?rev=1401236&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Localized.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Localized.java Tue Oct
23 10:11:34 2012
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util;
+
+import java.util.Locale;
+
+
+/**
+ * Interface of localized services (parser, formatter, codes, <i>etc.</i>).
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.05)
+ * @version 0.3
+ * @module
+ */
+public interface Localized {
+    /**
+     * Returns the locale of the implemented service. Some implementations may return
+     * {@code null} if no locale is explicitly defined. In such case, the locale to use
+     * is typically the {@linkplain Locale#getDefault() default} locale.
+     *
+     * @return The locale, or {@code null} if not explicitly defined.
+     */
+    Locale getLocale();
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Localized.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Localized.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java?rev=1401236&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java
Tue Oct 23 10:11:34 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util;
+
+import java.util.Locale;
+
+
+/**
+ * An exception which can produce an error message in the given locale.
+ * Exceptions implementing this interface uses the following policy:
+ *
+ * <ul>
+ *   <li>{@link Throwable#getMessage()} returns the message in the {@linkplain Locale#getDefault()
default locale}.
+ *       In a client-server architecture, this is often the locale on the server side.</li>
+ *   <li>{@link Throwable#getLocalizedMessage()} returns the message in the locale
returned by the
+ *       {@link #getLocale()} method. This is often the locale used by a {@link java.text.Format}
+ *       object for example, and can be presumed to be the locale on the client side.</li>
+ *   <li>{@link #getMessage(Locale)} returns the message in the given locale.
+ *       This method is specific to Apache SIS however.</li>
+ * </ul>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ *
+ * @see Exceptions#getMessage(Throwable, Locale)
+ */
+interface LocalizedException extends Localized {
+    /**
+     * The locale of the string returned by {@link #getLocalizedMessage()}.
+     *
+     * @return The locale of the localized exception message.
+     */
+    @Override
+    Locale getLocale();
+
+    /**
+     * Returns the message in the default locale.
+     *
+     * @return The exception message in the default locale.
+     */
+    String getMessage();
+
+    /**
+     * Returns the message in the locale specified by {@link #getLocale()}.
+     *
+     * @return The localized exception message.
+     */
+    String getLocalizedMessage();
+
+    /**
+     * Returns the message in the given locale.
+     *
+     * @param  locale The locale of the message to produce, or {@code null} for the default
locale.
+     * @return The exception message in the given locale.
+     */
+    String getMessage(Locale locale);
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java?rev=1401236&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java
Tue Oct 23 10:11:34 2012
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util;
+
+import java.util.Locale;
+import java.text.ParseException;
+import java.text.ParsePosition;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * A {@link ParseException} in which {@link #getLocalizedMessage()} returns the message in
the
+ * parser locale.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+final class LocalizedParseException extends ParseException implements LocalizedException
{
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = 8240939095802384277L;
+
+    /**
+     * The locale to use for formatting the localized error message.
+     */
+    private final Locale locale;
+
+    /**
+     * The arguments for the localization message, as an array of length 1, 2 or 3.
+     *
+     * <ul>
+     *   <li>The type of objects to be parsed, as a {@link Class}.
+     *       Omitted if the error is "unexpected end of string".</li>
+     *   <li>The text to be parsed, as a {@link String}.</li>
+     *   <li>The characters that couldn't be parsed. Omitted if empty.</li>
+     * </ul>
+     */
+    private final Object[] arguments;
+
+    /**
+     * Constructs a ParseException with the specified detail message and offset.
+     *
+     * @param locale      The locale for {@link #getLocalizedMessage()}.
+     * @param arguments   The value of {@link #arguments(String, ParsePosition)}.
+     * @param errorOffset The position where the error is found while parsing.
+     */
+    LocalizedParseException(final Locale locale, final Object[] arguments, final int errorOffset)
{
+        super(message(locale, arguments), errorOffset);
+        this.locale    = locale;
+        this.arguments = arguments;
+    }
+
+    /**
+     * Workaround for RFE #4093999
+     * ("Relax constraint on placement of this()/super() call in constructors").
+     *
+     * @param  type        The type of objects parsed by the {@link java.text.Format}.
+     * @param  text        The text that {@code Format} failed to parse.
+     * @param  offset      Index of the first character to parse in {@code text}.
+     * @param  errorOffset The position where the error is found while parsing.
+     * @return The {@code arguments} value to give to the constructor.
+     */
+    @Workaround(library="JDK", version="1.7")
+    static Object[] arguments(final Class<?> type, String text, final int offset, final
int errorOffset) {
+        if (errorOffset >= text.length()) {
+            return new Object[] {text};
+        }
+        final String erroneous = CharSequences.token(text, errorOffset).toString();
+        text = text.substring(offset);
+        if (erroneous.isEmpty()) {
+            return new Object[] {type, text};
+        }
+        return new Object[] {type, text, erroneous};
+    }
+
+    /**
+     * Formats the error message using the given locale and arguments.
+     */
+    private static String message(final Locale locale, final Object[] arguments) {
+        final int key;
+        switch (arguments.length) {
+            case 1: key = Errors.Keys.UnexpectedEndOfString_1;    break;
+            case 2: key = Errors.Keys.UnparsableStringForClass_2; break;
+            case 3: key = Errors.Keys.UnparsableStringForClass_3; break;
+            default: throw new AssertionError();
+        }
+        return Errors.getResources(locale).getString(key, arguments);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Locale getLocale() {
+        return locale;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getLocalizedMessage() {
+        return message(locale, arguments);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getMessage(final Locale locale) {
+        return message(locale, arguments);
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1401236&r1=1401235&r2=1401236&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java Tue
Oct 23 10:11:34 2012
@@ -550,7 +550,7 @@ public final class Logging extends Stati
             buffer.append(": ").append(message);
         }
         message = buffer.toString();
-        message = Exceptions.formatChainedMessages(message, error);
+        message = Exceptions.formatChainedMessages(null, message, error);
         final LogRecord record = new LogRecord(level, message);
         if (classe != null) {
             record.setSourceClassName(classe);

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1401236&r1=1401235&r2=1401236&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
Tue Oct 23 10:11:34 2012
@@ -87,6 +87,11 @@ public final class Errors extends Indexe
         public static final int IllegalClass_2 = 3;
 
         /**
+         * The “{0}” pattern can not be applied to formating of objects of type
‘{1}’.
+         */
+        public static final int IllegalFormatPatternForClass_2 = 29;
+
+        /**
          * The “{0}” language is not recognized.
          */
         public static final int IllegalLanguageCode_1 = 12;
@@ -147,6 +152,11 @@ public final class Errors extends Indexe
         public static final int UnexpectedArgumentDimension_3 = 5;
 
         /**
+         * More characters were expected at the end of “{0}”.
+         */
+        public static final int UnexpectedEndOfString_1 = 30;
+
+        /**
          * This affine transform is unmodifiable.
          */
         public static final int UnmodifiableAffineTransform = 23;
@@ -167,6 +177,16 @@ public final class Errors extends Indexe
         public static final int UnmodifiableObject_1 = 26;
 
         /**
+         * Text “{1}” can not be parsed as an object of type ‘{0}’.
+         */
+        public static final int UnparsableStringForClass_2 = 31;
+
+        /**
+         * Text “{1}” can not be parsed as an object of type ‘{0}’, because
of the “{2}” characters.
+         */
+        public static final int UnparsableStringForClass_3 = 32;
+
+        /**
          * Can not handle instances of ‘{0}’ because arbitrary implementations
are not yet supported.
          */
         public static final int UnsupportedImplementation_1 = 28;

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1401236&r1=1401235&r2=1401236&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
Tue Oct 23 10:11:34 2012
@@ -22,6 +22,7 @@ IllegalArgumentClass_3          = Argume
 IllegalArgumentValue_2          = Argument \u2018{0}\u2019 can not take the \u201c{1}\u201d
value.
 IllegalBitsPattern_1            = Illegal bits pattern: {0}.
 IllegalClass_2                  = Class \u2018{0}\u2019 is illegal. It must be \u2018{1}\u2019
or a derived class.
+IllegalFormatPatternForClass_2  = The \u201c{0}\u201d pattern can not be applied to formating
of objects of type \u2018{1}\u2019.
 IllegalLanguageCode_1           = The \u201c{0}\u201d language is not recognized.
 IllegalRange_2                  = Range [{0} \u2026 {1}] is not valid.
 InconsistentAttribute_2         = Value \u201c{1}\u201d of attribute \u2018{0}\u2019 is inconsistent
with other attributes.
@@ -34,10 +35,13 @@ NotAPrimitiveWrapper_1          = Class 
 NullArgument_1                  = Argument \u2018{0}\u2019 shall not be null.
 RecursiveCreateCallForKey_1     = Recursive call while creating an object for the \u201c{0}\u201d
key.
 UnexpectedArgumentDimension_3   = Argument \u2018{0}\u2019 has {1} dimensions, while {2}
was expected.
+UnexpectedEndOfString_1         = More characters were expected at the end of \u201c{0}\u201d.
 UnmodifiableAffineTransform     = This affine transform is unmodifiable.
 UnmodifiableGeometry            = This geometry is unmodifiable.
 UnmodifiableMetadata            = This metadata is unmodifiable.
 UnmodifiableObject_1            = Object \u2018{0}\u2019 is unmodifiable.
+UnparsableStringForClass_2      = Text \u201c{1}\u201d can not be parsed as an object of
type \u2018{0}\u2019.
+UnparsableStringForClass_3      = Text \u201c{1}\u201d can not be parsed as an object of
type \u2018{0}\u2019, because of the \u201c{2}\u201d characters.
 UnsupportedImplementation_1     = Can not handle instances of \u2018{0}\u2019 because arbitrary
implementations are not yet supported.
 UnsupportedOperation_1          = The \u2018{0}\u2019 operation is unsupported.
 ValueAlreadyDefined_1           = A value is already defined for \u201c{0}\u201d.

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1401236&r1=1401235&r2=1401236&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
Tue Oct 23 10:11:34 2012
@@ -22,6 +22,7 @@ IllegalArgumentClass_3          = L\u201
 IllegalArgumentValue_2          = L\u2019argument \u2018{0}\u2019 n\u2019accepte pas la valeur
\u201c{1}\u201d.
 IllegalBitsPattern_1            = Pattern de bits invalide: {0}.
 IllegalClass_2                  = La classe \u2018{0}\u2019 est ill\u00e9gale. Il doit s\u2019agir
d\u2019une classe \u2018{1}\u2019 ou d\u00e9riv\u00e9e.
+IllegalFormatPatternForClass_2  = Le mod\u00e8le \u201c{0}\u201d ne peut pas \u00eatre appliqu\u00e9
au formatage d\u2019objets de type \u2018{1}\u2019.
 IllegalLanguageCode_1           = Le code de langue \u201c{0}\u201d n\u2019est pas reconnu.
 IllegalRange_2                  = La plage [{0} \u2026 {1}] n\u2019est pas valide.
 InconsistentAttribute_2         = La valeur \u201c{1}\u201d de l\u2019attribut \u2018{0}\u2019
n\u2019est pas coh\u00e9rente avec celles des autres attributs.
@@ -34,10 +35,13 @@ NotAPrimitiveWrapper_1          = La cla
 NullArgument_1                  = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre nul.
 RecursiveCreateCallForKey_1     = Appel r\u00e9cursif lors de la cr\u00e9ation d\u2019un
objet pour la cl\u00e9 \u201c{0}\u201d.
 UnexpectedArgumentDimension_3   = L\u2019argument \u2018{0}\u2019 a {1} dimensions, alors
qu\u2019on en attendait {2}.
+UnexpectedEndOfString_1         = D\u2019autres caract\u00e8res \u00e9taient attendus \u00e0
la fin du texte \u201c{0}\u201d.
 UnmodifiableAffineTransform     = Cette transformation affine n\u2019est pas modifiable.
 UnmodifiableGeometry            = Cette g\u00e9om\u00e9trie n\u2019est pas modifiable.
 UnmodifiableMetadata            = Cette m\u00e9ta-donn\u00e9e n\u2019est pas modifiable.
 UnmodifiableObject_1            = L\u2019objet \u2018{0}\u2019 n\u2019est pas modifiable.
+UnparsableStringForClass_2      = Le texte \u201c{1}\u201d n\u2019est pas reconnu comme un
objet de type \u2018{0}\u2019.
+UnparsableStringForClass_3      = Le texte \u201c{1}\u201d n\u2019est pas reconnu comme un
objet de type \u2018{0}\u2019, \u00e0 cause des caract\u00e8res \u201c{2}\u201d.
 UnsupportedImplementation_1     = Les instances de \u2018{0}\u2019 ne peuvent pas \u00eatre
g\u00e9r\u00e9es parce que les impl\u00e9mentations arbitraires ne sont pas encore support\u00e9es.
 UnsupportedOperation_1          = L\u2019op\u00e9ration \u2018{0}\u2019 n\u2019est pas support\u00e9e.
 ValueAlreadyDefined_1           = Une valeur est d\u00e9j\u00e0 d\u00e9finie pour \u201c{0}\u201d.

Added: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java?rev=1401236&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
(added)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
Tue Oct 23 10:11:34 2012
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.measure;
+
+import java.util.Locale;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.math.MathFunctionsTest;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.apache.sis.test.TestUtilities.*;
+
+
+/**
+ * Tests parsing and formatting done by the {@link AngleFormat} class.
+ *
+ * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
+ * @since   0.3 (derived from geotk-2.0)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(MathFunctionsTest.class)
+public final strictfp class AngleFormatTest extends TestCase {
+    /**
+     * Tests using {@link Locale#CANADA}.
+     */
+    @Test
+    public void testCanadaLocale() {
+        final AngleFormat f = new AngleFormat("DD.ddd°", Locale.CANADA);
+        assertEquals( "20.000°",  formatAndParse(f, new Angle   ( 20.000)));
+        assertEquals( "20.749°",  formatAndParse(f, new Angle   ( 20.749)));
+        assertEquals("-12.247°",  formatAndParse(f, new Angle   (-12.247)));
+        assertEquals( "13.214°N", formatAndParse(f, new Latitude( 13.214)));
+        assertEquals( "12.782°S", formatAndParse(f, new Latitude(-12.782)));
+    }
+
+    /**
+     * Tests using {@link Locale#FRANCE}.
+     */
+    @Test
+    public void testFranceLocale() {
+        final AngleFormat f = new AngleFormat("DD.ddd°", Locale.FRANCE);
+        assertEquals("19,457°E", formatAndParse(f, new Longitude( 19.457)));
+        assertEquals("78,124°S", formatAndParse(f, new Latitude (-78.124)));
+    }
+
+    /**
+     * Tests with no decimal separator.
+     */
+    @Test
+    public void testNoSeparator() {
+        final AngleFormat f = new AngleFormat("DDddd", Locale.CANADA);
+        assertEquals("19457E", formatAndParse(f, new Longitude( 19.457)));
+        assertEquals("78124S", formatAndParse(f, new Latitude (-78.124)));
+    }
+
+    /**
+     * Tests with the degree separator.
+     */
+    @Test
+    public void testDegreeSeparator() {
+        final AngleFormat f = new AngleFormat("DD°MM.m", Locale.CANADA);
+        assertEquals( "12°30.0", formatAndParse(f, new Angle( 12.50)));
+        assertEquals("-10°15.0", formatAndParse(f, new Angle(-10.25)));
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java?rev=1401236&r1=1401235&r2=1401236&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java Tue
Oct 23 10:11:34 2012
@@ -22,6 +22,7 @@ import java.util.TimeZone;
 import java.util.Iterator;
 import java.util.concurrent.Callable;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.text.Format;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -97,6 +98,26 @@ public final strictfp class TestUtilitie
     }
 
     /**
+     * Formats the given value using the given formatter, and parses the text back to its
value.
+     * If the parsed value is not equal to the original one, an {@link AssertionError} is
thrown.
+     *
+     * @param  formatter The formatter to use for formatting and parsing.
+     * @param  value The value to format.
+     * @return The formatted value.
+     */
+    public static String formatAndParse(final Format formatter, final Object value) {
+        final String text = formatter.format(value);
+        final Object parsed;
+        try {
+            parsed = formatter.parseObject(text);
+        } catch (ParseException e) {
+            throw new AssertionError(e);
+        }
+        assertEquals("Parsed text not equal to the original value", value, parsed);
+        return text;
+    }
+
+    /**
      * Returns the single element from the given collection. If the given collection is null
      * or does not contains exactly one element, then an {@link AssertionError} is thrown.
      *

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1401236&r1=1401235&r2=1401236&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Tue Oct 23 10:11:34 2012
@@ -46,6 +46,7 @@ import org.junit.runners.Suite;
   org.apache.sis.util.type.SimpleInternationalStringTest.class,
   org.apache.sis.util.type.DefaultInternationalStringTest.class,
   org.apache.sis.math.MathFunctionsTest.class,
+  org.apache.sis.measure.AngleFormatTest.class,
   org.apache.sis.internal.util.ReferenceQueueConsumerTest.class,
   org.apache.sis.util.collection.WeakHashSetTest.class,
   org.apache.sis.util.collection.WeakValueHashMapTest.class,



Mime
View raw message