test/java/time/test/java/time/TestZoneId.java

Print this page

        

@@ -57,55 +57,50 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 package test.java.time;
 
-import java.time.*;
-
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
-import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.SimpleTimeZone;
-import java.util.TimeZone;
-
-import java.time.temporal.Queries;
-import java.time.temporal.TemporalQuery;
-import java.time.temporal.TemporalAccessor;
-import java.time.temporal.TemporalField;
+import java.time.DateTimeException;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.time.format.TextStyle;
 import java.time.zone.ZoneOffsetTransition;
 import java.time.zone.ZoneRules;
 import java.time.zone.ZoneRulesException;
+import java.util.List;
+import java.util.Locale;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
 
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 /**
  * Test ZoneId.
  */
 @Test
 public class TestZoneId extends AbstractTest {
 
-    private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
-    public static final String LATEST_TZDB = "2010i";
     private static final int OVERLAP = 2;
     private static final int GAP = 0;
 
     //-----------------------------------------------------------------------
     // Basics
     //-----------------------------------------------------------------------
     public void test_immutable() {
+        // cannot use standard test as ZoneId is abstract
         Class<ZoneId> cls = ZoneId.class;
         assertTrue(Modifier.isPublic(cls.getModifiers()));
         Field[] fields = cls.getDeclaredFields();
         for (Field field : fields) {
             if (Modifier.isStatic(field.getModifiers()) == false) {

@@ -114,131 +109,31 @@
                         (Modifier.isVolatile(field.getModifiers()) && Modifier.isTransient(field.getModifiers())));
             }
         }
     }
 
-    public void test_serialization_UTC() throws Exception {
-        ZoneId test = ZoneOffset.UTC;
-        assertSerializableAndSame(test);
-    }
-
-    public void test_serialization_fixed() throws Exception {
-        ZoneId test = ZoneId.of("UTC+01:30");
-        assertSerializable(test);
-    }
-
-    public void test_serialization_Europe() throws Exception {
-        ZoneId test = ZoneId.of("Europe/London");
-        assertSerializable(test);
-    }
-
-    public void test_serialization_America() throws Exception {
-        ZoneId test = ZoneId.of("America/Chicago");
-        assertSerializable(test);
-    }
-
     //-----------------------------------------------------------------------
     // UTC
     //-----------------------------------------------------------------------
     public void test_constant_UTC() {
         ZoneId test = ZoneOffset.UTC;
         assertEquals(test.getId(), "Z");
-        assertEquals(test.getText(TextStyle.FULL, Locale.UK), "Z");
+        assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), "Z");
         assertEquals(test.getRules().isFixedOffset(), true);
         assertEquals(test.getRules().getOffset(Instant.ofEpochSecond(0L)), ZoneOffset.UTC);
         checkOffset(test.getRules(), createLDT(2008, 6, 30), ZoneOffset.UTC, 1);
         assertSame(test, ZoneId.of("UTC+00"));
     }
 
     //-----------------------------------------------------------------------
-    // OLD_IDS_PRE_2005
-    //-----------------------------------------------------------------------
-    public void test_constant_OLD_IDS_PRE_2005() {
-        Map<String, String> ids = ZoneId.OLD_IDS_PRE_2005;
-        assertEquals(ids.get("EST"), "America/Indianapolis");
-        assertEquals(ids.get("MST"), "America/Phoenix");
-        assertEquals(ids.get("HST"), "Pacific/Honolulu");
-        assertEquals(ids.get("ACT"), "Australia/Darwin");
-        assertEquals(ids.get("AET"), "Australia/Sydney");
-        assertEquals(ids.get("AGT"), "America/Argentina/Buenos_Aires");
-        assertEquals(ids.get("ART"), "Africa/Cairo");
-        assertEquals(ids.get("AST"), "America/Anchorage");
-        assertEquals(ids.get("BET"), "America/Sao_Paulo");
-        assertEquals(ids.get("BST"), "Asia/Dhaka");
-        assertEquals(ids.get("CAT"), "Africa/Harare");
-        assertEquals(ids.get("CNT"), "America/St_Johns");
-        assertEquals(ids.get("CST"), "America/Chicago");
-        assertEquals(ids.get("CTT"), "Asia/Shanghai");
-        assertEquals(ids.get("EAT"), "Africa/Addis_Ababa");
-        assertEquals(ids.get("ECT"), "Europe/Paris");
-        assertEquals(ids.get("IET"), "America/Indiana/Indianapolis");
-        assertEquals(ids.get("IST"), "Asia/Kolkata");
-        assertEquals(ids.get("JST"), "Asia/Tokyo");
-        assertEquals(ids.get("MIT"), "Pacific/Apia");
-        assertEquals(ids.get("NET"), "Asia/Yerevan");
-        assertEquals(ids.get("NST"), "Pacific/Auckland");
-        assertEquals(ids.get("PLT"), "Asia/Karachi");
-        assertEquals(ids.get("PNT"), "America/Phoenix");
-        assertEquals(ids.get("PRT"), "America/Puerto_Rico");
-        assertEquals(ids.get("PST"), "America/Los_Angeles");
-        assertEquals(ids.get("SST"), "Pacific/Guadalcanal");
-        assertEquals(ids.get("VST"), "Asia/Ho_Chi_Minh");
-    }
-
-    @Test(expectedExceptions=UnsupportedOperationException.class)
-    public void test_constant_OLD_IDS_PRE_2005_immutable() {
-        Map<String, String> ids = ZoneId.OLD_IDS_PRE_2005;
-        ids.clear();
-    }
-
-    //-----------------------------------------------------------------------
-    // OLD_IDS_POST_2005
-    //-----------------------------------------------------------------------
-    public void test_constant_OLD_IDS_POST_2005() {
-        Map<String, String> ids = ZoneId.OLD_IDS_POST_2005;
-        assertEquals(ids.get("EST"), "-05:00");
-        assertEquals(ids.get("MST"), "-07:00");
-        assertEquals(ids.get("HST"), "-10:00");
-        assertEquals(ids.get("ACT"), "Australia/Darwin");
-        assertEquals(ids.get("AET"), "Australia/Sydney");
-        assertEquals(ids.get("AGT"), "America/Argentina/Buenos_Aires");
-        assertEquals(ids.get("ART"), "Africa/Cairo");
-        assertEquals(ids.get("AST"), "America/Anchorage");
-        assertEquals(ids.get("BET"), "America/Sao_Paulo");
-        assertEquals(ids.get("BST"), "Asia/Dhaka");
-        assertEquals(ids.get("CAT"), "Africa/Harare");
-        assertEquals(ids.get("CNT"), "America/St_Johns");
-        assertEquals(ids.get("CST"), "America/Chicago");
-        assertEquals(ids.get("CTT"), "Asia/Shanghai");
-        assertEquals(ids.get("EAT"), "Africa/Addis_Ababa");
-        assertEquals(ids.get("ECT"), "Europe/Paris");
-        assertEquals(ids.get("IET"), "America/Indiana/Indianapolis");
-        assertEquals(ids.get("IST"), "Asia/Kolkata");
-        assertEquals(ids.get("JST"), "Asia/Tokyo");
-        assertEquals(ids.get("MIT"), "Pacific/Apia");
-        assertEquals(ids.get("NET"), "Asia/Yerevan");
-        assertEquals(ids.get("NST"), "Pacific/Auckland");
-        assertEquals(ids.get("PLT"), "Asia/Karachi");
-        assertEquals(ids.get("PNT"), "America/Phoenix");
-        assertEquals(ids.get("PRT"), "America/Puerto_Rico");
-        assertEquals(ids.get("PST"), "America/Los_Angeles");
-        assertEquals(ids.get("SST"), "Pacific/Guadalcanal");
-        assertEquals(ids.get("VST"), "Asia/Ho_Chi_Minh");
-    }
-
-    @Test(expectedExceptions=UnsupportedOperationException.class)
-    public void test_constant_OLD_IDS_POST_2005_immutable() {
-        Map<String, String> ids = ZoneId.OLD_IDS_POST_2005;
-        ids.clear();
-    }
-
-    //-----------------------------------------------------------------------
     // system default
     //-----------------------------------------------------------------------
     public void test_systemDefault() {
         ZoneId test = ZoneId.systemDefault();
-        assertEquals(test.getId(), TimeZone.getDefault().getID());
+        assertEquals(test.getId(), TimeZone.getDefault()
+                                           .getID()
+                                           .replaceAll("GMT|UTC|UT", "Z"));
     }
 
     @Test(expectedExceptions = DateTimeException.class)
     public void test_systemDefault_unableToConvert_badFormat() {
         TimeZone current = TimeZone.getDefault();

@@ -260,75 +155,13 @@
             TimeZone.setDefault(current);
         }
     }
 
     //-----------------------------------------------------------------------
-    // mapped factory
-    //-----------------------------------------------------------------------
-    public void test_of_string_Map() {
-        Map<String, String> map = new HashMap<String, String>();
-        map.put("LONDON", "Europe/London");
-        map.put("PARIS", "Europe/Paris");
-        ZoneId test = ZoneId.of("LONDON", map);
-        assertEquals(test.getId(), "Europe/London");
-    }
-
-    public void test_of_string_Map_lookThrough() {
-        Map<String, String> map = new HashMap<String, String>();
-        map.put("LONDON", "Europe/London");
-        map.put("PARIS", "Europe/Paris");
-        ZoneId test = ZoneId.of("Europe/Madrid", map);
-        assertEquals(test.getId(), "Europe/Madrid");
-    }
-
-    public void test_of_string_Map_emptyMap() {
-        Map<String, String> map = new HashMap<String, String>();
-        ZoneId test = ZoneId.of("Europe/Madrid", map);
-        assertEquals(test.getId(), "Europe/Madrid");
-    }
-
-    @Test(expectedExceptions=DateTimeException.class)
-    public void test_of_string_Map_badFormat() {
-        Map<String, String> map = new HashMap<String, String>();
-        ZoneId.of("Not kknown", map);
-    }
-
-    @Test(expectedExceptions=ZoneRulesException.class)
-    public void test_of_string_Map_unknown() {
-        Map<String, String> map = new HashMap<String, String>();
-        ZoneId.of("Unknown", map);
-    }
-
-    //-----------------------------------------------------------------------
-    // regular factory
-    //-----------------------------------------------------------------------
-    @DataProvider(name="String_UTC")
-    Object[][] data_of_string_UTC() {
-        return new Object[][] {
-            {""}, {"Z"},
-            {"+00"},{"+0000"},{"+00:00"},{"+000000"},{"+00:00:00"},
-            {"-00"},{"-0000"},{"-00:00"},{"-000000"},{"-00:00:00"},
-        };
-    }
-
-    @Test(dataProvider="String_UTC")
-    public void test_of_string_UTC(String id) {
-        ZoneId test = ZoneId.of("UTC" + id);
-        assertSame(test, ZoneOffset.UTC);
-    }
-
-    @Test(dataProvider="String_UTC")
-    public void test_of_string_GMT(String id) {
-        ZoneId test = ZoneId.of("GMT" + id);
-        assertSame(test, ZoneOffset.UTC);
-    }
-
-    //-----------------------------------------------------------------------
     @DataProvider(name="String_Fixed")
     Object[][] data_of_string_Fixed() {
         return new Object[][] {
-            {"Z", "Z"},
             {"+0", "Z"},
             {"+5", "+05:00"},
             {"+01", "+01:00"},
             {"+0100", "+01:00"},{"+01:00", "+01:00"},
             {"+010000", "+01:00"},{"+01:00:00", "+01:00"},

@@ -344,170 +177,40 @@
 
     @Test(dataProvider="String_Fixed")
     public void test_of_string_offset(String input, String id) {
         ZoneId test = ZoneId.of(input);
         assertEquals(test.getId(), id);
-        assertEquals(test.getText(TextStyle.FULL, Locale.UK), id);
+        assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), id);
         assertEquals(test.getRules().isFixedOffset(), true);
         ZoneOffset offset = ZoneOffset.of(id);
         assertEquals(test.getRules().getOffset(Instant.ofEpochSecond(0L)), offset);
         checkOffset(test.getRules(), createLDT(2008, 6, 30), offset, 1);
     }
 
     @Test(dataProvider="String_Fixed")
     public void test_of_string_FixedUTC(String input, String id) {
         ZoneId test = ZoneId.of("UTC" + input);
         assertEquals(test.getId(), id);
-        assertEquals(test.getText(TextStyle.FULL, Locale.UK), id);
+        assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), id);
         assertEquals(test.getRules().isFixedOffset(), true);
         ZoneOffset offset = ZoneOffset.of(id);
         assertEquals(test.getRules().getOffset(Instant.ofEpochSecond(0L)), offset);
         checkOffset(test.getRules(), createLDT(2008, 6, 30), offset, 1);
     }
 
     @Test(dataProvider="String_Fixed")
     public void test_of_string_FixedGMT(String input, String id) {
         ZoneId test = ZoneId.of("GMT" + input);
         assertEquals(test.getId(), id);
-        assertEquals(test.getText(TextStyle.FULL, Locale.UK), id);
+        assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), id);
         assertEquals(test.getRules().isFixedOffset(), true);
         ZoneOffset offset = ZoneOffset.of(id);
         assertEquals(test.getRules().getOffset(Instant.ofEpochSecond(0L)), offset);
         checkOffset(test.getRules(), createLDT(2008, 6, 30), offset, 1);
     }
 
     //-----------------------------------------------------------------------
-    @DataProvider(name="String_UTC_Invalid")
-    Object[][] data_of_string_UTC_invalid() {
-        return new Object[][] {
-                {"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"}, {"G"}, {"H"}, {"I"}, {"J"}, {"K"}, {"L"}, {"M"},
-                {"N"}, {"O"}, {"P"}, {"Q"}, {"R"}, {"S"}, {"T"}, {"U"}, {"V"}, {"W"}, {"X"}, {"Y"},
-                {"+0:00"}, {"+00:0"}, {"+0:0"},
-                {"+000"}, {"+00000"},
-                {"+0:00:00"}, {"+00:0:00"}, {"+00:00:0"}, {"+0:0:0"}, {"+0:0:00"}, {"+00:0:0"}, {"+0:00:0"},
-                {"+01_00"}, {"+01;00"}, {"+01@00"}, {"+01:AA"},
-                {"+19"}, {"+19:00"}, {"+18:01"}, {"+18:00:01"}, {"+1801"}, {"+180001"},
-                {"-0:00"}, {"-00:0"}, {"-0:0"},
-                {"-000"}, {"-00000"},
-                {"-0:00:00"}, {"-00:0:00"}, {"-00:00:0"}, {"-0:0:0"}, {"-0:0:00"}, {"-00:0:0"}, {"-0:00:0"},
-                {"-19"}, {"-19:00"}, {"-18:01"}, {"-18:00:01"}, {"-1801"}, {"-180001"},
-                {"-01_00"}, {"-01;00"}, {"-01@00"}, {"-01:AA"},
-                {"@01:00"},
-        };
-    }
-
-    @Test(dataProvider="String_UTC_Invalid", expectedExceptions=DateTimeException.class)
-    public void test_of_string_UTC_invalid(String id) {
-        ZoneId.of("UTC" + id);
-    }
-
-    @Test(dataProvider="String_UTC_Invalid", expectedExceptions=DateTimeException.class)
-    public void test_of_string_GMT_invalid(String id) {
-        ZoneId.of("GMT" + id);
-    }
-
-    //-----------------------------------------------------------------------
-    @DataProvider(name="String_Invalid")
-    Object[][] data_of_string_invalid() {
-        // \u00ef is a random unicode character
-        return new Object[][] {
-                {""}, {":"}, {"#"},
-                {"\u00ef"}, {"`"}, {"!"}, {"\""}, {"\u00ef"}, {"$"}, {"^"}, {"&"}, {"*"}, {"("}, {")"}, {"="},
-                {"\\"}, {"|"}, {","}, {"<"}, {">"}, {"?"}, {";"}, {"'"}, {"["}, {"]"}, {"{"}, {"}"},
-                {"\u00ef:A"}, {"`:A"}, {"!:A"}, {"\":A"}, {"\u00ef:A"}, {"$:A"}, {"^:A"}, {"&:A"}, {"*:A"}, {"(:A"}, {"):A"}, {"=:A"}, {"+:A"},
-                {"\\:A"}, {"|:A"}, {",:A"}, {"<:A"}, {">:A"}, {"?:A"}, {";:A"}, {"::A"}, {"':A"}, {"@:A"}, {"~:A"}, {"[:A"}, {"]:A"}, {"{:A"}, {"}:A"},
-                {"A:B#\u00ef"}, {"A:B#`"}, {"A:B#!"}, {"A:B#\""}, {"A:B#\u00ef"}, {"A:B#$"}, {"A:B#^"}, {"A:B#&"}, {"A:B#*"},
-                {"A:B#("}, {"A:B#)"}, {"A:B#="}, {"A:B#+"},
-                {"A:B#\\"}, {"A:B#|"}, {"A:B#,"}, {"A:B#<"}, {"A:B#>"}, {"A:B#?"}, {"A:B#;"}, {"A:B#:"},
-                {"A:B#'"}, {"A:B#@"}, {"A:B#~"}, {"A:B#["}, {"A:B#]"}, {"A:B#{"}, {"A:B#}"},
-        };
-    }
-
-    @Test(dataProvider="String_Invalid", expectedExceptions=DateTimeException.class)
-    public void test_of_string_invalid(String id) {
-        ZoneId.of(id);
-    }
-
-    //-----------------------------------------------------------------------
-    public void test_of_string_GMT0() {
-        ZoneId test = ZoneId.of("GMT0");
-        assertEquals(test.getId(), "Z");
-        assertEquals(test.getRules().isFixedOffset(), true);
-    }
-
-    //-----------------------------------------------------------------------
-    public void test_of_string_London() {
-        ZoneId test = ZoneId.of("Europe/London");
-        assertEquals(test.getId(), "Europe/London");
-        assertEquals(test.getRules().isFixedOffset(), false);
-    }
-
-    //-----------------------------------------------------------------------
-    @Test(expectedExceptions=NullPointerException.class)
-    public void test_of_string_null() {
-        ZoneId.of((String) null);
-    }
-
-    @Test(expectedExceptions=ZoneRulesException.class)
-    public void test_of_string_unknown_simple() {
-        ZoneId.of("Unknown");
-    }
-
-    //-------------------------------------------------------------------------
-    // TODO: test by deserialization
-//    public void test_ofUnchecked_string_invalidNotChecked() {
-//        ZoneRegion test = ZoneRegion.ofLenient("Unknown");
-//        assertEquals(test.getId(), "Unknown");
-//    }
-//
-//    public void test_ofUnchecked_string_invalidNotChecked_unusualCharacters() {
-//        ZoneRegion test = ZoneRegion.ofLenient("QWERTYUIOPASDFGHJKLZXCVBNM~/._+-");
-//        assertEquals(test.getId(), "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-");
-//    }
-
-    //-----------------------------------------------------------------------
-    // from(TemporalAccessor)
-    //-----------------------------------------------------------------------
-    public void test_factory_from_DateTimeAccessor_zoneId() {
-        TemporalAccessor mock = new TemporalAccessor() {
-            @Override
-            public boolean isSupported(TemporalField field) {
-                return false;
-            }
-
-            @Override
-            public long getLong(TemporalField field) {
-                throw new DateTimeException("Mock");
-            }
-
-            @Override
-            public <R> R query(TemporalQuery<R> query) {
-                if (query == Queries.zoneId()) {
-                    return (R) ZONE_PARIS;
-                }
-                return TemporalAccessor.super.query(query);
-            }
-        };
-        assertEquals(ZoneId.from(mock), ZONE_PARIS);
-    }
-
-    public void test_factory_from_DateTimeAccessor_offset() {
-        ZoneOffset offset = ZoneOffset.ofHours(1);
-        assertEquals(ZoneId.from(offset), offset);
-    }
-
-    @Test(expectedExceptions=DateTimeException.class)
-    public void test_factory_from_DateTimeAccessor_invalid_noDerive() {
-        ZoneId.from(LocalTime.of(12, 30));
-    }
-
-    @Test(expectedExceptions=NullPointerException.class)
-    public void test_factory_from_DateTimeAccessor_null() {
-        ZoneId.from((TemporalAccessor) null);
-    }
-
-    //-----------------------------------------------------------------------
     // Europe/London
     //-----------------------------------------------------------------------
     public void test_London() {
         ZoneId test = ZoneId.of("Europe/London");
         assertEquals(test.getId(), "Europe/London");

@@ -997,57 +700,10 @@
         assertEquals(test.getId(), "+01:30");
         assertEquals(test.getRules().isFixedOffset(), true);
     }
 
     //-----------------------------------------------------------------------
-    // equals() / hashCode()
-    //-----------------------------------------------------------------------
-    public void test_equals() {
-        ZoneId test1 = ZoneId.of("Europe/London");
-        ZoneId test2 = ZoneId.of("Europe/Paris");
-        ZoneId test2b = ZoneId.of("Europe/Paris");
-        assertEquals(test1.equals(test2), false);
-        assertEquals(test2.equals(test1), false);
-
-        assertEquals(test1.equals(test1), true);
-        assertEquals(test2.equals(test2), true);
-        assertEquals(test2.equals(test2b), true);
-
-        assertEquals(test1.hashCode() == test1.hashCode(), true);
-        assertEquals(test2.hashCode() == test2.hashCode(), true);
-        assertEquals(test2.hashCode() == test2b.hashCode(), true);
-    }
-
-    public void test_equals_null() {
-        assertEquals(ZoneId.of("Europe/London").equals(null), false);
-    }
-
-    public void test_equals_notTimeZone() {
-        assertEquals(ZoneId.of("Europe/London").equals("Europe/London"), false);
-    }
-
-    //-----------------------------------------------------------------------
-    // toString()
-    //-----------------------------------------------------------------------
-    @DataProvider(name="ToString")
-    Object[][] data_toString() {
-        return new Object[][] {
-            {"Europe/London", "Europe/London"},
-            {"Europe/Paris", "Europe/Paris"},
-            {"Europe/Berlin", "Europe/Berlin"},
-            {"UTC", "Z"},
-            {"UTC+01:00", "+01:00"},
-        };
-    }
-
-    @Test(dataProvider="ToString")
-    public void test_toString(String id, String expected) {
-        ZoneId test = ZoneId.of(id);
-        assertEquals(test.toString(), expected);
-    }
-
-    //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     private Instant createInstant(int year, int month, int day, ZoneOffset offset) {
         return LocalDateTime.of(year, month, day, 0, 0).toInstant(offset);
     }