tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [32/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-87 Implemeted support for org.joda.time.DateTimeZone.
Date Tue, 06 Sep 2016 17:18:28 GMT
TAMAYA-87 Implemeted support for org.joda.time.DateTimeZone.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/b4586e1d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/b4586e1d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/b4586e1d

Branch: refs/heads/master
Commit: b4586e1db25d8ddd5f0f725c3690c6ff29496ead
Parents: 1b70d6a
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Sun Mar 6 23:24:01 2016 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Sun Mar 6 23:24:01 2016 +0100

----------------------------------------------------------------------
 .../tamaya/jodatime/DateTimeZoneConverter.java  | 22 +++++++++++++++++---
 .../jodatime/DateTimeZoneConverterTest.java     | 20 ++++++++++++++----
 2 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/b4586e1d/jodatime/src/main/java/org/apache/tamaya/jodatime/DateTimeZoneConverter.java
----------------------------------------------------------------------
diff --git a/jodatime/src/main/java/org/apache/tamaya/jodatime/DateTimeZoneConverter.java
b/jodatime/src/main/java/org/apache/tamaya/jodatime/DateTimeZoneConverter.java
index bf18393..198a345 100644
--- a/jodatime/src/main/java/org/apache/tamaya/jodatime/DateTimeZoneConverter.java
+++ b/jodatime/src/main/java/org/apache/tamaya/jodatime/DateTimeZoneConverter.java
@@ -26,14 +26,25 @@ import java.util.regex.Pattern;
 
 import static java.util.Objects.requireNonNull;
 
+/**
+ * Converter, converting from {@code String} to Joda-Time's
+ * {@code DateTimeZone}.
+ *
+ * This converter supports the conversion from a numerich time zone
+ * information in the format {@code [+-]hh:mm} as well as from
+ * all time zone ids supported by Joda Time.
+ *
+ * @see DateTimeZone
+ * @see DateTimeZone#getAvailableIDs()
+ */
 public class DateTimeZoneConverter implements PropertyConverter<DateTimeZone> {
-    private static final Pattern IS_INTEGER_VALUE = Pattern.compile("(\\+|-)?\\d+");
+    private static final String PATTERN_REGEX = "(\\+|-)?\\d+";
+    private static final Pattern IS_INTEGER_VALUE = Pattern.compile(PATTERN_REGEX);
 
     @Override
     public DateTimeZone convert(String value, ConversionContext context) {
-        if (true == true) throw new RuntimeException("Method must catch up with the current
API!");
-
         String trimmed = requireNonNull(value).trim();
+        addSupportedFormats(context);
 
         DateTimeZone result = null;
 
@@ -52,6 +63,11 @@ public class DateTimeZoneConverter implements PropertyConverter<DateTimeZone>
{
         return result;
     }
 
+    private void addSupportedFormats(ConversionContext context) {
+        context.addSupportedFormats(DateTimeZoneConverter.class, "Time zone in the form [+-]hh:mm
via the regex " + PATTERN_REGEX);
+        context.addSupportedFormats(DateTimeZoneConverter.class, "All time zone ids supported
by Joda Time");
+    }
+
     private boolean isSingleIntegerValue(String value) {
         boolean match = IS_INTEGER_VALUE.matcher(value).matches();
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/b4586e1d/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
----------------------------------------------------------------------
diff --git a/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
b/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
index 6620044..babbe06 100644
--- a/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
+++ b/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
@@ -18,7 +18,9 @@
  */
 package org.apache.tamaya.jodatime;
 
+import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.ConversionContext.Builder;
 import org.joda.time.DateTimeZone;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -28,11 +30,13 @@ import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
 
 public class DateTimeZoneConverterTest {
     private DateTimeZoneConverter converter = new DateTimeZoneConverter();
 
-    @Ignore
     @Test
     public void canConvertDateTimeZoneInformation() {
         Object[][] inputResultPairs = {
@@ -63,7 +67,6 @@ public class DateTimeZoneConverterTest {
         }
     }
 
-    @Ignore
     @Test
     public void invalidInputValuesResultInReturningNull() {
         String[] inputValues = {
@@ -83,10 +86,19 @@ public class DateTimeZoneConverterTest {
         }
     }
 
-    @Ignore
     @Test
     public void allSupportedFormatsAreAddedToTheConversionContext() {
-        if (true == true) throw new RuntimeException("Method must catch up with the current
API!");
+        String firstFormat = "Time zone in the form [+-]hh:mm via the regex (\\+|-)?\\d+
(DateTimeZoneConverter)";
+        String secondFormat = "All time zone ids supported by Joda Time (DateTimeZoneConverter)";
+
+        ConversionContext context = new Builder(TypeLiteral.of(DateTimeZone.class)).build();
+
+        DateTimeZone result = converter.convert("+01:00", context);
+
+        assertThat(result, notNullValue());
+        assertThat(context.getSupportedFormats(), hasSize(2));
+        assertThat(context.getSupportedFormats(), hasItem(firstFormat));
+        assertThat(context.getSupportedFormats(), hasItem(secondFormat));
     }
 
 }


Mime
View raw message