jdk/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
author rriggs
Fri, 06 Feb 2015 17:29:11 -0500
changeset 28848 824124d1cba5
parent 20795 8ec9e5b79828
child 41600 5abb663b1ca4
permissions -rw-r--r--
8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear Summary: Check the year range consistently with other Hijrah date years Reviewed-by: lancea, scolebourne
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     1
/*
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     4
 *
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    10
 *
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    15
 * accompanied this code).
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    16
 *
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    20
 *
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    23
 * questions.
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    24
 */
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    25
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    26
package test.java.time.chrono;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    27
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    28
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
20519
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
    29
import static java.time.temporal.ChronoField.DAY_OF_YEAR;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    30
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    31
import static java.time.temporal.ChronoField.YEAR;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    32
import static org.testng.Assert.assertEquals;
28848
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
    33
import static org.testng.Assert.assertFalse;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    34
import static org.testng.Assert.assertTrue;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    35
import static org.testng.Assert.fail;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    36
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    37
import java.time.DateTimeException;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    38
import java.time.DayOfWeek;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    39
import java.time.LocalDate;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    40
import java.time.LocalDateTime;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    41
import java.time.LocalTime;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    42
import java.time.OffsetDateTime;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    43
import java.time.ZoneId;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    44
import java.time.ZoneOffset;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    45
import java.time.ZonedDateTime;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    46
import java.time.chrono.ChronoLocalDate;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    47
import java.time.chrono.ChronoLocalDateTime;
20519
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
    48
import java.time.chrono.ChronoPeriod;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    49
import java.time.chrono.ChronoZonedDateTime;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    50
import java.time.chrono.Chronology;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    51
import java.time.chrono.HijrahChronology;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    52
import java.time.chrono.HijrahDate;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    53
import java.time.chrono.JapaneseChronology;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    54
import java.time.chrono.JapaneseDate;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    55
import java.time.chrono.MinguoChronology;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    56
import java.time.chrono.MinguoDate;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    57
import java.time.chrono.ThaiBuddhistChronology;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    58
import java.time.chrono.ThaiBuddhistDate;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    59
import java.time.format.DateTimeFormatter;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    60
import java.time.format.FormatStyle;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    61
import java.time.temporal.ChronoField;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    62
import java.time.temporal.ChronoUnit;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    63
import java.time.temporal.TemporalAccessor;
20795
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
    64
import java.time.temporal.TemporalAdjusters;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    65
import java.time.temporal.ValueRange;
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    66
import java.time.temporal.WeekFields;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    67
import java.util.Locale;
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    68
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    69
import org.testng.annotations.DataProvider;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    70
import org.testng.annotations.Test;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    71
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    72
/**
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    73
 * Tests for the Umm alQura chronology and data.
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    74
 * Note: The dates used for testing are just a sample of calendar data.
28848
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
    75
 * @bug 8067800
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    76
 */
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    77
@Test
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    78
public class TestUmmAlQuraChronology {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    79
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    80
    private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    81
    private static final ZoneId ZONE_RIYADH = ZoneId.of("Asia/Riyadh");
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    82
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    83
    // Test for HijrahChronology Aliases
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    84
    @Test
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    85
    public void test_aliases() {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    86
        HijrahChronology hc = (HijrahChronology) Chronology.of("Hijrah");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    87
        assertEquals(hc, HijrahChronology.INSTANCE, "Alias for Hijrah-umalqura");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    88
        hc = (HijrahChronology) Chronology.of("islamic");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    89
        assertEquals(hc, HijrahChronology.INSTANCE, "Alias for Hijrah-umalqura");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    90
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    91
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    92
    // Test to check if the exception is thrown for an incorrect chronology id
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    93
    @Test(expectedExceptions=DateTimeException.class)
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    94
    public void test_badChronology() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    95
        Chronology test = Chronology.of("Hijrah-ummalqura");
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    96
    }
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
    97
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    98
    //--------------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
    99
    // regular data factory for Umm alQura dates and the corresponding ISO dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   100
    //--------------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   101
    @DataProvider(name = "UmmAlQuraVsISODates")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   102
    Object[][] data_UmmAlQuraVsISODates() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   103
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   104
            {HijrahDate.of(1318, 1, 1), LocalDate.of(1900, 04, 30)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   105
            {HijrahDate.of(1318, 12, 29), LocalDate.of(1901, 04, 19)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   106
            {HijrahDate.of(1319, 01, 01), LocalDate.of(1901, 04, 20)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   107
            {HijrahDate.of(1433, 12, 29), LocalDate.of(2012, 11, 14)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   108
            {HijrahDate.of(1434, 01, 01), LocalDate.of(2012, 11, 15)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   109
            {HijrahDate.of(1434, 02, 18), LocalDate.of(2012, 12, 31)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   110
            {HijrahDate.of(1502, 12, 29), LocalDate.of(2079, 10, 25)},
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   111
        };
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   112
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   113
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   114
    // Test to verify the epoch days for given Hijrah & ISO date instances
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   115
    @Test(dataProvider="UmmAlQuraVsISODates")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   116
        public void Test_UmmAlQuraVsISODates(HijrahDate hd, LocalDate ld) {
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   117
        assertEquals(hd.toEpochDay(), ld.toEpochDay(), "Umm alQura date and ISO date should have same epochDay");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   118
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   119
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   120
    // UmmAlQura chronology ranges for year, month and days for the HijrahChronology
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   121
    @Test
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   122
    public void Test_UmmAlQuraChronoRange() {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   123
        HijrahChronology chrono = HijrahChronology.INSTANCE;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   124
        ValueRange year = chrono.range(YEAR);
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   125
        assertEquals(year.getMinimum(), 1300, "Minimum year");
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   126
        assertEquals(year.getLargestMinimum(), 1300, "Largest minimum year");
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   127
        assertEquals(year.getMaximum(), 1600, "Largest year");
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   128
        assertEquals(year.getSmallestMaximum(), 1600, "Smallest Maximum year");
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   129
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   130
        ValueRange month = chrono.range(MONTH_OF_YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   131
        assertEquals(month.getMinimum(), 1, "Minimum month");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   132
        assertEquals(month.getLargestMinimum(), 1, "Largest minimum month");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   133
        assertEquals(month.getMaximum(), 12, "Largest month");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   134
        assertEquals(month.getSmallestMaximum(), 12, "Smallest Maximum month");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   135
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   136
        ValueRange day = chrono.range(DAY_OF_MONTH);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   137
        assertEquals(day.getMinimum(), 1, "Minimum day");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   138
        assertEquals(day.getLargestMinimum(), 1, "Largest minimum day");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   139
        assertEquals(day.getMaximum(), 30, "Largest day");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   140
        assertEquals(day.getSmallestMaximum(), 29, "Smallest Maximum day");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   141
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   142
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   143
    //-----------------------------------------------------------------------
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   144
    // regular data factory for dates and the corresponding range values
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   145
    //-----------------------------------------------------------------------
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   146
    @DataProvider(name = "dates")
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   147
    Object[][] data_dates() {
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   148
        return new Object[][]{
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   149
            {HijrahDate.of(1300, 5, 1), 1300, 1600, 1, 12, 1, 30, 30},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   150
            {HijrahDate.of(1300, 6, 1), 1300, 1600, 1, 12, 1, 29, 30},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   151
            {HijrahDate.of(1434, 12, 1), 1300, 1600, 1, 12, 1, 29, 30},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   152
            {HijrahDate.of(1500, 4, 1), 1300, 1600, 1, 12, 1, 30, 30},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   153
            {HijrahDate.of(1600, 6, 1), 1300, 1600, 1, 12, 1, 29, 30},
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   154
        };
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   155
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   156
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   157
    // Test to verify the min/max field ranges for given dates
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   158
    @Test(dataProvider="dates")
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   159
    public void Test_UmmAlQuraRanges(HijrahDate date,
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   160
                        int minYear, int maxYear,
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   161
                        int minMonth, int maxMonth,
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   162
                        int minDay, int maxDay, int maxChronoDay) {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   163
        // Check the chronology ranges
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   164
        HijrahChronology chrono = date.getChronology();
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   165
        ValueRange yearRange = chrono.range(YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   166
        assertEquals(yearRange.getMinimum(), minYear, "Minimum year for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   167
        assertEquals(yearRange.getLargestMinimum(), minYear, "Largest minimum year for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   168
        assertEquals(yearRange.getMaximum(), maxYear, "Maximum year for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   169
        assertEquals(yearRange.getSmallestMaximum(), maxYear, "Smallest Maximum year for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   170
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   171
        ValueRange monthRange = chrono.range(MONTH_OF_YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   172
        assertEquals(monthRange.getMinimum(), minMonth, "Minimum month for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   173
        assertEquals(monthRange.getMaximum(), maxMonth, "Maximum month for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   174
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   175
        ValueRange daysRange = chrono.range(DAY_OF_MONTH);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   176
        assertEquals(daysRange.getMinimum(), minDay, "Minimum day for chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   177
        assertEquals(daysRange.getMaximum(), maxChronoDay, "Maximum day for Hijrah chronology");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   178
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   179
        // Check the date ranges
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   180
        yearRange = date.range(YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   181
        assertEquals(yearRange.getMinimum(), minYear, "Minimum year for Hijrah date");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   182
        assertEquals(yearRange.getLargestMinimum(), minYear, "Largest minimum  year for Hijrah date");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   183
        assertEquals(yearRange.getMaximum(), maxYear, "Maximum year for Hijrah date");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   184
        assertEquals(yearRange.getSmallestMaximum(), maxYear, "Smallest maximum year for Hijrah date");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   185
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   186
        monthRange = date.range(MONTH_OF_YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   187
        assertEquals(monthRange.getMinimum(), minMonth, "Minimum month for HijrahDate");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   188
        assertEquals(monthRange.getMaximum(), maxMonth, "Maximum month for HijrahDate");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   189
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   190
        daysRange = date.range(DAY_OF_MONTH);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   191
        assertEquals(daysRange.getMinimum(), minDay, "Minimum day for HijrahDate");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   192
        assertEquals(daysRange.getMaximum(), maxDay, "Maximum day for HijrahDate");
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   193
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   194
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   195
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   196
    // Check the date limits
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   197
    @Test
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   198
    public void test_hijrahDateLimits() {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   199
        HijrahChronology chrono = HijrahChronology.INSTANCE;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   200
        ValueRange yearRange = chrono.range(YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   201
        ValueRange monthRange = chrono.range(MONTH_OF_YEAR);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   202
        ValueRange dayRange = chrono.range(DAY_OF_MONTH);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   203
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   204
        HijrahDate xx = chrono.date(1434, 1, 1);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   205
        HijrahDate minDate = chrono.date((int)yearRange.getLargestMinimum(),
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   206
                (int)monthRange.getMinimum(), (int)dayRange.getMinimum());
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   207
        try {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   208
            HijrahDate before = minDate.minus(1, ChronoUnit.DAYS);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   209
            fail("Exception did not occur, minDate: " + minDate + ".minus(1, DAYS) = " + before);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   210
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   211
        } catch (DateTimeException ex) {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   212
            // ignore, this exception was expected
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   213
        }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   214
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   215
        HijrahDate maxDate = chrono.date((int)yearRange.getSmallestMaximum(),
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   216
                (int)monthRange.getMaximum(), 1);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   217
        int monthLen = maxDate.lengthOfMonth();
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   218
        maxDate = maxDate.with(DAY_OF_MONTH, monthLen);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   219
        try {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   220
            HijrahDate after = maxDate.plus(1, ChronoUnit.DAYS);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   221
            fail("Exception did not occur, maxDate: " + maxDate + ".plus(1, DAYS) = " + after);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   222
        } catch (DateTimeException ex) {
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   223
            // ignore, this exception was expected
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   224
        }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   225
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   226
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   227
    // Data provider to verify the dateYearDay() method
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   228
    @DataProvider(name="dateYearDay")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   229
    Object[][] data_dateYearDay() {
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   230
        return new Object[][] {
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   231
            {HijrahChronology.INSTANCE.dateYearDay(1434, 42), HijrahChronology.INSTANCE.date(1434, 02, 13)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   232
            {HijrahChronology.INSTANCE.dateYearDay(1330, 354), HijrahChronology.INSTANCE.date(1330, 12, 29)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   233
            {HijrahChronology.INSTANCE.dateYearDay(1600, 1), HijrahChronology.INSTANCE.date(1600, 1, 1)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   234
            {HijrahChronology.INSTANCE.dateYearDay(1400, 175), HijrahChronology.INSTANCE.date(1400, 6, 28)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   235
            {HijrahChronology.INSTANCE.dateYearDay(1520, 190), HijrahChronology.INSTANCE.date(1520, 7, 13)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   236
            {HijrahChronology.INSTANCE.dateYearDay(1521, 112), HijrahChronology.INSTANCE.date(1521, 4, 25)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   237
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   238
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   239
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   240
    // Test to verify the dateYearDay() method
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   241
    @Test(dataProvider="dateYearDay")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   242
    public void test_DateYearDay(ChronoLocalDate date1,   ChronoLocalDate date2) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   243
       assertEquals(date1, date2);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   244
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   245
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   246
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   247
    // HijrahDate.with(DAY_OF_YEAR, n)
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   248
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   249
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   250
    public void test_getDayOfYear() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   251
        HijrahDate hd1 = HijrahChronology.INSTANCE.dateYearDay(1434, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   252
        for (int i = 1; i <= hd1.lengthOfYear(); i++) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   253
            HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1434, i);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   254
            int doy = hd.get(DAY_OF_YEAR);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   255
            assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   256
        }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   257
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   258
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   259
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   260
    public void test_withDayOfYear() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   261
        HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1434, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   262
        for (int i = 1; i <= hd.lengthOfYear(); i++) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   263
            HijrahDate hd2 = hd.with(DAY_OF_YEAR, i);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   264
            int doy = hd2.get(DAY_OF_YEAR);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   265
            assertEquals(doy, i, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   266
        }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   267
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   268
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   269
    @Test(expectedExceptions=java.time.DateTimeException.class)
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   270
    public void test_withDayOfYearTooSmall() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   271
        HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1435, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   272
        HijrahDate hd2 = hd.with(DAY_OF_YEAR, 0);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   273
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   274
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   275
    @Test(expectedExceptions=java.time.DateTimeException.class)
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   276
    public void test_withDayOfYearTooLarge() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   277
        HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1435, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   278
        HijrahDate hd2 = hd.with(DAY_OF_YEAR, hd.lengthOfYear() + 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   279
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   280
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   281
    // Test to verify the with() method with ChronoField is set to DAY_OF_WEEK
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   282
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   283
    public void test_adjustWithDayOfWeek() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   284
        assertEquals(HijrahChronology.INSTANCE.date(1320, 1, 15).with(ChronoField.DAY_OF_WEEK, 4), HijrahDate.of(1320, 1, 15));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   285
        assertEquals(HijrahChronology.INSTANCE.date(1421, 11, 15).with(ChronoField.DAY_OF_WEEK, 1), HijrahDate.of(1421, 11, 11));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   286
        assertEquals(HijrahChronology.INSTANCE.date(1529, 7, 18).with(ChronoField.DAY_OF_WEEK, 6), HijrahDate.of(1529, 7, 20));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   287
        assertEquals(HijrahChronology.INSTANCE.date(1534, 2, 10).with(ChronoField.DAY_OF_WEEK, 5), HijrahDate.of(1534, 2, 12));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   288
        assertEquals(HijrahChronology.INSTANCE.date(1552, 4, 1).with(ChronoField.DAY_OF_WEEK, 2), HijrahDate.of(1552, 3, 26));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   289
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   290
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   291
    // Test to verify the with() method with ChronoField is set to DAY_OF_MONTH
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   292
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   293
    public void test_adjustWithDayOfMonth() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   294
        assertEquals(HijrahChronology.INSTANCE.date(1320, 1, 15).with(ChronoField.DAY_OF_MONTH, 2), HijrahDate.of(1320, 1, 2));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   295
        assertEquals(HijrahChronology.INSTANCE.date(1421, 11, 15).with(ChronoField.DAY_OF_MONTH, 9), HijrahDate.of(1421, 11, 9));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   296
        assertEquals(HijrahChronology.INSTANCE.date(1529, 7, 18).with(ChronoField.DAY_OF_MONTH, 13), HijrahDate.of(1529, 7, 13));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   297
        assertEquals(HijrahChronology.INSTANCE.date(1534, 12, 10).with(ChronoField.DAY_OF_MONTH, 29), HijrahDate.of(1534, 12, 29));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   298
        assertEquals(HijrahChronology.INSTANCE.date(1552, 4, 1).with(ChronoField.DAY_OF_MONTH, 6), HijrahDate.of(1552, 4, 6));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   299
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   300
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   301
    // Test to verify the with() method with ChronoField is set to DAY_OF_YEAR
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   302
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   303
    public void test_adjustWithDayOfYear() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   304
        assertEquals(HijrahChronology.INSTANCE.date(1320, 1, 15).with(ChronoField.DAY_OF_YEAR, 24), HijrahDate.of(1320, 1, 24));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   305
        assertEquals(HijrahChronology.INSTANCE.date(1421, 11, 15).with(ChronoField.DAY_OF_YEAR, 135), HijrahDate.of(1421, 5, 18));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   306
        assertEquals(HijrahChronology.INSTANCE.date(1529, 7, 18).with(ChronoField.DAY_OF_YEAR, 64), HijrahDate.of(1529, 3, 5));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   307
        assertEquals(HijrahChronology.INSTANCE.date(1534, 2, 10).with(ChronoField.DAY_OF_YEAR, 354), HijrahDate.of(1534, 12, 29));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   308
        assertEquals(HijrahChronology.INSTANCE.date(1552, 4, 1).with(ChronoField.DAY_OF_YEAR, 291), HijrahDate.of(1552, 10, 26));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   309
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   310
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   311
    // Data provider to get the difference between two dates in terms of days, months and years
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   312
    @DataProvider(name="datesForDiff")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   313
    Object[][] data_datesForDiffs() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   314
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   315
            {HijrahDate.of(1350, 5, 15), HijrahDate.of(1351, 12, 29), 574, 19, 1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   316
            {HijrahDate.of(1434, 5, 1), HijrahDate.of(1434,6, 12), 40, 1, 0},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   317
            {HijrahDate.of(1436, 1, 1), HijrahDate.of(1475, 12, 29), 14173, 479, 39},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   318
            {HijrahDate.of(1500, 6, 12), HijrahDate.of(1551, 7, 12), 18102, 613, 51},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   319
            {HijrahDate.of(1550, 3, 11), HijrahDate.of(1551, 4, 11), 384, 13, 1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   320
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   321
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   322
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   323
    // Test to verify the difference between two given dates in terms of days, months and years
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   324
    @Test(dataProvider="datesForDiff")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   325
    public void test_diffBetweenDates(ChronoLocalDate from, ChronoLocalDate to, long days, long months, long years) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   326
          assertEquals(from.until(to, ChronoUnit.DAYS), days);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   327
          assertEquals(from.until(to, ChronoUnit.MONTHS), months);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   328
          assertEquals(from.until(to, ChronoUnit.YEARS), years);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   329
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   330
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   331
    // Data provider to get the difference between two dates as a period
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   332
    @DataProvider(name="datesForPeriod")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   333
    Object[][] data_Period() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   334
        return new Object[][] {
20519
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   335
            {HijrahDate.of(1350, 5, 15), HijrahDate.of(1434, 7, 20), HijrahChronology.INSTANCE.period(84, 2, 5)},
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   336
            {HijrahDate.of(1403, 5, 28), HijrahDate.of(1434, 7, 20), HijrahChronology.INSTANCE.period(31, 1, 22)},
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   337
            {HijrahDate.of(1434, 7, 20), HijrahDate.of(1484, 2, 15), HijrahChronology.INSTANCE.period(49, 6, 24)},
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   338
            {HijrahDate.of(1500, 6, 12), HijrahDate.of(1450, 4, 21), HijrahChronology.INSTANCE.period(-50, -1, -20)},
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   339
            {HijrahDate.of(1549, 3, 11), HijrahDate.of(1550, 3, 10), HijrahChronology.INSTANCE.period(0, 11, 28)},
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   340
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   341
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   342
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   343
    // Test to get the Period between two given dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   344
    @Test(dataProvider="datesForPeriod")
20519
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   345
    public void test_until(HijrahDate h1, HijrahDate h2, ChronoPeriod p) {
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   346
        ChronoPeriod period = h1.until(h2);
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   347
        assertEquals(period, p);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   348
    }
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   349
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   350
    // Test to get the Period between dates in different chronologies
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   351
    @Test(dataProvider="datesForPeriod")
20519
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   352
    public void test_periodUntilDiffChrono(HijrahDate h1, HijrahDate h2, ChronoPeriod p) {
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   353
        MinguoDate m = MinguoChronology.INSTANCE.date(h2);
20519
eee7a92074fd 8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents: 19425
diff changeset
   354
        ChronoPeriod period = h1.until(m);
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   355
        assertEquals(period, p);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   356
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   357
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   358
    // Test to get the adjusted date from a given date using TemporalAdjuster methods
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   359
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   360
    public void test_temporalDayAdjustments() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   361
        HijrahDate date = HijrahDate.of(1554, 7, 21);
20795
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   362
        assertEquals(date.with(TemporalAdjusters.firstDayOfMonth()), HijrahDate.of(1554, 7, 1));
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   363
        assertEquals(date.with(TemporalAdjusters.lastDayOfMonth()), HijrahDate.of(1554, 7, 29));
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   364
        assertEquals(date.with(TemporalAdjusters.firstDayOfNextMonth()), HijrahDate.of(1554, 8, 1));
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   365
        assertEquals(date.with(TemporalAdjusters.firstDayOfNextYear()), HijrahDate.of(1555, 1, 1));
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   366
        assertEquals(date.with(TemporalAdjusters.firstDayOfYear()), HijrahDate.of(1554, 1, 1));
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   367
        assertEquals(date.with(TemporalAdjusters.lastDayOfYear()), HijrahDate.of(1554, 12, 30));
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   368
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   369
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   370
    // Data provider for string representation of the date instances
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   371
    @DataProvider(name="toString")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   372
    Object[][] data_toString() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   373
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   374
            {HijrahChronology.INSTANCE.date(1320, 1, 1), "Hijrah-umalqura AH 1320-01-01"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   375
            {HijrahChronology.INSTANCE.date(1500, 10, 28), "Hijrah-umalqura AH 1500-10-28"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   376
            {HijrahChronology.INSTANCE.date(1500, 10, 29), "Hijrah-umalqura AH 1500-10-29"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   377
            {HijrahChronology.INSTANCE.date(1434, 12, 5), "Hijrah-umalqura AH 1434-12-05"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   378
            {HijrahChronology.INSTANCE.date(1434, 12, 6), "Hijrah-umalqura AH 1434-12-06"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   379
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   380
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   381
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   382
    // Test to verify the returned string value of a given date instance
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   383
    @Test(dataProvider="toString")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   384
    public void test_toString(ChronoLocalDate hijrahDate, String expected) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   385
        assertEquals(hijrahDate.toString(), expected);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   386
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   387
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   388
    // Data provider for maximum number of days
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   389
    @DataProvider(name="monthDays")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   390
    Object[][] data_monthDays() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   391
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   392
            {1432, 1, 29},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   393
            {1432, 4, 30},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   394
            {1433, 12, 29},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   395
            {1434, 1, 29},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   396
            {1435, 8, 29},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   397
            {1435, 9, 30},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   398
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   399
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   400
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   401
    // Test to verify the maximum number of days by adding one month to a given date
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   402
    @Test (dataProvider="monthDays")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   403
    public void test_valueRange_monthDays(int year, int month, int maxlength) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   404
        ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   405
        ValueRange range = null;
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   406
        for (int i=1; i<=12; i++) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   407
            range = date.range(ChronoField.DAY_OF_MONTH);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   408
            date = date.plus(1, ChronoUnit.MONTHS);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   409
            assertEquals(range.getMaximum(), month, maxlength);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   410
        }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   411
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   412
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   413
    // Test to get the last day of the month by adjusting the date with lastDayOfMonth() method
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   414
    @Test(dataProvider="monthDays")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   415
    public void test_lastDayOfMonth(int year, int month, int numDays) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   416
        HijrahDate hDate = HijrahChronology.INSTANCE.date(year, month, 1);
20795
8ec9e5b79828 8025722: TemporalAdjusters and TemporalQueries
rriggs
parents: 20519
diff changeset
   417
        hDate = hDate.with(TemporalAdjusters.lastDayOfMonth());
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   418
        assertEquals(hDate.get(ChronoField.DAY_OF_MONTH), numDays);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   419
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   420
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   421
    // Data provider for the 12 islamic month names in a formatted date
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   422
    @DataProvider(name="patternMonthNames")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   423
    Object[][] data_patternMonthNames() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   424
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   425
            {1434, 1, 1, "01 AH Thu Muharram 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   426
            {1434, 2, 1, "01 AH Fri Safar 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   427
            {1434, 3, 1, "01 AH Sun Rabi\u02bb I 1434"},//the actual month name is Rabi Al-Awwal, but the locale data contains short form.
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   428
            {1434, 4, 1, "01 AH Mon Rabi\u02bb II 1434"},//the actual month name is Rabi Al-Akhar, but the locale data contains short form.
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   429
            {1434, 5, 1, "01 AH Wed Jumada I 1434"},//the actual month name is Jumada Al-Awwal, but the locale data contains short form.
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   430
            {1434, 6, 1, "01 AH Thu Jumada II 1434"},//the actual month name is Jumada Al-Akhar, but the locale data contains short form.
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   431
            {1434, 7, 1, "01 AH Sat Rajab 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   432
            {1434, 8, 1, "01 AH Mon Sha\u02bbban 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   433
            {1434, 9, 1, "01 AH Tue Ramadan 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   434
            {1434, 10, 1, "01 AH Thu Shawwal 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   435
            {1434, 11, 1, "01 AH Sat Dhu\u02bbl-Qi\u02bbdah 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   436
            {1434, 12, 1, "01 AH Sun Dhu\u02bbl-Hijjah 1434"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   437
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   438
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   439
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   440
    // Test to verify the formatted dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   441
    @Test(dataProvider="patternMonthNames")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   442
    public void test_ofPattern(int year, int month, int day, String expected) {
19425
fdde8b1f0397 8022770: java/time/tck/java/time/chrono/TCKChronology.java start failing
rriggs
parents: 19030
diff changeset
   443
        DateTimeFormatter test = DateTimeFormatter.ofPattern("dd G E MMMM yyyy", Locale.US);
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   444
        assertEquals(test.format(HijrahDate.of(year, month, day)), expected);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   445
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   446
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   447
    // Data provider for localized dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   448
    @DataProvider(name="chronoDateTimes")
19425
fdde8b1f0397 8022770: java/time/tck/java/time/chrono/TCKChronology.java start failing
rriggs
parents: 19030
diff changeset
   449
   Object[][] data_chronodatetimes() {
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   450
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   451
            {1432, 12, 29, "Safar 1, 1434 AH"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   452
            {1433, 1, 30, "Safar 30, 1434 AH"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   453
            {1434, 6, 30, "Rajab 30, 1435 AH"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   454
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   455
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   456
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   457
    // Test to verify the localized dates using ofLocalizedDate() method
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   458
    @Test(dataProvider="chronoDateTimes")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   459
    public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   460
        HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   461
        ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   462
        hdt = hdt.plus(1, ChronoUnit.YEARS);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   463
        hdt = hdt.plus(1, ChronoUnit.MONTHS);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   464
        hdt = hdt.plus(1, ChronoUnit.DAYS);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   465
        hdt = hdt.plus(1, ChronoUnit.HOURS);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   466
        hdt = hdt.plus(1, ChronoUnit.MINUTES);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   467
        hdt = hdt.plus(1, ChronoUnit.SECONDS);
19425
fdde8b1f0397 8022770: java/time/tck/java/time/chrono/TCKChronology.java start failing
rriggs
parents: 19030
diff changeset
   468
        DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   469
        assertEquals(df.format(hdt), expected);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   470
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   471
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   472
    // Data provider to get the day of the week in a given date
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   473
    // The day of the week varies if the week starts with a saturday or sunday
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   474
    @DataProvider(name="dayOfWeek")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   475
    Object[][] data_dayOfweek() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   476
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   477
            {HijrahDate.of(1434, 6, 24), 1, 7},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   478
            {HijrahDate.of(1432, 9, 3), 5, 4},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   479
            {HijrahDate.of(1334, 12, 29), 7, 6},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   480
            {HijrahDate.of(1354, 5, 24), 1, 7},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   481
            {HijrahDate.of(1465, 10, 2), 2, 1},
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   482
        };
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   483
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   484
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   485
    // Test to get the day of the week based on a Saturday/Sunday as the first day of the week
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   486
    @Test(dataProvider="dayOfWeek")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   487
    public void test_dayOfWeek(HijrahDate date, int satStart, int sunStart) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   488
        assertEquals(date.get(WeekFields.of(DayOfWeek.SATURDAY, 7).dayOfWeek()), satStart);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   489
        assertEquals(date.get(WeekFields.of(DayOfWeek.SUNDAY, 7).dayOfWeek()), sunStart);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   490
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   491
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   492
    // Data sample to get the epoch days of a date instance
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   493
    @DataProvider(name="epochDays")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   494
    Object[][] data_epochdays() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   495
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   496
            {1332, -20486},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   497
            {1334, -19777},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   498
            {1336, -19068},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   499
            {1432, 14950},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   500
            {1434, 15659},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   501
            {1534, 51096},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   502
            {1535, 51450},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   503
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   504
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   505
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   506
    // Test to verify the number of epoch days of a date instance
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   507
    @Test(dataProvider="epochDays")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   508
    public void test_epochDays(int y, long epoch) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   509
        HijrahDate date = HijrahDate.of(y, 1, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   510
        assertEquals(date.toEpochDay(), epoch);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   511
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   512
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   513
    // Data provider to verify whether a given hijrah year is a leap year or not
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   514
    @DataProvider(name="leapYears")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   515
    Object[][] data_leapyears() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   516
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   517
            {1302, true},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   518
            {1305, false},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   519
            {1315, false},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   520
            {1534, false},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   521
            {1411, true},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   522
            {1429, false},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   523
            {1433, true},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   524
            {1443, true},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   525
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   526
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   527
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   528
    // Test to verify whether a given hijrah year is a leap year or not
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   529
    @Test(dataProvider="leapYears")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   530
    public void test_leapYears(int y, boolean leapyear) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   531
        HijrahDate date = HijrahDate.of(y, 1, 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   532
        assertEquals(date.isLeapYear(), leapyear);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   533
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   534
28848
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   535
    // Data provider to verify that a given hijrah year is outside the range of supported years
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   536
    // The values are dependent on the currently configured UmmAlQura calendar data
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   537
    @DataProvider(name="OutOfRangeLeapYears")
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   538
    Object[][] data_invalid_leapyears() {
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   539
        return new Object[][] {
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   540
                {1299},
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   541
                {1601},
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   542
                {Integer.MAX_VALUE},
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   543
                {Integer.MIN_VALUE},
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   544
        };
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   545
    }
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   546
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   547
    @Test(dataProvider="OutOfRangeLeapYears")
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   548
    public void test_notLeapYears(int y) {
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   549
        assertFalse(HijrahChronology.INSTANCE.isLeapYear(y), "Out of range leap year");
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   550
    }
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   551
824124d1cba5 8067800: Unexpected DateTimeException in the java.time.chrono.HijrahChronology.isLeapYear
rriggs
parents: 20795
diff changeset
   552
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   553
    // Date samples to convert HijrahDate to LocalDate and vice versa
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   554
    @DataProvider(name="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   555
    Object[][] data_samples() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   556
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   557
            {HijrahChronology.INSTANCE.date(1319, 12, 30), LocalDate.of(1902, 4, 9)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   558
            {HijrahChronology.INSTANCE.date(1320, 1, 1), LocalDate.of(1902, 4, 10)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   559
            {HijrahChronology.INSTANCE.date(1321, 12, 30), LocalDate.of(1904, 3, 18)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   560
            {HijrahChronology.INSTANCE.date(1433, 7, 29), LocalDate.of(2012, 6, 19)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   561
            {HijrahChronology.INSTANCE.date(1434, 10, 12), LocalDate.of(2013, 8, 19)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   562
            {HijrahChronology.INSTANCE.date(1500, 3, 3), LocalDate.of(2077, 1, 28)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   563
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   564
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   565
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   566
    // Test to get LocalDate instance from a given HijrahDate
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   567
    @Test(dataProvider="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   568
    public void test_toLocalDate(ChronoLocalDate hijrahDate, LocalDate iso) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   569
        assertEquals(LocalDate.from(hijrahDate), iso);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   570
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   571
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   572
    // Test to adjust HijrahDate with a given LocalDate
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   573
    @Test(dataProvider="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   574
    public void test_adjust_toLocalDate(ChronoLocalDate hijrahDate, LocalDate iso) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   575
        assertEquals(hijrahDate.with(iso), hijrahDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   576
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   577
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   578
    // Test to get a HijrahDate from a calendrical
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   579
    @Test(dataProvider="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   580
    public void test_fromCalendrical(ChronoLocalDate hijrahDate, LocalDate iso) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   581
        assertEquals(HijrahChronology.INSTANCE.date(iso), hijrahDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   582
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   583
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   584
    // Test to verify the day of week of a given HijrahDate and LocalDate
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   585
    @Test(dataProvider="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   586
    public void test_dayOfWeekEqualIsoDayOfWeek(ChronoLocalDate hijrahDate, LocalDate iso) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   587
        assertEquals(hijrahDate.get(ChronoField.DAY_OF_WEEK), iso.get(ChronoField.DAY_OF_WEEK), "Hijrah day of week should be same as ISO day of week");
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   588
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   589
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   590
    // Test to get the local date by applying the MIN adjustment with hijrah date
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   591
    @Test(dataProvider="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   592
    public void test_LocalDate_adjustToHijrahDate(ChronoLocalDate hijrahDate, LocalDate localDate) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   593
        LocalDate test = LocalDate.MIN.with(hijrahDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   594
        assertEquals(test, localDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   595
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   596
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   597
    // Test to get the local date time by applying the MIN adjustment with hijrah date
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   598
    @Test(dataProvider="samples")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   599
    public void test_LocalDateTime_adjustToHijrahDate(ChronoLocalDate hijrahDate, LocalDate localDate) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   600
        LocalDateTime test = LocalDateTime.MIN.with(hijrahDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   601
        assertEquals(test, LocalDateTime.of(localDate, LocalTime.MIDNIGHT));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   602
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   603
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   604
    // Sample dates for comparison
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   605
    @DataProvider(name="datesForComparison")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   606
    Object[][] data_datesForComparison() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   607
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   608
            {HijrahChronology.INSTANCE.date(1434, 6, 26), LocalDate.of(2013, 5, 5), -1, 1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   609
            {HijrahChronology.INSTANCE.date(1433, 4, 15), LocalDate.of(2012, 3, 15), 1, -1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   610
            {HijrahChronology.INSTANCE.date(1432, 5, 21), LocalDate.of(2011, 4, 22), -1, 1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   611
            {HijrahChronology.INSTANCE.date(1433, 7, 29), LocalDate.of(2012, 6, 2), -1, 1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   612
            {HijrahChronology.INSTANCE.date(1434, 10, 12), LocalDate.of(2013, 8, 2), -1, 1},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   613
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   614
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   615
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   616
    // Test to compare dates in both forward and reverse order
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   617
    @Test(dataProvider="datesForComparison")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   618
    public void test_compareDates(HijrahDate hdate, LocalDate ldate, int result1, int result2) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   619
        assertEquals(ldate.compareTo(hdate), result1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   620
        assertEquals(hdate.compareTo(ldate), result2);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   621
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   622
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   623
    // Test to verify the values of various chrono fields for a given hijrah date instance
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   624
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   625
    public void test_chronoFields() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   626
        ChronoLocalDate hdate = HijrahChronology.INSTANCE.date(1434, 6, 28);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   627
        assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), 3);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   628
        assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), 7);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   629
        assertEquals(hdate.get(ChronoField.ALIGNED_WEEK_OF_MONTH), 4);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   630
        assertEquals(hdate.get(ChronoField.ALIGNED_WEEK_OF_YEAR), 25);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   631
        assertEquals(hdate.get(ChronoField.ERA), 1);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   632
        assertEquals(hdate.get(ChronoField.YEAR_OF_ERA), 1434);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   633
        assertEquals(hdate.get(ChronoField.MONTH_OF_YEAR), 6);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   634
        assertEquals(hdate.get(ChronoField.DAY_OF_MONTH), 28);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   635
        assertEquals(hdate.get(ChronoField.DAY_OF_WEEK), 3);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   636
        assertEquals(hdate.get(ChronoField.DAY_OF_YEAR), 175);
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   637
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   638
19030
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   639
    // Test to verify the returned hijrah date after adjusting the day of week as Saturday
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   640
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   641
    public void test_adjustInto() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   642
        assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1434, 6, 28)), HijrahDate.of(1434, 7, 1));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   643
        assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1432, 4, 13)), HijrahDate.of(1432, 4, 14));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   644
        assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1433, 11, 29)), HijrahDate.of(1433, 12, 4));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   645
        assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1434, 5, 10)), HijrahDate.of(1434, 5, 11));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   646
        assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1434, 9, 11)), HijrahDate.of(1434, 9, 12));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   647
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   648
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   649
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   650
    // zonedDateTime(TemporalAccessor)
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   651
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   652
    @DataProvider(name="zonedDateTime")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   653
    Object[][] data_zonedDateTime() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   654
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   655
            {ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   656
            {OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   657
            {LocalDateTime.of(2012, 2, 29, 2, 7), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   658
            {JapaneseDate.of(2012, 2, 29), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   659
            {ThaiBuddhistDate.of(2012 + 543, 2, 29), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   660
            {LocalDate.of(2012, 2, 29), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   661
            {LocalTime.of(20, 30, 29, 0), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   662
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   663
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   664
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   665
    // Test to check the zoned date times
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   666
    @Test(dataProvider="zonedDateTime")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   667
    public void test_zonedDateTime(TemporalAccessor accessor,  HijrahDate expectedDate, LocalTime expectedTime, Class<?> expectedEx) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   668
        if (expectedEx == null) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   669
            ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(accessor);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   670
            assertEquals(result.toLocalDate(), expectedDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   671
            assertEquals(HijrahDate.from(accessor), expectedDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   672
            assertEquals(result.toLocalTime(), expectedTime);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   673
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   674
        } else {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   675
            try {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   676
                ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(accessor);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   677
                fail();
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   678
            } catch (Exception ex) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   679
                assertTrue(expectedEx.isInstance(ex));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   680
            }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   681
        }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   682
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   683
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   684
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   685
    // zonedDateTime(Instant, ZoneId )
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   686
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   687
    @Test
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   688
    public void test_Instant_zonedDateTime() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   689
        OffsetDateTime offsetDateTime = OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   690
        ZonedDateTime zonedDateTime = ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   691
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   692
        ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(offsetDateTime.toInstant(), offsetDateTime.getOffset());
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   693
        assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   694
        assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   695
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   696
        result = HijrahChronology.INSTANCE.zonedDateTime(zonedDateTime.toInstant(), zonedDateTime.getOffset());
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   697
        assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   698
        assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   699
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   700
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   701
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   702
    // localDateTime()
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   703
    //-----------------------------------------------------------------------
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   704
    @DataProvider(name="localDateTime")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   705
    Object[][] data_localDateTime() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   706
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   707
            {LocalDateTime.of(2012, 2, 29, 2, 7), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7), null},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   708
            {ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   709
            {OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   710
            {JapaneseDate.of(2012, 2, 29), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   711
            {ThaiBuddhistDate.of(2012 + 543, 2, 29), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   712
            {LocalDate.of(2012, 2, 29), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   713
            {LocalTime.of(20, 30, 29, 0), null, null, DateTimeException.class},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   714
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   715
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   716
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   717
    // Test to verify local date time values from various date instances defined in the localDateTime data provider
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   718
    @Test(dataProvider="localDateTime")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   719
    public void test_localDateTime(TemporalAccessor accessor,  HijrahDate expectedDate, LocalTime expectedTime, Class<?> expectedEx) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   720
        if (expectedEx == null) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   721
            ChronoLocalDateTime<HijrahDate> result = HijrahChronology.INSTANCE.localDateTime(accessor);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   722
            assertEquals(result.toLocalDate(), expectedDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   723
            assertEquals(HijrahDate.from(accessor), expectedDate);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   724
            assertEquals(result.toLocalTime(), expectedTime);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   725
        } else {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   726
            try {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   727
                ChronoLocalDateTime<HijrahDate> result = HijrahChronology.INSTANCE.localDateTime(accessor);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   728
                fail();
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   729
            } catch (Exception ex) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   730
                assertTrue(expectedEx.isInstance(ex));
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   731
            }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   732
        }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   733
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   734
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   735
    // Sample Hijrah & Minguo Dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   736
    @DataProvider(name="hijrahToMinguo")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   737
    Object[][] data_hijrahToMinguo() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   738
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   739
            {HijrahDate.of(1350,5,15), MinguoDate.of(20,9,28)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   740
            {HijrahDate.of(1434,5,1), MinguoDate.of(102,3,13)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   741
            {HijrahDate.of(1436,1,1), MinguoDate.of(103,10,25)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   742
            {HijrahDate.of(1500,6,12), MinguoDate.of(166,5,5)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   743
            {HijrahDate.of(1550,3,11), MinguoDate.of(214,8,11)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   744
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   745
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   746
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   747
    // Test to verify the date conversion from Hijrah to Minguo chronology
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   748
    @Test(dataProvider="hijrahToMinguo")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   749
    public void test_hijrahToMinguo(HijrahDate hijrah, MinguoDate minguo) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   750
        assertEquals(MinguoChronology.INSTANCE.date(hijrah), minguo);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   751
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   752
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   753
    // Sample Hijrah & Thai Dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   754
    @DataProvider(name="hijrahToThai")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   755
    Object[][] data_hijrahToThai() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   756
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   757
            {HijrahDate.of(1350,5,15), ThaiBuddhistDate.of(2474,9,28)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   758
            {HijrahDate.of(1434,5,1), ThaiBuddhistDate.of(2556,3,13)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   759
            {HijrahDate.of(1436,1,1), ThaiBuddhistDate.of(2557,10,25)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   760
            {HijrahDate.of(1500,6,12), ThaiBuddhistDate.of(2620,5,5)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   761
            {HijrahDate.of(1550,3,11), ThaiBuddhistDate.of(2668,8,11)},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   762
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   763
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   764
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   765
    // Test to verify the date conversion from Hijrah to Thai chronology
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   766
    @Test(dataProvider="hijrahToThai")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   767
    public void test_hijrahToThai(HijrahDate hijrah, ThaiBuddhistDate thai) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   768
        assertEquals(ThaiBuddhistChronology.INSTANCE.date(hijrah), thai);
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   769
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   770
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   771
    // Sample Hijrah & Japanese Dates
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   772
    @DataProvider(name="hijrahToJapanese")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   773
    Object[][] data_hijrahToJapanese() {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   774
        return new Object[][] {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   775
            {HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   776
            {HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   777
            {HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   778
            {HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   779
            {HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"},
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   780
        };
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   781
    }
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   782
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   783
    // Test to verify the date conversion from Hijrah to Japanese chronology
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   784
    @Test(dataProvider="hijrahToJapanese")
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   785
      public void test_hijrahToJapanese(HijrahDate hijrah, String japanese) {
32f129cb6351 8016025: JSR 310 DateTime API Updates IV
sherman
parents: 16852
diff changeset
   786
          assertEquals(JapaneseChronology.INSTANCE.date(hijrah).toString(), japanese);
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   787
    }
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents:
diff changeset
   788
}