test/java/time/tck/java/time/TCKMonth.java

Print this page




  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  63 import static org.testng.Assert.assertEquals;
  64 
  65 import java.util.ArrayList;
  66 import java.util.Arrays;
  67 import java.util.List;
  68 import java.util.Locale;
  69 
  70 import java.time.DateTimeException;
  71 import java.time.LocalDate;
  72 import java.time.LocalTime;
  73 import java.time.Month;

  74 import java.time.format.TextStyle;
  75 import java.time.temporal.ChronoField;
  76 import java.time.temporal.ChronoUnit;
  77 import java.time.temporal.ISOChrono;
  78 import java.time.temporal.JulianFields;
  79 import java.time.temporal.Queries;
  80 import java.time.temporal.TemporalAccessor;
  81 import java.time.temporal.TemporalField;





  82 
  83 import org.testng.annotations.DataProvider;
  84 import org.testng.annotations.Test;
  85 
  86 /**
  87  * Test Month.
  88  */
  89 @Test
  90 public class TCKMonth extends AbstractDateTimeTest {
  91 
  92     private static final int MAX_LENGTH = 12;
  93 
  94     //-----------------------------------------------------------------------
  95     @Override
  96     protected List<TemporalAccessor> samples() {
  97         TemporalAccessor[] array = {Month.JANUARY, Month.JUNE, Month.DECEMBER, };
  98         return Arrays.asList(array);
  99     }
 100 
 101     @Override


 150     public void test_factory_CalendricalObject_null() {
 151         Month.from((TemporalAccessor) null);
 152     }
 153 
 154     //-----------------------------------------------------------------------
 155     // get(TemporalField)
 156     //-----------------------------------------------------------------------
 157     @Test
 158     public void test_get_TemporalField() {
 159         assertEquals(Month.JULY.get(ChronoField.MONTH_OF_YEAR), 7);
 160     }
 161 
 162     @Test
 163     public void test_getLong_TemporalField() {
 164         assertEquals(Month.JULY.getLong(ChronoField.MONTH_OF_YEAR), 7);
 165     }
 166 
 167     //-----------------------------------------------------------------------
 168     // query(TemporalQuery)
 169     //-----------------------------------------------------------------------
 170     @Test
 171     public void test_query_chrono() {
 172         assertEquals(Month.JUNE.query(Queries.chrono()), ISOChrono.INSTANCE);
 173         assertEquals(Queries.chrono().queryFrom(Month.JUNE), ISOChrono.INSTANCE);
 174     }
 175 
 176     @Test
 177     public void test_query_zoneId() {
 178         assertEquals(Month.JUNE.query(Queries.zoneId()), null);
 179         assertEquals(Queries.zoneId().queryFrom(Month.JUNE), null);
 180     }
 181 
 182     @Test
 183     public void test_query_precision() {
 184         assertEquals(Month.JUNE.query(Queries.precision()), ChronoUnit.MONTHS);
 185         assertEquals(Queries.precision().queryFrom(Month.JUNE), ChronoUnit.MONTHS);
 186     }
 187 
 188     @Test
 189     public void test_query_offset() {
 190         assertEquals(Month.JUNE.query(Queries.offset()), null);
 191         assertEquals(Queries.offset().queryFrom(Month.JUNE), null);
 192     }
 193 
 194     @Test
 195     public void test_query_zone() {
 196         assertEquals(Month.JUNE.query(Queries.zone()), null);
 197         assertEquals(Queries.zone().queryFrom(Month.JUNE), null);
 198     }
 199 
 200     @Test(expectedExceptions=NullPointerException.class)
 201     public void test_query_null() {
 202         Month.JUNE.query(null);
 203     }
 204 
 205     //-----------------------------------------------------------------------
 206     // getText()
 207     //-----------------------------------------------------------------------
 208     @Test(groups={"tck"})
 209     public void test_getText() {
 210         assertEquals(Month.JANUARY.getText(TextStyle.SHORT, Locale.US), "Jan");
 211     }
 212 
 213     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 214     public void test_getText_nullStyle() {
 215         Month.JANUARY.getText(null, Locale.US);
 216     }
 217 
 218     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 219     public void test_getText_nullLocale() {
 220         Month.JANUARY.getText(TextStyle.FULL, null);
 221     }
 222 
 223     //-----------------------------------------------------------------------
 224     // plus(long), plus(long,unit)
 225     //-----------------------------------------------------------------------
 226     @DataProvider(name="plus")
 227     Object[][] data_plus() {
 228         return new Object[][] {
 229             {1, -13, 12},
 230             {1, -12, 1},
 231             {1, -11, 2},
 232             {1, -10, 3},
 233             {1, -9, 4},
 234             {1, -8, 5},
 235             {1, -7, 6},
 236             {1, -6, 7},
 237             {1, -5, 8},
 238             {1, -4, 9},
 239             {1, -3, 10},
 240             {1, -2, 11},




  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  63 import static org.testng.Assert.assertEquals;
  64 





  65 import java.time.DateTimeException;
  66 import java.time.LocalDate;
  67 import java.time.LocalTime;
  68 import java.time.Month;
  69 import java.time.chrono.IsoChronology;
  70 import java.time.format.TextStyle;
  71 import java.time.temporal.ChronoField;
  72 import java.time.temporal.ChronoUnit;

  73 import java.time.temporal.JulianFields;
  74 import java.time.temporal.Queries;
  75 import java.time.temporal.TemporalAccessor;
  76 import java.time.temporal.TemporalField;
  77 import java.time.temporal.TemporalQuery;
  78 import java.util.ArrayList;
  79 import java.util.Arrays;
  80 import java.util.List;
  81 import java.util.Locale;
  82 
  83 import org.testng.annotations.DataProvider;
  84 import org.testng.annotations.Test;
  85 
  86 /**
  87  * Test Month.
  88  */
  89 @Test
  90 public class TCKMonth extends AbstractDateTimeTest {
  91 
  92     private static final int MAX_LENGTH = 12;
  93 
  94     //-----------------------------------------------------------------------
  95     @Override
  96     protected List<TemporalAccessor> samples() {
  97         TemporalAccessor[] array = {Month.JANUARY, Month.JUNE, Month.DECEMBER, };
  98         return Arrays.asList(array);
  99     }
 100 
 101     @Override


 150     public void test_factory_CalendricalObject_null() {
 151         Month.from((TemporalAccessor) null);
 152     }
 153 
 154     //-----------------------------------------------------------------------
 155     // get(TemporalField)
 156     //-----------------------------------------------------------------------
 157     @Test
 158     public void test_get_TemporalField() {
 159         assertEquals(Month.JULY.get(ChronoField.MONTH_OF_YEAR), 7);
 160     }
 161 
 162     @Test
 163     public void test_getLong_TemporalField() {
 164         assertEquals(Month.JULY.getLong(ChronoField.MONTH_OF_YEAR), 7);
 165     }
 166 
 167     //-----------------------------------------------------------------------
 168     // query(TemporalQuery)
 169     //-----------------------------------------------------------------------
 170     @DataProvider(name="query")
 171     Object[][] data_query() {
 172         return new Object[][] {
 173                 {Month.JUNE, Queries.chronology(), IsoChronology.INSTANCE},
 174                 {Month.JUNE, Queries.zoneId(), null},
 175                 {Month.JUNE, Queries.precision(), ChronoUnit.MONTHS},
 176                 {Month.JUNE, Queries.zone(), null},
 177                 {Month.JUNE, Queries.offset(), null},
 178                 {Month.JUNE, Queries.localDate(), null},
 179                 {Month.JUNE, Queries.localTime(), null},
 180         };





 181     }
 182 
 183     @Test(dataProvider="query")
 184     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 185         assertEquals(temporal.query(query), expected);

 186     }
 187 
 188     @Test(dataProvider="query")
 189     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 190         assertEquals(query.queryFrom(temporal), expected);

 191     }
 192 
 193     @Test(expectedExceptions=NullPointerException.class)
 194     public void test_query_null() {
 195         Month.JUNE.query(null);
 196     }
 197 
 198     //-----------------------------------------------------------------------
 199     // getText()
 200     //-----------------------------------------------------------------------
 201     @Test(groups={"tck"})
 202     public void test_getText() {
 203         assertEquals(Month.JANUARY.getDisplayName(TextStyle.SHORT, Locale.US), "Jan");
 204     }
 205 
 206     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 207     public void test_getText_nullStyle() {
 208         Month.JANUARY.getDisplayName(null, Locale.US);
 209     }
 210 
 211     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 212     public void test_getText_nullLocale() {
 213         Month.JANUARY.getDisplayName(TextStyle.FULL, null);
 214     }
 215 
 216     //-----------------------------------------------------------------------
 217     // plus(long), plus(long,unit)
 218     //-----------------------------------------------------------------------
 219     @DataProvider(name="plus")
 220     Object[][] data_plus() {
 221         return new Object[][] {
 222             {1, -13, 12},
 223             {1, -12, 1},
 224             {1, -11, 2},
 225             {1, -10, 3},
 226             {1, -9, 4},
 227             {1, -8, 5},
 228             {1, -7, 6},
 229             {1, -6, 7},
 230             {1, -5, 8},
 231             {1, -4, 9},
 232             {1, -3, 10},
 233             {1, -2, 11},